Sha256: a9cd10d892fbd7c6c65d514c2aed42ce66e50f52017f08cc94d519171a503c04

Contents?: true

Size: 772 Bytes

Versions: 1

Compression:

Stored size: 772 Bytes

Contents

require 'just_xiangqi/pieces/piece'

module JustXiangqi

  # = Xiang
  #
  # The piece that can move 2 spaces diagonally on its side of the river
  class Xiang < Piece
    # 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)
      players_side_squares(game_state).diagonal(square).at_range(square, 2).unoccupied_or_occupied_by_opponent(player_number) 
    end

    private

    def players_side_squares(game_state)
      condition = player_number == 2 ? -> (y) { y <= 4 } : -> (y) { y >= 5 }
      game_state.squares.where(y: condition)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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