Class: JustXiangqi::Ma
- Defined in:
- lib/just_xiangqi/pieces/ma.rb
Overview
Ma
The piece that can move in an l shape, but can be blocked by adjacent pieces.
Constant Summary collapse
- MOVEMENT_MAP =
{ [0,-1] => [[-1,-2], [1,-2]], [1,0] => [[2,-1], [2,1]], [0,1] => [[-1,2], [1,2]], [-1,0] => [[-2,-1], [-2,1]] }
Instance Method Summary collapse
-
#destinations(square, game_state) ⇒ SquareSet
All the squares that the piece can move to and/or capture.
Methods inherited from Piece
Constructor Details
This class inherits a constructor from JustXiangqi::Piece
Instance Method Details
#destinations(square, game_state) ⇒ SquareSet
All the squares that the piece can move to and/or capture.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/just_xiangqi/pieces/ma.rb', line 23 def destinations(square, game_state) _squares = MOVEMENT_MAP.map do |adjacent_map, destinations_map| adjacent = find_square_by_displacement(square, game_state, adjacent_map) if adjacent.nil? || adjacent.occupied? nil else find_valid_destinations(square, game_state, destinations_map) end end.flatten.compact SquareSet.new(squares: _squares) end |