Created
December 2, 2013 21:00
-
-
Save jacknoble/7758869 to your computer and use it in GitHub Desktop.
Our Sliding Piece class for chess.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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