-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathperftUnit.pas
140 lines (135 loc) · 3.51 KB
/
perftUnit.pas
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
unit perftUnit;
interface
uses mmsystem,BoardUnit,GenMoveUnit,EvalUnit,SearchUnit,HistoryUnit,hashunit;
Procedure Perft(D:Byte);
implementation
function Minimax(d:Byte):int64;
var kolMoves:Byte;
var i:Byte;
Var M:int64;
Begin
if d=1 then
Begin
kolMoves:=1;
// KolMoves:=GenMove;
Eval;
(*if kolMoves>0 then
if Tekmoves.Mov[1].kolCap=0 then
Begin
kolPr:=0;
for I:=1 to kolMoves do
if Tekmoves.Mov[i].kto<>Tekmoves.Mov[i].Chto then inc(kolPR);
if kolPR<>GenMoveP then Writeln('Error') Else
Begin
// if KolPR>0 then Writeln('OK');
end;
end;*)
for i:=1 to kolMoves do
Begin
// Makemove(i);
// UnMakeMove;
end;
MiniMax:=kolMoves;
Exit;
end;
M:=0;
unGenMove;
kolMoves:=GenMove;
randomM;
SortM;
for i:=1 to kolMoves do
Begin
MakemoveSort(i);
M:=M+minimax(d-1);
UnMakeMove;
Promote(i);
end;
Minimax:=M;
end;
Procedure Perft(D:Byte);
Var i,j,k:integer;
var BestScore,Score:Integer;
Var kolMov:Byte;
Var t,t1:Cardinal;
Var kolNodes:int64;
Var NewRE:Boolean;
Begin
Randomize;
initBoard;
sethashsize(32);
avaria:=false;
avariaT:=TimeGetTime+10000000;
inithash();
ochod:=false;
t1:=timegettime;
ochod:=false;
inittree();
kolMov:=genmove;
randomM;
sortM;
for i:=0 to 255 do
Begin
killerOt[i]:=0;
KillerKu[i]:=0;
KillerKto[i]:=0;
killerOt2[i]:=0;
KillerKu2[i]:=0;
KillerKto2[i]:=0;
end;
GuD:=0;
Bad:=0;
for i:=0 to 31 do
for j:=0 to 31 do
for k:=0 to 3 do
Begin
HistoryP[i,j,k]:=1;
HistoryK[i,j,k]:=1;
end;
for i:=1 to 25 do
Begin
killerot[GLPLY+2]:=0;
killerku[GLPLY+2]:=0;
killerkto[GLPLy+2]:=0;
killerot2[GLPLY+2]:=0;
killerku2[GLPLY+2]:=0;
killerkto2[GLPLy+2]:=0;
killerot[GLPLY+1]:=0;
killerku[GLPLY+1]:=0;
killerkto[GLPLy+1]:=0;
killerot2[GLPLY+1]:=0;
killerku2[GLPLY+1]:=0;
killerkto2[GLPLy+1]:=0;
BestScore:=-100000;
for j:=1 to kolMov do
Begin
if (TekMoves.Mov[1].kolCap>0)or ((TekMoves.Mov[tekmoves.sortmov[j]].Kto and 8)=0)
then NewRE:=true Else NewRe:=false;
MakeMoveSort(j);
if j=1 then Score:=-AB(-100000,-BestScore,i-1,true,true,NewRE,trunc(i*0.49+0.5))
Else
Begin
Score:=-AB(-BestScore-1,-BestScore,i-1,false,false,NewRE,trunc(i*0.49+0.5));
if Score>BestScore then
Score:=-AB(-100000,-BestScore,i-1,true,true,NewRE,trunc(i*0.49+0.5));
end;
unmakeMove;
if Score>BestScore then
Begin
Promote(j);
BestScore:=Score;
end;
end;
// Writeln(BestScore);
Writeln('Score= ',BestScore,' depth=',i,' Time=',TimeGetTime-t1:10,' Nodes=',Nodes:12, Round(Nodes/(Timegettime-t1+1)):10, MaxPly:6);
end;
// Writeln(gud:10,bad:10,gud*100/(bad+gud):6:2);
ochod:=false;
t1:=timegettime;
for i:=1 to D do
Begin
t:=TimegetTime;
kolNodes:=Minimax(i);
Writeln('Depth=',i:2,' Time=',TimeGetTime-t:10,' Nodes=',kolNodes:12, Round(Nodes/(Timegettime-t1+1)):10, MaxPly:6);
end;
end;
end.