-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCRecList.cs
More file actions
101 lines (91 loc) · 1.68 KB
/
CRecList.cs
File metadata and controls
101 lines (91 loc) · 1.68 KB
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
using System;
using System.Collections.Generic;
using System.IO;
namespace BookReaderAbk
{
class CRec
{
public byte fr;
public byte to;
public byte promotion;
public byte priority;
public int games;
public int win;
public int loose;
public int ply;
public int nextMove;
public int nextSibling;
public long position;
public int GetValue()
{
int value=games+win-loose;
if(value <1)
value=1;
return value;
}
public void LoadFromBinaryReader(BinaryReader br)
{
fr = br.ReadByte();
to = br.ReadByte();
promotion = br.ReadByte();
priority = br.ReadByte();
games = br.ReadInt32();
win = br.ReadInt32();
loose = br.ReadInt32();
ply = br.ReadInt32();
nextMove = br.ReadInt32();
nextSibling = br.ReadInt32();
}
public void SaveToBinaryWriter(BinaryWriter bw)
{
bw.Write(fr);
bw.Write(to);
bw.Write(promotion);
bw.Write(priority);
bw.Write(games);
bw.Write(win);
bw.Write(loose);
bw.Write(ply);
bw.Write(nextMove);
bw.Write(nextSibling);
}
string SquareToStr(byte square)
{
int y = square >> 3;
int x = square & 7;
string file = "abcdefgh";
string rank = "12345678";
return $"{file[x]}{rank[y]}";
}
string PromotionToStr(byte p)
{
switch (p)
{
case 1:
return "r";
case 2:
return "n";
case 3:
return "b";
case 4:
return "q";
default:
return String.Empty;
}
}
public string GetUci()
{
return SquareToStr(fr) + SquareToStr(to) + PromotionToStr(promotion);
}
}
internal class CRecList:List<CRec>
{
public void SortGames()
{
Sort(delegate (CRec r1, CRec r2)
{
return r2.games - r1.games;
});
}
}
}