-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.c
executable file
·104 lines (92 loc) · 2.09 KB
/
search.c
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
/*
* search.c
* Alpha-beta vyhledavaci funkce
*/
#include"data.h"
int SilentAlphaBeta(TGame *, int, int, int, int);
extern int IQ, SIQ;
int AlphaBeta(TGame *aGame, int depth, int alpha, int beta)
{
TGame lGame;
TMoveList lList;
int best, p, i = 0, value;
//char c[5];
if (depth <= 0)
{
if (SIQ < 0)
return SilentAlphaBeta(aGame, depth, alpha, beta, 0);
else
return Evaluate(aGame);
}
p = MoveGen(aGame, lList, 0);
if (p == 0)
return Evaluate(aGame);
best = -1 * MATV;
while (i < p && best < beta)
{
lGame = *aGame;
/*
SqrToStr(lList[i].from, &c[0]);
SqrToStr(lList[i].to, &c[2]);
MakeMoveStr(c, &lGame);
*/
MakeMove(lList[i], &lGame);
if (best > alpha)
alpha = best;
value = -1 * AlphaBeta(&lGame, depth - 1, -1 * beta, -1 * alpha);
if (value > best)
best = value;
i++;
}
return best;
}
int SilentAlphaBeta(TGame *aGame, int depth, int alpha, int beta, int nt)
{
TGame lGame;
TMoveList lList;
int best, lCount, i = 0, value;
//char c[5];
if (depth <= SIQ)
{
if (depth < 0)
return EvaluateM(aGame);
else
return Evaluate(aGame);
}
lCount = SMoveGen(aGame, lList);
best = -1 * MATV;
while (i < lCount && best < beta)
{
lGame = *aGame;
/*
SqrToStr(lList[i].from, &c[0]);
SqrToStr(lList[i].to, &c[2]);
MakeMoveStr(c, &lGame);
*/
MakeMove(lList[i], &lGame);
if (best > alpha)
alpha = best;
value = -1 * SilentAlphaBeta(&lGame, depth - 1, -1 * beta, -1 * alpha, 0);
if (value > best)
best = value;
i++;
}
/* vygenerovat take NULL tah */
/* jinak bude napriklad nucen delat nevyhodne
braci tahy */
if (nt == 0)
{
lGame = *aGame;
if (aGame->sidetomove == WHITE)
lGame.sidetomove = BLACK;
else
lGame.sidetomove = WHITE;
lGame.enpas = -1; /* no enpassant while NULL move */
value = -1 * SilentAlphaBeta(&lGame, depth - 1, -1 * beta, -1 * alpha, 1);
if (value > best)
best = value;
}
else if (nt == 1 && lCount == 0)
return EvaluateM(aGame);
return best;
}