Class: JustChess::Knight

Inherits:
Piece
  • Object
show all
Defined in:
lib/just_chess/pieces/knight.rb

Overview

Knight

The piece that jumps over pieces 1v2h or 2v1h

Instance Attribute Summary

Attributes inherited from Piece

#has_moved, #id, #player_number

Instance Method Summary collapse

Methods inherited from Piece

#as_json, #can_move?, #capture_squares, #has_not_moved?, #initialize, #move_squares, #moved, #opponent, #potential_capture_squares, #type

Constructor Details

This class inherits a constructor from JustChess::Piece

Instance Method Details

#destinations(square, game_state) ⇒ SquareSet

All the squares that the piece can move to and/or capture.

Parameters:

  • square (Square)

    the origin square.

  • game_state (GameState)

    the current game state.

Returns:



19
20
21
# File 'lib/just_chess/pieces/knight.rb', line 19

def destinations(square, game_state)
  game_state.squares.not_orthogonal_or_diagonal(square).at_range(square,2).unoccupied_or_occupied_by_opponent(player_number)
end