-
Notifications
You must be signed in to change notification settings - Fork 0
/
evaluate.c
133 lines (112 loc) · 3.19 KB
/
evaluate.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
// evaluate.c
#include "ark.h"
const int PawnTable[64] = {
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
10 , 10 , 0 , -10 , -10 , 0 , 10 , 10 ,
5 , 0 , 0 , 5 , 5 , 0 , 0 , 5 ,
0 , 0 , 10 , 20 , 20 , 10 , 0 , 0 ,
5 , 5 , 5 , 10 , 10 , 5 , 5 , 5 ,
10 , 10 , 10 , 20 , 20 , 10 , 10 , 10 ,
20 , 20 , 20 , 30 , 30 , 20 , 20 , 20 ,
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
};
const int KnightTable[64] = {
0 , -10 , 0 , 0 , 0 , 0 , -10 , 0 ,
0 , 0 , 0 , 5 , 5 , 0 , 0 , 0 ,
0 , 0 , 10 , 10 , 10 , 10 , 0 , 0 ,
0 , 0 , 10 , 20 , 20 , 10 , 5 , 0 ,
5 , 10 , 15 , 20 , 20 , 15 , 10 , 5 ,
5 , 10 , 10 , 20 , 20 , 10 , 10 , 5 ,
0 , 0 , 5 , 10 , 10 , 5 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
};
const int BishopTable[64] = {
0 , 0 , -10 , 0 , 0 , -10 , 0 , 0 ,
0 , 0 , 0 , 10 , 10 , 0 , 0 , 0 ,
0 , 0 , 10 , 15 , 15 , 10 , 0 , 0 ,
0 , 10 , 15 , 20 , 20 , 15 , 10 , 0 ,
0 , 10 , 15 , 20 , 20 , 15 , 10 , 0 ,
0 , 0 , 10 , 15 , 15 , 10 , 0 , 0 ,
0 , 0 , 0 , 10 , 10 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
};
const int RookTable[64] = {
0 , 0 , 5 , 10 , 10 , 5 , 0 , 0 ,
0 , 0 , 5 , 10 , 10 , 5 , 0 , 0 ,
0 , 0 , 5 , 10 , 10 , 5 , 0 , 0 ,
0 , 0 , 5 , 10 , 10 , 5 , 0 , 0 ,
0 , 0 , 5 , 10 , 10 , 5 , 0 , 0 ,
0 , 0 , 5 , 10 , 10 , 5 , 0 , 0 ,
25 , 25 , 25 , 25 , 25 , 25 , 25 , 25 ,
0 , 0 , 5 , 10 , 10 , 5 , 0 , 0
};
const int Mirror64[64] = {
56 , 57 , 58 , 59 , 60 , 61 , 62 , 63 ,
48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 ,
40 , 41 , 42 , 43 , 44 , 45 , 46 , 47 ,
32 , 33 , 34 , 35 , 36 , 37 , 38 , 39 ,
24 , 25 , 26 , 27 , 28 , 29 , 30 , 31 ,
16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 ,
8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ,
0 , 1 , 2 , 3 , 4 , 5 , 6 , 7
};
#define MIRROR64(sq) (Mirror64[(sq)])
int EvalPosition(const S_BOARD *board) {
int pce;
int pceNum;
int sq;
int score = board->material[WHITE] - board->material[BLACK];
pce = wP;
for(pceNum = 0; pceNum < board->pceNum[pce]; ++pceNum) {
sq = board->pList[pce][pceNum];
ASSERT(SqOnBoard(sq));
score += PawnTable[SQ64(sq)];
}
pce = bP;
for(pceNum = 0; pceNum < board->pceNum[pce]; ++pceNum) {
sq = board->pList[pce][pceNum];
ASSERT(SqOnBoard(sq));
score -= PawnTable[MIRROR64(SQ64(sq))];
}
pce = wN;
for(pceNum = 0; pceNum < board->pceNum[pce]; ++pceNum) {
sq = board->pList[pce][pceNum];
ASSERT(SqOnBoard(sq));
score += KnightTable[SQ64(sq)];
}
pce = bN;
for(pceNum = 0; pceNum < board->pceNum[pce]; ++pceNum) {
sq = board->pList[pce][pceNum];
ASSERT(SqOnBoard(sq));
score -= KnightTable[MIRROR64(SQ64(sq))];
}
pce = wB;
for(pceNum = 0; pceNum < board->pceNum[pce]; ++pceNum) {
sq = board->pList[pce][pceNum];
ASSERT(SqOnBoard(sq));
score += BishopTable[SQ64(sq)];
}
pce = bB;
for(pceNum = 0; pceNum < board->pceNum[pce]; ++pceNum) {
sq = board->pList[pce][pceNum];
ASSERT(SqOnBoard(sq));
score -= BishopTable[MIRROR64(SQ64(sq))];
}
pce = wR;
for(pceNum = 0; pceNum < board->pceNum[pce]; ++pceNum) {
sq = board->pList[pce][pceNum];
ASSERT(SqOnBoard(sq));
score += RookTable[SQ64(sq)];
}
pce = bR;
for(pceNum = 0; pceNum < board->pceNum[pce]; ++pceNum) {
sq = board->pList[pce][pceNum];
ASSERT(SqOnBoard(sq));
score -= RookTable[MIRROR64(SQ64(sq))];
}
if(board->side == WHITE) {
return score;
} else {
return -score;
}
}