Skip to content
Browse files

added convenience method to Pentago::Board

  • Loading branch information...
1 parent e52b2e3 commit 77ad11674bc375cbc9837c7cd0518f48fc52f4f5 @etrepat committed Jan 30, 2011
Showing with 13 additions and 2 deletions.
  1. +13 −2 lib/pentago/board.rb
View
15 lib/pentago/board.rb
@@ -76,6 +76,14 @@ def rotate(square, direction = :clockwise)
@squares = board
end
+
+ def empty_squares
+ squares.map.with_index { |sq, index| index unless sq }.compact
+ end
+
+ def empty_positions
+ empty_squares.map { |sq| [sq%COLS, sq/ROWS] }
+ end
def moves
squares.compact.size
@@ -112,6 +120,10 @@ def ==(board)
end
alias_method :eql?, :==
+
+ def dup
+ Board.restore(squares)
+ end
def self.restore(board)
restored = Board.new
@@ -139,5 +151,4 @@ def valid_position?(x, y)
r.include?(x) && r.include?(y)
end
end
-end
-
+end

0 comments on commit 77ad116

Please sign in to comment.
Something went wrong with that request. Please try again.