bot
This commit is contained in:
parent
80d4c256c0
commit
24ddcce233
10 changed files with 188 additions and 10 deletions
|
|
@ -296,6 +296,27 @@ impl Board {
|
|||
self.get_field_checkers(field).map(|(count, color)| color)
|
||||
}
|
||||
|
||||
/// returns the list of Fields containing Checkers of the Color
|
||||
pub fn get_color_fields(&self, color: Color) -> Vec<(usize, i8)> {
|
||||
match color {
|
||||
Color::White => self
|
||||
.positions
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|&(_, count)| *count > 0)
|
||||
.map(|(i, count)| (i + 1, *count))
|
||||
.collect(),
|
||||
Color::Black => self
|
||||
.positions
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|&(_, count)| *count < 0)
|
||||
.rev()
|
||||
.map(|(i, count)| (i + 1, (0 - count)))
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get the corner field for the color
|
||||
pub fn get_color_corner(&self, color: &Color) -> Field {
|
||||
if color == &Color::White {
|
||||
|
|
@ -407,4 +428,11 @@ mod tests {
|
|||
let player = Player::new("".into(), Color::White);
|
||||
assert!(board.set(&Color::White, 23, -3).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_color_fields() {
|
||||
let board = Board::new();
|
||||
assert_eq!(board.get_color_fields(Color::White), vec![(1, 15)]);
|
||||
assert_eq!(board.get_color_fields(Color::Black), vec![(24, 15)]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -165,6 +165,14 @@ impl GameState {
|
|||
.next()
|
||||
}
|
||||
|
||||
pub fn player_color_by_id(&self, player_id: &PlayerId) -> Option<Color> {
|
||||
self.players
|
||||
.iter()
|
||||
.filter(|(id, _)| *id == player_id)
|
||||
.map(|(_, player)| player.color)
|
||||
.next()
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Rules checks
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
mod game;
|
||||
pub use game::{EndGameReason, GameEvent, GameState, Stage};
|
||||
pub use game::{EndGameReason, GameEvent, GameState, Stage, TurnStage};
|
||||
|
||||
mod player;
|
||||
pub use player::{Color, Player, PlayerId};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue