wip mirror
This commit is contained in:
parent
f1461985ac
commit
f9f4405943
|
|
@ -34,9 +34,9 @@ impl Default for Bot {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let strategy = DefaultStrategy::default();
|
let strategy = DefaultStrategy::default();
|
||||||
Self {
|
Self {
|
||||||
player_id: 2,
|
player_id: 1,
|
||||||
strategy: Box::new(strategy),
|
strategy: Box::new(strategy),
|
||||||
// color: Color::Black,
|
color: Color::White,
|
||||||
// schools_enabled: false,
|
// schools_enabled: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -64,26 +64,17 @@ impl Bot {
|
||||||
|
|
||||||
pub fn handle_event(&mut self, event: &GameEvent) -> Option<GameEvent> {
|
pub fn handle_event(&mut self, event: &GameEvent) -> Option<GameEvent> {
|
||||||
let game = self.strategy.get_mut_game();
|
let game = self.strategy.get_mut_game();
|
||||||
let mirror_event = if let GameEvent::Move {
|
let internal_event = if self.color == Color::Black {
|
||||||
player_id,
|
&event.get_mirror()
|
||||||
moves: (move1, move2),
|
|
||||||
} = event
|
|
||||||
{
|
|
||||||
&GameEvent::Move {
|
|
||||||
player_id: *player_id,
|
|
||||||
moves: (move1.mirror(), move2.mirror()),
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
event
|
event
|
||||||
};
|
};
|
||||||
game.consume(if self.color == Color::White {
|
|
||||||
event
|
game.consume(internal_event);
|
||||||
} else {
|
|
||||||
mirror_event
|
|
||||||
});
|
|
||||||
if game.stage == Stage::Ended {
|
if game.stage == Stage::Ended {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
// TODO mirror
|
||||||
if game.active_player_id == self.player_id {
|
if game.active_player_id == self.player_id {
|
||||||
return match game.turn_stage {
|
return match game.turn_stage {
|
||||||
TurnStage::MarkAdvPoints => Some(GameEvent::Mark {
|
TurnStage::MarkAdvPoints => Some(GameEvent::Mark {
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,8 @@ impl Default for DefaultStrategy {
|
||||||
let game = GameState::default();
|
let game = GameState::default();
|
||||||
Self {
|
Self {
|
||||||
game,
|
game,
|
||||||
player_id: 2,
|
player_id: 1,
|
||||||
color: Color::Black,
|
color: Color::White,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -733,6 +733,58 @@ impl GameEvent {
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_mirror(&self) -> Self {
|
||||||
|
// let mut mirror = self.clone();
|
||||||
|
let mirror_player_id = if let Some(player_id) = self.player_id() {
|
||||||
|
if player_id == 1 {
|
||||||
|
2
|
||||||
|
} else {
|
||||||
|
1
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
|
match self {
|
||||||
|
Self::PlayerJoined { player_id: _, name } => Self::PlayerJoined {
|
||||||
|
player_id: mirror_player_id,
|
||||||
|
name: name.clone(),
|
||||||
|
},
|
||||||
|
Self::PlayerDisconnected { player_id: _ } => GameEvent::PlayerDisconnected {
|
||||||
|
player_id: mirror_player_id,
|
||||||
|
},
|
||||||
|
Self::Roll { player_id: _ } => GameEvent::Roll {
|
||||||
|
player_id: mirror_player_id,
|
||||||
|
},
|
||||||
|
Self::RollResult { player_id: _, dice } => GameEvent::RollResult {
|
||||||
|
player_id: mirror_player_id,
|
||||||
|
dice: *dice,
|
||||||
|
},
|
||||||
|
Self::Mark {
|
||||||
|
player_id: _,
|
||||||
|
points,
|
||||||
|
} => GameEvent::Mark {
|
||||||
|
player_id: mirror_player_id,
|
||||||
|
points: *points,
|
||||||
|
},
|
||||||
|
Self::Go { player_id: _ } => GameEvent::Go {
|
||||||
|
player_id: mirror_player_id,
|
||||||
|
},
|
||||||
|
Self::Move {
|
||||||
|
player_id: _,
|
||||||
|
moves: (move1, move2),
|
||||||
|
} => Self::Move {
|
||||||
|
player_id: mirror_player_id,
|
||||||
|
moves: (move1.mirror(), move2.mirror()),
|
||||||
|
},
|
||||||
|
Self::BeginGame { goes_first } => GameEvent::BeginGame {
|
||||||
|
goes_first: (if *goes_first == 1 { 2 } else { 1 }),
|
||||||
|
},
|
||||||
|
Self::EndGame { reason } => GameEvent::EndGame { reason: *reason },
|
||||||
|
Self::PlayError => GameEvent::PlayError,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue