-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevaluator.inc.c
284 lines (130 loc) · 3.46 KB
/
evaluator.inc.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
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
141
142
int adv=0; /* white's advantage */
int f,r;
rooks[0] = -1;
rooks[1] = -1;
if (!mate_material(WHITE))
{
if (!mate_material(BLACK))
{
return 0;
}
adv += weights[NOMATERIAL];
verbose_print(8,8,weights[NOMATERIAL],"no mating material (white)");
}
else if (!mate_material(BLACK))
{
adv += -weights[NOMATERIAL];
verbose_print(8,8,-weights[NOMATERIAL],"no mating material (black)");
}
for (f=0;f<8;f++) {
for (r=0;r<8;r++) {
switch(getpiece(f,r)) {
case WQUEEN:
adv += score_queen(f,r,WHITE);
break;
case BQUEEN:
adv -= score_queen(f,r,BLACK);
break;
case WROOK:
adv += score_rook(f,r,WHITE);
break;
case BROOK:
adv -= score_rook(f,r,BLACK);
break;
case WPAWN:
adv += score_pawn(f,r,WHITE);
break;
case BPAWN:
adv -= score_pawn(f,r,BLACK);
break;
case WKNIGHT:
adv += score_knight(f,r,WHITE);
break;
case BKNIGHT:
adv -= score_knight(f,r,BLACK);
break;
/* case WBISHOP: */
/* adv += score_bishop(f,r,WHITE); */
/* break; */
/* case BBISHOP: */
/* adv -= score_bishop(f,r,BLACK); */
/* break; */
}
}
}
if (board->pieces[WBISHOP]>=2) {
adv += weights[TWOBISHOPS];
verbose_print(8,8,weights[TWOBISHOPS], "bishop pair");
}
if (board->pieces[BBISHOP]>=2) {
adv -= weights[TWOBISHOPS];
verbose_print(8,8,-weights[TWOBISHOPS], "bishop pair");
}
if (wkcastledp()) {
verbose_print(8,8,weights[KCASTLEBONUS], "castled king side");
adv+=weights[KCASTLEBONUS];
}
else if (wqcastledp()) {
verbose_print(8,8,weights[QCASTLEBONUS], "castled queen side");
adv+=weights[QCASTLEBONUS];
}
else {
if (!wkcastlep()) {
verbose_print(8,8,-weights[NOCASTLEKING],
"lost castling rights (kingside)");
adv-=weights[NOCASTLEKING];
}
if (!wqcastlep()) {
verbose_print(8,8,-weights[NOCASTLEQUEEN],
"lost castling rights (queenside)");
adv-=weights[NOCASTLEQUEEN];
}
}
if (bkcastledp())
{
verbose_print(8,8,-weights[KCASTLEBONUS], "castled king side");
adv-=weights[KCASTLEBONUS];
}
else if (bqcastledp())
{
verbose_print(8,8,-weights[QCASTLEBONUS], "castled queen side");
adv-=weights[QCASTLEBONUS];
}
else
{
if (!bkcastlep()) {
verbose_print(8,8,weights[NOCASTLEKING],
"lost castling rights (kingside)");
adv+=weights[NOCASTLEKING];
}
if (!bqcastlep()) {
verbose_print(8,8,weights[NOCASTLEQUEEN],
"lost castling rights (queenside)");
adv+=weights[NOCASTLEQUEEN];
}
}
verbose_printf(("adv: %6d\n", adv));
verbose_printf(("material: WHITE %6d\tBLACK %6d\n",
board->material[WHITE], board->material[BLACK]));
verbose_printf(("position: WHITE %6d\tBLACK %6d\n",
board->position[WHITE], board->position[BLACK]));
verbose_printf(("material advantage: %6d\n", material_advantage()));
verbose_printf(("mobility: %6d\n", mobility_advantage()));
adv += board->position[WHITE]-board->position[BLACK];
adv += material_advantage();
adv += mobility_advantage();
#ifdef VERBOSE
for(r=7;r>=0;r--)
{
for (f=0;f<8;f++)
{
chesspiece p = getpiece(f,r);
if (p)
printf(" %c=%3d ", rep(p), squarevalue(f,r,p));
else
printf(" ");
}
printf("\n");
}
#endif /* VERBOSE */
return (tomove() == WHITE) ? adv : -adv;