-
Notifications
You must be signed in to change notification settings - Fork 0
/
boardevaluator.cpp
114 lines (101 loc) · 2.73 KB
/
boardevaluator.cpp
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
#include "boardevaluator.h"
const short BoardEvaluator::pknight[64] =
{0, 4, 8, 10, 10, 8, 4, 0,
4, 8, 16, 20, 20, 16, 8, 4,
8, 16, 24, 28, 28, 24, 16, 8,
10, 20, 28, 32, 32, 28, 20, 10,
10, 20, 28, 32, 32, 28, 20, 10,
8, 16, 24, 28, 28, 24, 16, 8,
4, 8, 16, 20, 20, 16, 8, 4,
0, 4, 8, 10, 10, 8, 4, 0};
const short BoardEvaluator::pbishop[64] =
{14, 14, 14, 14, 14, 14, 14, 14,
14, 22, 18, 18, 18, 18, 22, 14,
14, 18, 22, 22, 22, 22, 18, 14,
14, 18, 22, 22, 22, 22, 18, 14,
14, 18, 22, 22, 22, 22, 18, 14,
14, 18, 22, 22, 22, 22, 18, 14,
14, 22, 18, 18, 18, 18, 22, 14,
14, 14, 14, 14, 14, 14, 14, 14};
const short BoardEvaluator::ppawn[64] =
{0, 0, 0, 0, 0, 0, 0, 0,
4, 4, 4, 0, 0, 4, 4, 4,
6, 8, 2, 10, 10, 2, 8, 6,
6, 8, 12, 16, 16, 12, 8, 6,
8, 12, 16, 24, 24, 16, 12, 8,
12, 16, 24, 32, 32, 24, 16, 12,
12, 16, 24, 32, 32, 24, 16, 12,
0, 0, 0, 0, 0, 0, 0, 0};
BoardEvaluator::BoardEvaluator()
{
}
int BoardEvaluator::getBoardScore(pieceColor color)
{
int total = 0;
for (int i = 0; i < 64; i++)
{
int c = i / 8, r = i % 8;
char p = Board::_board[c][r];
if (p != '\0')
{
pieceType type = Board::getType(p);
pieceColor pcolor = Board::getColor(p);
int result = 0;
switch (type)
{
case KING:
result += 9000;
break;
case QUEEN:
result += 1100;
result += pknight[i];
break;
case BISHOP:
result += 315;
result += pbishop[i];
break;
case KNIGHT:
result += 330;
result += pknight[i];
break;
case ROOK:
result += 500;
break;
case PAWN:
result += 100;
result += ppawn[i];
break;
case UNKNOWN:
break;
}
total += (color == pcolor) ? result : -result;
}
}
return total;
}
int BoardEvaluator::pieceValue(char c)
{
int value = 0;
switch (tolower(c))
{
case 'k':
value = 9000;
break;
case 'q':
value = 1100;
break;
case 'b':
value = 315;
break;
case 'n':
value = 330;
break;
case 'r':
value = 500;
break;
case 'p':
value = 100;
break;
}
return value;
}