-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnull.rs
53 lines (40 loc) · 1016 Bytes
/
null.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use crate::game::{Game, PlayerIndex};
use serde::Serialize;
// A trivial game with no moves
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize)]
enum Never {}
#[derive(Clone)]
struct NullGame;
#[derive(PartialEq, Eq, Debug, Default, Clone, Copy)]
struct Unit;
impl std::fmt::Display for Unit {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "()")
}
}
impl PlayerIndex for Unit {
fn to_index(&self) -> usize {
0
}
}
impl Game for NullGame {
type S = Unit;
type A = Option<Never>;
type P = Unit;
fn apply(_: Self::S, _: &Option<Never>) -> Self::S {
unreachable!();
}
fn generate_actions(_: &Self::S, _: &mut Vec<Self::A>) {}
fn is_terminal(_: &Self::S) -> bool {
true
}
fn notation(_: &Self::S, _: &Option<Never>) -> String {
unreachable!();
}
fn winner(_: &Self::S) -> Option<Unit> {
None
}
fn player_to_move(_: &Self::S) -> Unit {
Unit
}
}