-
Notifications
You must be signed in to change notification settings - Fork 1
/
evaluate.js
101 lines (89 loc) · 2.93 KB
/
evaluate.js
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
// piece tables for Xiangqi are from:
// Li, Cuanqi
// 2008 "Using AdaBoost to Implement Chinese Chess Evaluation Functions", UCLA thesis
var soldierTable = [
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, -2, 0, 4, 0, -2, 0, 0,
2, 0, 8, 0, 8, 0, 8, 0, 2,
6, 12, 18, 18, 20, 18, 18, 12, 6,
10, 20, 30, 34, 40, 34, 30, 20, 10,
14, 26, 42, 60, 80, 60, 42, 26, 14,
18, 36, 56, 80, 120, 80, 56, 36, 18,
0, 3, 6, 9, 12, 9, 6, 3, 0
];
var horseTable = [
0, -4, 0, 0, 0, 0, 0, -4, 0,
0, 2, 4, 4, -2, 4, 4, 2, 0,
4, 2, 8, 8, 4, 8, 8, 2, 4,
2, 6, 8, 6, 10, 6, 8, 6, 2,
4, 12, 16, 14, 12, 14, 16, 12, 4,
6, 16, 14, 18, 16, 18, 14, 16, 6,
8, 24, 18, 24, 20, 24, 18, 24, 8,
12, 14, 16, 20, 18, 20, 16, 14, 12,
4, 10, 28, 16, 8, 16, 28, 10, 4,
4, 8, 16, 12, 4, 12, 16, 8, 4
];
var chariotTable = [
-2, 10, 6, 14, 12, 14, 6, 10, -2,
8, 4, 8, 16, 8, 16, 8, 4, 8,
4, 8, 6, 14, 12, 14, 6, 8, 4,
6, 10, 8, 14, 14, 14, 8, 10, 6,
12, 16, 14, 20, 20, 20, 14, 16, 12,
12, 14, 12, 18, 18, 18, 12, 14, 12,
12, 18, 16, 22, 22, 22, 16, 18, 12,
12, 12, 12, 18, 18, 18, 12, 12, 12,
16, 20, 18, 24, 26, 24, 18, 20, 16,
14, 14, 12, 18, 16, 18, 12, 14, 14
]
var cannonTable = [
0, 0, 2, 6, 6, 6, 2, 0, 0,
0, 2, 4, 6, 6, 6, 4, 2, 0,
4, 0, 8, 6, 10, 6, 8, 0, 4,
0, 0, 0, 2, 4, 2, 0, 0, 0,
-2, 0, 4, 2, 6, 2, 4, 0, -2,
0, 0, 0, 2, 8, 2, 0, 0, 0,
0, 0, -2, 4, 10, 4, -2, 0, 0,
2, 2, 0, -10, -8, -10, 0, 2, 2,
2, 2, 0, -4, -14, -4, 0, 2, 2,
6, 4, 0, -10, -12, -10, 0, 4, 6
]
function evalPosition() {
var score = scoreMaterial();
var piece;
var square = 0;
for (square = 0; square < NUM_SPACES; square++) {
piece = GameBoard.pieces[square];
if (piece) {
//switch statement?
switch(piece) {
case PIECES.rH:
score += horseTable[square];
break;
case PIECES.rR:
score += chariotTable[square];
break;
case PIECES.rC:
score += cannonTable[square];
break;
case PIECES.rS:
score += soldierTable[square];
break;
case PIECES.bH:
score -= horseTable[MIRROR_BOARD[square]];
break;
case PIECES.bR:
score -= chariotTable[MIRROR_BOARD[square]];
break;
case PIECES.bC:
score -= cannonTable[MIRROR_BOARD[square]];
break;
case PIECES.bS:
score -= soldierTable[MIRROR_BOARD[square]];
break;
}
}
}
return score;
}