-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCEval.cs
126 lines (115 loc) · 2.51 KB
/
CEval.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NSProgram
{
internal class CEval
{
int index = -1;
public int number = 1;
public int resultOk = 0;
public int resultFail = 0;
public string line = String.Empty;
public List<string> fenList = new List<string>();
string Line
{
get
{
return (fenList.Count <= 0) || (index >= fenList.Count) ? String.Empty : fenList[index];
}
}
public string Fen
{
get
{
return LineToFen(Line);
}
}
public void Reset()
{
index = -1;
number = 1;
resultOk = 0;
resultFail = 0;
Next();
}
string LineToFen(string line)
{
string[] tokens = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
List<string> sl = new List<string>(tokens);
List<string> subList = sl.GetRange(0, 6);
string fen = String.Join(" ", subList.ToArray()).Trim();
Program.chess.SetFen(fen);
return Program.chess.GetFen();
}
public List<string> GetFens()
{
List<string> sl = new List<string>();
foreach (string l in fenList)
{
if( (l.Substring(0, 3) == "t: ")|| (l.Substring(0, 3) == "// "))
continue;
sl.Add(LineToFen(l));
}
return sl;
}
public void LoadFen()
{
string fn = Constants.testFen;
fenList.Clear();
if (!File.Exists(fn))
return;
using (FileStream fs = File.Open(fn, FileMode.Open, FileAccess.Read, FileShare.Read))
using (StreamReader reader = new StreamReader(fs))
{
string line = String.Empty;
while ((line = reader.ReadLine()) != null)
if (!String.IsNullOrEmpty(line))
fenList.Add(line);
}
}
public bool Next()
{
index++;
if (Line == String.Empty)
return false;
if (Line.Substring(0, 3) == "t: ")
{
Console.WriteLine(Line.Substring(3));
return Next();
}
if (Line.Substring(0,3)=="// ")
return Next();
if (Line == "finish")
index = fenList.Count;
number++;
return !String.IsNullOrEmpty(Line);
}
public bool GetResult(string move)
{
Program.chess.SetFen(Fen);
string san = Program.chess.UmoToSan(move);
if (Line.Contains("bm "))
if (Line.Contains($" {move}")||Line.Contains($" {san}"))
return true;
else
return false;
if (Line.Contains("am "))
if (Line.Contains($" {move}") ||Line.Contains($" {san}"))
return false;
else
return true;
return true;
}
public void SetResult(bool r)
{
if (r)
resultOk++;
else
resultFail++;
}
}
}