Skip to content

Commit

Permalink
#38 cleaned up stepping code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Kapsyloffer committed Mar 5, 2024
1 parent a65fe8b commit 8d29eef
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/rules/game_tile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ impl Tile {
//Leapfrog
else if boardstate[step_y][step_x] != Tile::Empty && stepping {
boardstate[rock_y][rock_x] = boardstate[step_y][step_x];
//Clear the spot behind us. (The D'Lcrantz method)
boardstate[step_y][step_x] = Tile::Empty;
}
//Edge case; diagonal 2 step pushes that are still on the board.
Expand All @@ -220,15 +219,8 @@ impl Tile {
}

//If the rock gets pushed off the edge.
if !on_board {
if stepping {
if boardstate[end_y][end_x] != Tile::Empty {
boardstate[end_y][end_x] = Tile::Empty;
}
else if boardstate[step_y][step_x] != Tile::Empty{
boardstate[step_y][step_x] = Tile::Empty;
}
}
if !on_board && stepping {
boardstate[step_y][step_x] = Tile::Empty;
}

//Move the rock.
Expand Down
26 changes: 26 additions & 0 deletions src/rules/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1204,4 +1204,30 @@ fn squish_test_4(){
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);
}


#[test]
fn squish_test_5(){
let state: [[Tile; 4]; 4] = [
[Tile::Empty, Tile::Empty, Tile::Empty, 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],
];

let target_state: [[Tile; 4]; 4] = [
[Tile::Empty, Tile::Empty, Tile::Empty, Tile::White],
[Tile::Empty, Tile::Empty, Tile::Empty, 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, (2, 1), (0, 3), true));
assert!(Tile::aggressive_move(&mut board, (2, 1), (0, 3)));
assert_eq!(*board.get_state(), target_state);
}

0 comments on commit 8d29eef

Please sign in to comment.