Sha256: f3ed6a58caa2b1b28b327ca644a75b907d5472c41d1946447a0e268ae53d58ca

Contents?: true

Size: 802 Bytes

Versions: 1

Compression:

Stored size: 802 Bytes

Contents

require 'just_xiangqi/pieces/piece'

module JustXiangqi
  
  # = Jiang
  #
  # The piece that can move 1 space orthogonally within the palace.
  class Jiang < Piece
    PALACE_X_COORDINATES = [3, 4, 5]
    PALACE_Y_COORDINATES = [0, 1, 2, 7, 8, 9]

    # All the squares that the piece can move to and/or capture.
    #
    # @param [Square] square
    #   the origin square.
    #
    # @param [GameState] game_state
    #   the current game state.
    #
    # @return [SquareSet]
    def destinations(square, game_state)
      palace_squares(game_state).orthogonal(square).at_range(square, 1).unoccupied_or_occupied_by_opponent(player_number)
    end

    private

    def palace_squares(game_state)
      game_state.squares.where(x: PALACE_X_COORDINATES, y: PALACE_Y_COORDINATES) 
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
just_xiangqi-0.1.0 lib/just_xiangqi/pieces/jiang.rb