forked from ethz-gtc/npc-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.rs
40 lines (34 loc) · 869 Bytes
/
player.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
/*
* SPDX-License-Identifier: Apache-2.0 OR MIT
* © 2020-2022 ETH Zurich and other contributors, see AUTHORS.txt for details
*/
use std::fmt;
use npc_engine_core::AgentId;
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
pub enum Player {
O,
X,
}
impl Player {
pub fn from_agent(agent: AgentId) -> Self {
match agent {
AgentId(0) => Player::O,
AgentId(1) => Player::X,
AgentId(id) => panic!("Invalid AgentId {id}"),
}
}
pub fn to_agent(self) -> AgentId {
match self {
Player::O => AgentId(0),
Player::X => AgentId(1),
}
}
}
impl fmt::Display for Player {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Player::O => write!(f, "O"),
Player::X => write!(f, "X"),
}
}
}