Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
BakerNet committed Aug 25, 2024
1 parent f41cc81 commit 41a9e1b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
17 changes: 9 additions & 8 deletions minesweeper-lib/src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,12 @@ impl Minesweeper {

fn has_no_revealed_nearby(&self, cell_point: BoardPoint) -> bool {
let neighbors = self.board.neighbors(cell_point);
neighbors
.iter()
.copied()
.map(|n| self.board.neighbors(n))
.flatten()
let nearby = neighbors
.into_iter()
.flat_map(|n| self.board.neighbors(n))
.collect::<HashSet<_>>();
nearby
.into_iter()
.filter(|i| self.board[*i].1.revealed)
.count()
== 0
Expand Down Expand Up @@ -427,17 +428,17 @@ impl Minesweeper {
if unplanted_mines == 0 {
return;
}
let has_revealed_neighbor = |bp: &BoardPoint| {
let has_revealed_neighbor = |bp: BoardPoint| {
self.board
.neighbors(*bp)
.neighbors(bp)
.iter()
.any(|c| self.board[*c].1.revealed)
};
let mut take_available: Vec<BoardPoint> = self
.available
.iter()
.filter(|&bp| {
*bp != first_cell && !neighbors.contains(bp) && !has_revealed_neighbor(bp)
*bp != first_cell && !neighbors.contains(bp) && !has_revealed_neighbor(*bp)
})
.copied()
.collect::<Vec<_>>();
Expand Down
4 changes: 2 additions & 2 deletions web/src/app/minesweeper/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ pub async fn get_game(game_id: String) -> Result<GameInfo, ServerFnError> {
game_log.log,
players_simple,
);
if player_num.is_some() {
completed_minesweeper.player_board_final(player_num.unwrap().into())
if let Some(p) = player_num {
completed_minesweeper.player_board_final(p.into())
} else if game.max_players == 0 {
completed_minesweeper.player_board_final(0)
} else {
Expand Down

0 comments on commit 41a9e1b

Please sign in to comment.