-
Notifications
You must be signed in to change notification settings - Fork 0
/
eval.cpp
119 lines (101 loc) · 3.79 KB
/
eval.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
115
116
117
118
119
//
// Created by benrr on 9/19/2023.
//
#include "eval.h"
#include "find.h"
float CAST_INT_TO_FLOAT[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0};
[[maybe_unused]] int DEFAULT_PIECE_WEIGHTS[] = {0, 1, 3, 3, 5, 9, 100};
float PIECE_WEIGHTS_MIDGAME[] = {0.0, 0.8, 3.2, 3.3, 4.7, 9.4};
float PIECE_WEIGHTS_THRESHOLD[] = {0.0, 0.9, 3.2, 3.3, 4.8, 9.4};
float PIECE_WEIGHTS_ENDGAME[] = {0.0, 1.0, 3.2, 3.3, 5.3, 9.4};
float* PIECE_WEIGHTS[] = {PIECE_WEIGHTS_MIDGAME, PIECE_WEIGHTS_THRESHOLD, PIECE_WEIGHTS_ENDGAME};
float BISHOP_PAIR_BONUS_MIDGAME = 0.3;
float BISHOP_PAIR_BONUS_THRESHOLD = 0.4;
float BISHOP_PAIR_BONUS_ENDGAME = 0.5;
float BISHOP_PAIR_BONUS[] = {BISHOP_PAIR_BONUS_MIDGAME, BISHOP_PAIR_BONUS_THRESHOLD, BISHOP_PAIR_BONUS_ENDGAME};
float SECOND_ROOK_PENALTY_MIDGAME = -0.2;
float SECOND_ROOK_PENALTY_THRESHOLD = 0.1;
float SECOND_ROOK_PENALTY_ENDGAME = -0.3;
float SECOND_ROOK_PENALTY[] = {SECOND_ROOK_PENALTY_MIDGAME, SECOND_ROOK_PENALTY_THRESHOLD, SECOND_ROOK_PENALTY_ENDGAME};
float BOARD_SQUARE_WEIGHTS[8][8] = {
{.11, .13, .13, .13, .13, .13, .13, .11},
{.13, .15, .17, .17, .17, .17, .15, .13},
{.13, .17, .19, .19, .19, .19, .17, .13},
{.13, .17, .19, .20, .20, .19, .17, .13},
{.13, .17, .19, .20, .20, .19, .17, .13},
{.13, .17, .19, .19, .19, .19, .17, .13},
{.13, .15, .17, .17, .17, .17, .15, .13},
{.11, .13, .13, .13, .13, .13, .13, .11}
};
// Function to evaluate material on the board with better weights
float evaluate(std::vector<std::vector<int>>& chessboard) {
float materialBalance = 0.0;
int whitePieces[] = {0, 0, 0, 0, 0, 0, 0};
int blackPieces[] = {0, 0, 0, 0, 0, 0, 0};
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
int piece = chessboard[i][j];
if (piece > 0) {
whitePieces[piece - 1] += 1;
materialBalance += BOARD_SQUARE_WEIGHTS[i][j];
}
else if (piece < 0) {
blackPieces[abs(piece) - 1] += 1;
materialBalance -= BOARD_SQUARE_WEIGHTS[i][j];
}
}
}
int gamestate = 0;
if (whitePieces[5] != blackPieces[5]) {
gamestate = 1;
}
if (whitePieces[5] == 0) {
gamestate = 2;
}
for (int i = 0; i < 6; i++) {
materialBalance += CAST_INT_TO_FLOAT[whitePieces[i]] * PIECE_WEIGHTS[gamestate][i];
materialBalance -= CAST_INT_TO_FLOAT[blackPieces[i]] * PIECE_WEIGHTS[gamestate][i];
}
if (whitePieces[2] >= 2) {
materialBalance += BISHOP_PAIR_BONUS[gamestate];
}
if (blackPieces[2] >= 2) {
materialBalance -= BISHOP_PAIR_BONUS[gamestate];
}
if (whitePieces[3] >= 2) {
materialBalance += SECOND_ROOK_PENALTY[gamestate];
}
if (blackPieces[3] >= 2) {
materialBalance -= SECOND_ROOK_PENALTY[gamestate];
}
return materialBalance;
}
/**
// Function to evaluate material on the board with better weights
float updateEval(std::vector<std::vector<int>>& chessboard, float oldEval, move move) {
int gamestate = 0;
if (whitePieces[5] != blackPieces[5]) {
gamestate = 1;
}
if (whitePieces[5] == 0) {
gamestate = 2;
}
for (int i = 0; i < 6; i++) {
materialBalance += CAST_INT_TO_FLOAT[whitePieces[i]] * PIECE_WEIGHTS[gamestate][i];
materialBalance -= CAST_INT_TO_FLOAT[blackPieces[i]] * PIECE_WEIGHTS[gamestate][i];
}
if (whitePieces[2] >= 2) {
materialBalance += BISHOP_PAIR_BONUS[gamestate];
}
if (blackPieces[2] >= 2) {
materialBalance -= BISHOP_PAIR_BONUS[gamestate];
}
if (whitePieces[3] >= 2) {
materialBalance += SECOND_ROOK_PENALTY[gamestate];
}
if (blackPieces[3] >= 2) {
materialBalance -= SECOND_ROOK_PENALTY[gamestate];
}
return materialBalance;
}
**/