Skip to content

Commit

Permalink
Minesweeper code improvement, noticed by Predrag
Browse files Browse the repository at this point in the history
It wasn't actually removing the origin. The whole game
still worked as expected because of other checks but
removing the origin makes it more robust and faster
so it's a valuable improvement.
  • Loading branch information
radanskoric committed Sep 24, 2024
1 parent 43f32d4 commit 2d2341f
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Finally, if we hit a mine we exit early with `:lose`. Otherwise we check if all
The only thing missing here is the neighbours method on the coordinate. We implement it by first creating a list of offsets to all 8 neighbours:
```ruby
Coordinate = Data.define(:x, :y) do
NEIGHBOURS = (Enumerator.product([-1, 0, 1], [-1, 0, 1]).to_a - [0, 0]).map { |x, y| self.new(x, y) }
NEIGHBOURS = (Enumerator.product([-1, 0, 1], [-1, 0, 1]).to_a - [[0, 0]]).map { |x, y| self.new(x, y) }
# ...
end
```
Expand Down

0 comments on commit 2d2341f

Please sign in to comment.