forked from gameguild-gg/SDL3-CPM-CMake-Example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMCTS.h
More file actions
45 lines (37 loc) · 939 Bytes
/
MCTS.h
File metadata and controls
45 lines (37 loc) · 939 Bytes
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
//
// Created by Alexandre Tolstenko Nogueira on 2024.03.21.
//
#ifndef UNTITLED130_MCTS_H
#define UNTITLED130_MCTS_H
#include "Board.h"
#include <iostream>
// monte carlo tree search node
struct __attribute__((packed)) Node {
size_t visits=0;
int32_t wins=0;
Node* parent= nullptr;
std::unordered_set<Node*> children;
Board board;
Node(Board board, Node* parent): board(board), parent(parent) {}
~Node();
double uct() const;
void print_node() const;
};
struct MCTS {
private:
int max_iterations;
Node* root = nullptr;
Node* best_child(Node* node) const;
Node* selection(Node* node);
Node* expansion(Node* node);
int simulation(Node* node);
void backpropagation(Node* node, int result);
public:
MCTS(int max_iterations): max_iterations(max_iterations) {}
~MCTS(){
delete root;
}
Board search(Board board, int iterations=0);
Board* current_board() const;
};
#endif //UNTITLED130_MCTS_H