pub trait Rollout {
type State: State;
type ResponseGenerator: ResponseGenerator<State = Self::State>;
// Required method
fn play(
&self,
state: &Self::State,
response_generator: &Self::ResponseGenerator,
) -> f32;
}Expand description
Rollout trait for MCTS search
The Rollout trait defines the interface for performing rollouts in a game state. It is used by the MCTS algorithm to simulate game play and evaluate the potential outcomes of different moves. It is implemented for specific game states in the game-specific code.
§Type Parameters
S- Game state type
§Examples
#[derive(Debug, Clone, Default)]
struct TestAction;
struct TestResponseGen;
impl ResponseGenerator for TestResponseGen {
type State = TestGameState;
fn generate(&self, _state: &TestGameState) -> Vec<TestAction> { vec![TestAction] }
}
struct TestRollout;
impl Rollout for TestRollout {
type State = TestGameState;
type ResponseGenerator = TestResponseGen;
fn play(&self, state: &TestGameState, _rg: &TestResponseGen) -> f32 { state.value as f32 }
}
let state = TestGameState { value: 42 };
let rollout = TestRollout;
let rg = TestResponseGen;
let score = rollout.play(&state, &rg);
assert_eq!(score, 42.0);Required Associated Types§
type ResponseGenerator: ResponseGenerator<State = Self::State>
Required Methods§
Sourcefn play(
&self,
state: &Self::State,
response_generator: &Self::ResponseGenerator,
) -> f32
fn play( &self, state: &Self::State, response_generator: &Self::ResponseGenerator, ) -> f32
Performs a rollout (simulation) from the given state using the provided response generator, and returns the evaluated value.
The rollout is a simulation of the game from the given state to a terminal state, following simple heuristics or random moves. The result is a score in the range [-1.0, 1.0], where 1.0 indicates a win for the computer player, -1.0 indicates a loss, and 0.0 indicates a draw.
§Arguments
state- The game state to perform the rollout fromresponse_generator- The response generator for producing legal actions
§Returns
[-1.0, 1.0] score representing the outcome of the rollout from the perspective of the computer player.