-
Notifications
You must be signed in to change notification settings - Fork 0
/
evaluationAB.h
134 lines (119 loc) · 4.8 KB
/
evaluationAB.h
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
int whiteMovesAB(int moveCount,int bestSoFar);
int blackMovesAB(int moveCount,int bestSoFar);
int evaluationAB(int moveLabel,bool side,int moveCount,int bestSoFar)
{
int effect=0,capture = 0,a;
int piece = move[moveLabel].piece;
//------------------------------------------------------------------IMPLEMENTING THE MOVE--------------------------------------------------------------------//
//capture = move.implement();
capture = board[location[piece].first+move[moveLabel].goTo.first][location[piece].second+move[moveLabel].goTo.second];
if(capture != 0)
{
location[capture].first = -1;
location[capture].second = -1;
}
board[location[piece].first][location[piece].second] = 0;
board[location[piece].first+move[moveLabel].goTo.first][location[piece].second+move[moveLabel].goTo.second] = piece;
location[piece].first += move[moveLabel].goTo.first;
location[piece].second += move[moveLabel].goTo.second;
//-----------------------------------------------------------------EVALUATING THE MOVE-----------------------------------------------------------------------//
if(side == false) // side is black
{
if(checkmate(true)) //checking if the move made by black side puts the white king in checkmate
{
board[location[piece].first][location[piece].second] = capture;
if(capture != 0)
{
location[capture] = location[piece];
}
board[location[piece].first-move[moveLabel].goTo.first][location[piece].second-move[moveLabel].goTo.second] = piece;
location[piece].first -= move[moveLabel].goTo.first;
location[piece].second -= move[moveLabel].goTo.second;
return 1000; // value for checkmate
}
else
{
//calculating the effect of the move made
if(capture != 0)
{
effect = value[capture];
}
if (moveCount < moveLimit)
{
a = whiteMovesAB(moveCount,bestSoFar);
//----------------------------------REVERTING THE CHANGES MADE IN THE BOARD------------------------------------------------------------------//
board[location[piece].first][location[piece].second] = capture;
if(capture != 0)
{
location[capture] = location[piece];
}
board[location[piece].first-move[moveLabel].goTo.first][location[piece].second-move[moveLabel].goTo.second] = piece;
location[piece].first -= move[moveLabel].goTo.first;
location[piece].second -= move[moveLabel].goTo.second;
return (a+effect);
}
else
{
board[location[piece].first][location[piece].second] = capture;
if(capture != 0)
{
location[capture] = location[piece];
}
board[location[piece].first-move[moveLabel].goTo.first][location[piece].second-move[moveLabel].goTo.second] = piece;
location[piece].first -= move[moveLabel].goTo.first;
location[piece].second -= move[moveLabel].goTo.second;
return effect;
}
}
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------//
else if(side == true) // side is white
{
if(checkmate(false)) //checking if the move made by white side puts the black king in checkmate
{
board[location[piece].first][location[piece].second] = capture;
if(capture != 0)
{
location[capture] = location[piece];
}
board[location[piece].first-move[moveLabel].goTo.first][location[piece].second-move[moveLabel].goTo.second] = piece;
location[piece].first -= move[moveLabel].goTo.first;
location[piece].second -= move[moveLabel].goTo.second;
return (-1000); // value for checkmate
}
else
{
//calculating the effect of the move made
if(capture != 0)
{
effect = value[capture];
}
if (moveCount < moveLimit)
{
a = blackMovesAB(moveCount,bestSoFar);
//----------------------------------REVERTING THE CHANGES MADE IN THE BOARD------------------------------------------------------------------//
board[location[piece].first][location[piece].second] = capture;
if(capture != 0)
{
location[capture] = location[piece];
}
board[location[piece].first-move[moveLabel].goTo.first][location[piece].second-move[moveLabel].goTo.second] = piece;
location[piece].first -= move[moveLabel].goTo.first;
location[piece].second -= move[moveLabel].goTo.second;
return (a-effect);
}
else
{
board[location[piece].first][location[piece].second] = capture;
if(capture != 0)
{
location[capture] = location[piece];
}
board[location[piece].first-move[moveLabel].goTo.first][location[piece].second-move[moveLabel].goTo.second] = piece;
location[piece].first -= move[moveLabel].goTo.first;
location[piece].second -= move[moveLabel].goTo.second;
return (-effect);
}
}
}
}