Skip to content

Instantly share code, notes, and snippets.

@jacknoble
Created December 2, 2013 21:00
Show Gist options
  • Select an option

  • Save jacknoble/7758869 to your computer and use it in GitHub Desktop.

Select an option

Save jacknoble/7758869 to your computer and use it in GitHub Desktop.
Our Sliding Piece class for chess.
require 'matrix'
require_relative "piece"
class SlidingPiece < Piece
def moves
move_possibilities = []
self.class::SLIDE_DIRECTIONS.each do |direction|
(1..7).each do |magnitude|
pos_move = (magnitude * Vector.elements(direction) + Vector.elements(@position)).to_a
move_possibilities << pos_move
break unless @board.tile_clear?(pos_move)
end
end
legal_moves(move_possibilities)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment