mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 09:52:44 +00:00 
			
		
		
		
	 1682f0b760
			
		
	
	
		1682f0b760
		
	
	
	
	
		
			
			SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
		
			
				
	
	
		
			47 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2020, the SerenityOS developers.
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <AK/Function.h>
 | |
| #include <AK/NonnullOwnPtrVector.h>
 | |
| #include <LibChess/Chess.h>
 | |
| #include <math.h>
 | |
| 
 | |
| class MCTSTree {
 | |
| public:
 | |
|     enum EvalMethod {
 | |
|         Simulation,
 | |
|         Heuristic,
 | |
|     };
 | |
| 
 | |
|     MCTSTree(const Chess::Board& board, double exploration_parameter = sqrt(2), MCTSTree* parent = nullptr);
 | |
| 
 | |
|     MCTSTree& select_leaf();
 | |
|     MCTSTree& expand();
 | |
|     int simulate_game() const;
 | |
|     int heuristic() const;
 | |
|     void apply_result(int game_score);
 | |
|     void do_round();
 | |
| 
 | |
|     Chess::Move best_move() const;
 | |
|     double expected_value() const;
 | |
|     double uct(Chess::Color color) const;
 | |
|     bool expanded() const;
 | |
| 
 | |
|     EvalMethod eval_method() const { return m_eval_method; }
 | |
|     void set_eval_method(EvalMethod method) { m_eval_method = method; }
 | |
| 
 | |
| private:
 | |
|     NonnullOwnPtrVector<MCTSTree> m_children;
 | |
|     MCTSTree* m_parent { nullptr };
 | |
|     int m_white_points { 0 };
 | |
|     int m_simulations { 0 };
 | |
|     bool m_moves_generated { false };
 | |
|     double m_exploration_parameter;
 | |
|     EvalMethod m_eval_method { EvalMethod::Simulation };
 | |
|     Chess::Board m_board;
 | |
| };
 |