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