Skip to content

Commit

Permalink
I forgor that one case
Browse files Browse the repository at this point in the history
  • Loading branch information
Kapsyloffer committed Feb 18, 2024
1 parent 18f1db5 commit ee47e88
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/rules/game_tile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ impl Tile {
if on_board {
//If a future rock position is not empty then the move is not valid.
if size == 2 && state[rock_y as usize][rock_x as usize] != Tile::Empty {
return false;
if state[new_y as usize][new_x as usize] != Tile::Empty || state[step_y as usize][step_x as usize] != Tile::Empty {
return false;
}
}
}

Expand Down
26 changes: 26 additions & 0 deletions src/rules/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1184,4 +1184,30 @@ fn squish_test_3(){
//Not supposed to do that.
assert!(!Tile::is_valid(&board, (2, 2), (0, 0), true));
assert!(!Tile::aggressive_move(&mut board, (2, 2), (0, 0)));
}


#[test]
fn squish_test_4(){
let state: [[Tile; 4]; 4] = [
[Tile::Empty, Tile::Empty, Tile::Empty, Tile::Black],
[Tile::Empty, Tile::Empty, Tile::Empty, Tile::Empty],
[Tile::Empty, Tile::Empty, Tile::Empty, Tile::Empty],
[Tile::White, Tile::Empty, Tile::Empty, Tile::Empty],
];

let target_state: [[Tile; 4]; 4] = [
[Tile::Empty, Tile::Empty, Tile::Empty, Tile::Black],
[Tile::Empty, Tile::Empty, Tile::White, Tile::Empty],
[Tile::Empty, Tile::Empty, Tile::Empty, Tile::Empty],
[Tile::Empty, Tile::Empty, Tile::Empty, Tile::Empty],
];

let mut board = Board::new_board(Tile::Black, Tile::Black);
board.set_state(&state);

//Not supposed to do that.
assert!(Tile::is_valid(&board, (3, 0), (1, 2), true));
assert!(Tile::aggressive_move(&mut board, (3, 0), (1, 2)));
assert_eq!(*board.get_state(), target_state);
}

0 comments on commit ee47e88

Please sign in to comment.