Skip to content

Commit

Permalink
Fix Coordinate::NEIGHBOURS constant
Browse files Browse the repository at this point in the history
It currently didn't actually remove [0, 0]. That was
a mistake but it was self corrected by other checks
later which is why it still works correctly.

Fixing this will make neighbours iteration a bit faster.
  • Loading branch information
radanskoric committed Sep 22, 2024
1 parent 9aa83e5 commit bee4123
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/minesweeper/coordinate.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Minesweeper
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) }

def neighbour?(other)
[(self.x - other.x).abs, (self.y - other.y).abs].max <= 1
Expand Down

0 comments on commit bee4123

Please # to comment.