factory to patterns with spill

This commit is contained in:
Daniel Olsen 2021-01-03 05:16:04 +01:00
parent 0aaee4f6f4
commit 3e086c485a
2 changed files with 8 additions and 7 deletions

View File

@ -214,15 +214,15 @@ impl Game {
return Ok(game) return Ok(game)
}; };
let target = match game_move.2 { // This is a workaround for borrowing _only_that board pattern
1..=5 =>&mut board.patterns let target: &mut Vec<Tile> = match game_move.2 {
.split_at_mut(game_move.2 - 1).1 1..=5 => &mut board.patterns[game_move.2 - 1],
.split_at_mut(game_move.2).0
.first().unwrap_or(return Err("something went wrong while borrowing the target")),
_ => return Err("That's not a valid pattern line") _ => return Err("That's not a valid pattern line")
}; };
if target.first() != Some(&sel_tile) { println!("{:#?}", target);
if target.first() != None && target.first() != Some(&sel_tile) {
return Err("You cannot place that tile on that pattern-line, because there are already other tiles with a different color there") return Err("You cannot place that tile on that pattern-line, because there are already other tiles with a different color there")
} }

View File

@ -6,7 +6,8 @@ fn main() -> Result<(), &'static str>{
let mut game = Game::new(2)?; let mut game = Game::new(2)?;
game.fill()?; game.fill()?;
println!("{:#?}", game); println!("{:#?}", game);
let game2 = game.do_move(GameMove(0, Tile::Red, 0))?; let game2 = game.do_move(GameMove(0, Tile::Red, 2))?;
let game2 = game2.do_move(GameMove(1, Tile::Red, 2))?;
println!("{:#?}", game2); println!("{:#?}", game2);
Ok(()) Ok(())
} }