-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathheuristic.rs
35 lines (31 loc) · 1.05 KB
/
heuristic.rs
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
use crate::game::{Move, Player, State};
/// A heuristic can be implemented by an algorithm.
/// This allows us to automatically generate algorithm implementations via their heuristic.
pub trait Heuristic {
/// The type returned by the heuristic
type Key: Ord;
/// Evaluate a state using this heuristic for a given player
fn evaluate(
&self,
rng: &mut rand::rngs::ThreadRng,
state: &State,
player: &Player,
) -> Self::Key;
/// Evaluate how the heuristic would change after a move
/// Sometimes this should be implemented as it can be faster than
/// placing the piece and then evaluating
fn evaluate_move(
&self,
rng: &mut rand::rngs::ThreadRng,
state: &State,
player: &Player,
mv: &Move,
) -> Self::Key {
// By default, just place the piece and then evaluate
let mut state = state.clone();
state.place_piece(mv);
self.evaluate(rng, &state, player)
}
/// String name for the heuristic
fn name(&self) -> String;
}