Permalink
Browse files

Pieces: remove duplication in #raw_directional_moves

  • Loading branch information...
1 parent e896148 commit 589f0546dd893255db6c599e9d3012233aae2202 @alex-tan committed Feb 5, 2013
@@ -73,5 +73,13 @@ def opponent?(variable)
def ally?(variable)
variable.kind_of?(Piece) && variable.color == color
end
+
+ # Returns the coordinates of itself in a given game.
+ # @param [Game] game
+ # @return [Coordinate]
+ def coordinates_in_game(game)
+ board = game.board
+ board.coordinates_of(self)
+ end
end
end
@@ -2,8 +2,7 @@ module RubyChessBoard
class Bishop < Piece
# @private
def raw_directional_moves(game)
- board = game.board
- position = board.coordinates_of(self)
+ position = coordinates_in_game(game)
CoordinateCollection.new sets: [
position.relative_coordinate_set(1, 1),
@@ -2,8 +2,7 @@ module RubyChessBoard
class King < Piece
# @private
def raw_directional_moves(game)
- board = game.board
- position = board.coordinates_of(self)
+ position = coordinates_in_game(game)
CoordinateCollection.new coordinates: [
position.relative_coordinate(0, 1),
@@ -2,8 +2,7 @@ module RubyChessBoard
class Knight < Piece
# @private
def raw_directional_moves(game)
- board = game.board
- position = board.coordinates_of(self)
+ position = coordinates_in_game(game)
CoordinateCollection.new coordinates: [
position.relative_coordinate(1, 2),
@@ -15,7 +15,7 @@ def rank_directions
# @private
def raw_directional_moves(game)
board = game.board
- position = board.coordinates_of(self)
+ position = coordinates_in_game(game)
collection = CoordinateCollection.new
@@ -2,8 +2,7 @@ module RubyChessBoard
class Queen < Piece
# @private
def raw_directional_moves(game)
- board = game.board
- position = board.coordinates_of(self)
+ position = coordinates_in_game(game)
CoordinateCollection.new sets: [
position.relative_coordinate_set(0, 1),
@@ -2,8 +2,7 @@ module RubyChessBoard
class Rook < Piece
# @private
def raw_directional_moves(game)
- board = game.board
- position = board.coordinates_of(self)
+ position = coordinates_in_game(game)
CoordinateCollection.new sets: [
position.relative_coordinate_set(0, 1),

0 comments on commit 589f054

Please sign in to comment.