Skip to content

Commit b775d49

Browse files
committed
Add MCE-MCTS
1 parent 5c4d96f commit b775d49

File tree

4 files changed

+204
-35
lines changed

4 files changed

+204
-35
lines changed

src/cpp/search/eval.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@
1111
namespace hyperion {
1212
namespace engine {
1313

14+
// ======================================================================================
15+
// ======================================================================================
16+
// ====================UNCOMENT BELOW FOR MCTS WITH STATIC EVALUATION====================
17+
// ======================================================================================
18+
// ======================================================================================
1419
// For fun I Will add a temporary static evaluation to see how good I can make this. a lot of this will be refactored but hey, the source code is on github so who cares if I cange it
1520
// Static evaluation for fun:
16-
21+
/*
1722
// --- Piece Values ---
1823
constexpr int PAWN_VALUE = 100;
1924
constexpr int KNIGHT_VALUE = 320;
@@ -59,6 +64,7 @@ const int* piece_square_tables[] = {
5964
queen_pst,
6065
king_pst
6166
};
67+
*/
6268
//--
6369
/* static_evaluate */
6470
//--
@@ -70,6 +76,7 @@ const int* piece_square_tables[] = {
7076
// The final score is returned from the perspective of the side to move, a common
7177
// practice in negamax-style search algorithms. This means a positive score is always
7278
// advantageous for the current player.
79+
/*
7380
double static_evaluate(const core::Position& pos) {
7481
int score = 0;
7582
@@ -106,7 +113,7 @@ double static_evaluate(const core::Position& pos) {
106113
// If it's Black's turn, a positive score is good for White, so its bad for Black (-score).
107114
return (pos.get_side_to_move() == WHITE) ? static_cast<double>(score) : -static_cast<double>(score);
108115
}
109-
116+
*/
110117
//--
111118
/* limited_depth_playout */
112119
//--
@@ -119,6 +126,7 @@ double static_evaluate(const core::Position& pos) {
119126
// its depth limit, it calls `static_evaluate` on the final position. The result is
120127
// then normalized to a value between -1.0 and 1.0 using `std::tanh`, making it
121128
// suitable for use in a Monte Carlo Tree Search (MCTS) algorithm.
129+
/*
122130
double limited_depth_playout(core::Position position, std::mt19937& gen) {
123131
core::MoveGenerator move_gen;
124132
std::vector<core::Move> move_list;
@@ -166,8 +174,13 @@ double limited_depth_playout(core::Position position, std::mt19937& gen) {
166174
// tanh is a great function for this. We scale the score so that +/- 3 pawns is a near certain win/loss.
167175
return std::tanh(final_score / (PAWN_VALUE * 3.0));
168176
}
177+
*/
178+
// ======================================================================================
179+
// ======================================================================================
180+
// ====================UNCOMENT ABOVE FOR MCTS WITH STATIC EVALUATION====================
181+
// ======================================================================================
182+
// ======================================================================================
169183

170-
// NOTE: THIS WILL BE COMPLETLY REWORKED ONCE WE HAVE A WORKING NN TO EVALUATE THE POS
171184

172185
//--
173186
/* random_playout */
@@ -178,7 +191,6 @@ double limited_depth_playout(core::Position position, std::mt19937& gen) {
178191
// position: The board state from which the random playout will begin. It is passed by value to avoid modifying the original
179192
// gen: A reference to a Mersenne Twister random number generator for selecting moves
180193
// The result of the game from the perspective of the starting player: 1.0 for a win, -1.0 for a loss, and 0.0 for a draw
181-
/*
182194
double random_playout(core::Position position, std::mt19937& gen) {
183195
core::MoveGenerator move_gen;
184196
std::vector<core::Move> move_list;
@@ -220,7 +232,7 @@ double random_playout(core::Position position, std::mt19937& gen) {
220232
}
221233
// This line is un reachable as the loop only terminates via a return, but it prevents compiler warnings
222234
return 0.0;
223-
}*/
235+
}
224236

225237
} // namespace engine
226238
} // namespace hyperion

src/cpp/search/eval.hpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,25 @@
77
namespace hyperion {
88
namespace engine {
99

10-
// A simple static evaluation function
10+
double random_playout(core::Position position, std::mt19937& gen);
11+
12+
// ======================================================================================
13+
// ======================================================================================
14+
// ====================UNCOMENT BELOW FOR MCTS WITH STATIC EVALUATION====================
15+
// ======================================================================================
16+
// ======================================================================================
17+
/*
18+
// satic evaluation function
1119
double static_evaluate(const core::Position& pos);
1220
1321
// Simulates a limited number of pseudo-legal random moves, then evaluates.
1422
double limited_depth_playout(core::Position position, std::mt19937& gen);
15-
23+
*/
24+
// ======================================================================================
25+
// ======================================================================================
26+
// ====================UNCOMENT ABOVE FOR MCTS WITH STATIC EVALUATION====================
27+
// ======================================================================================
28+
// ======================================================================================
1629
} // namespace engine
1730
} // namespace hyperion
1831

0 commit comments

Comments
 (0)