-
Notifications
You must be signed in to change notification settings - Fork 0
/
value.c
executable file
·104 lines (100 loc) · 2.44 KB
/
value.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
/*
* value.c
* Ohodnoceni pozice
*/
#include"data.h"
#define abs(x) (x > 0 ? x : -x)
#define sign(x) (x == 0 ? 0 : x / abs(x))
int Evaluate(TGame * aGame)
{
int lMoveCount;
TMoveList lList;
lMoveCount = MoveGen(aGame, lList, 1);
if (lMoveCount == 0)
{
if (InCheck(aGame->sidetomove, aGame)) /* MAT */
return -1 * MATV;
else
return 0; /* PAT */
}
else
return EvaluateM(aGame);
}
int EvaluateM(TGame * aGame)
{
int i, v = 0, x, y, b2s = 0, c2s = 0;
v += 2 * (aGame->whiteplayer.rochada[0] - aGame->blackplayer.rochada[0]);
v += aGame->whiteplayer.rochada[1] - aGame->blackplayer.rochada[1];
v += aGame->whiteplayer.rochada[2] - aGame->blackplayer.rochada[2];
v += 2 * (sign(aGame->board[3][3]) + sign(aGame->board[3][4])
+ sign(aGame->board[4][3]) + sign(aGame->board[4][4]));
v += sign(aGame->board[2][2]) +
sign(aGame->board[2][3]) +
sign(aGame->board[2][4]) +
sign(aGame->board[2][5]) +
sign(aGame->board[3][2]) +
sign(aGame->board[3][5]) +
sign(aGame->board[4][2]) +
sign(aGame->board[4][5]) +
sign(aGame->board[5][2]) +
sign(aGame->board[5][3]) +
sign(aGame->board[5][4]) +
sign(aGame->board[5][5]);
for (i = 1; i < 16; i++)
{
switch (aGame->whiteplayer.pieces[i].fig)
{
case WPWN:
v += PWNV;
if (aGame->whiteplayer.pieces[i].pos.x > 4) v++;
if (aGame->whiteplayer.pieces[i].pos.x > 5) v++;
break;
case WKNT:
v += KNTV;
x = aGame->whiteplayer.pieces[i].pos.x;
y = aGame->whiteplayer.pieces[i].pos.y;
if (x > 0 && y > 0 && x < 7 && y < 7) v++;
break;
case WBSP:
v += BSPV;
b2s++;
if (b2s > 1) v++;
break;
case WROK:
v += ROKV;
break;
case WQEN:
v += QENV;
break;
}
switch (aGame->blackplayer.pieces[i].fig)
{
case BPWN:
v -= PWNV;
if (aGame->blackplayer.pieces[i].pos.x < 3) v--;
if (aGame->blackplayer.pieces[i].pos.x < 2) v--;
break;
case BKNT:
v -= KNTV;
x = aGame->blackplayer.pieces[i].pos.x;
y = aGame->blackplayer.pieces[i].pos.y;
if (x > 0 && y > 0 && x < 7 && y < 7) v--;
break;
case BBSP:
v -= BSPV;
c2s++;
if (c2s > 1) v--;
break;
case BROK:
v -= ROKV;
break;
case BQEN:
v -= QENV;
break;
}
}
if (aGame->sidetomove == WHITE)
return v;
else
return -v;
}