Skip to content

Commit

Permalink
Add game over case for ties
Browse files Browse the repository at this point in the history
  • Loading branch information
aymud committed Feb 19, 2024
1 parent c6480c9 commit 6ae5662
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ fn main() {
ui.set_board(board_model);
ui.set_is_game_over(true);
}
// In case of ties.
let board: Vec<GamePieceData> = get_game_board(&ui);
if is_game_board_full(&board) {
ui.set_is_game_over(true);
}
}
});

Expand Down Expand Up @@ -76,6 +81,15 @@ fn get_indices_of_winning_combination(grid: &[GamePieceData]) -> Option<(usize,
None // No winner found.
}

fn is_game_board_full(board: &[GamePieceData]) -> bool {
for cell in board.iter() {
if cell.marker.is_empty() {
return false;
}
}
true
}

fn clear_game_board(board: &mut [GamePieceData]) {
for cell in board.iter_mut() {
cell.marker = "".into();
Expand Down

0 comments on commit 6ae5662

Please sign in to comment.