diff --git a/src/azul.rs b/src/azul.rs index 3771391..334d465 100644 --- a/src/azul.rs +++ b/src/azul.rs @@ -214,15 +214,15 @@ impl Game { return Ok(game) }; - let target = match game_move.2 { - 1..=5 =>&mut board.patterns - .split_at_mut(game_move.2 - 1).1 - .split_at_mut(game_move.2).0 - .first().unwrap_or(return Err("something went wrong while borrowing the target")), + // This is a workaround for borrowing _only_that board pattern + let target: &mut Vec = match game_move.2 { + 1..=5 => &mut board.patterns[game_move.2 - 1], _ => 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") } diff --git a/src/main.rs b/src/main.rs index bac077f..714e554 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,8 @@ fn main() -> Result<(), &'static str>{ let mut game = Game::new(2)?; game.fill()?; 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); Ok(()) }