Module: Boards::MovablePiece

Included in:
Chess::Board
Defined in:
lib/boardgame_engine/board_modules.rb

Overview

Boards with movable pieces

Instance Method Summary collapse

Instance Method Details

#move_piece(start_location, end_location, set_start_to: nil) ⇒ Piece

Move a piece from at a start location to an end location. Should be called after checking that the movement is valid board and game logic wise.

to nil

Parameters:

  • start_location (<Type>)

    the starting location of the piece

  • end_location (<Type>)

    the destination of the piece

  • set_start_to (<Type>) (defaults to: nil)

    what to place at the start location. defaults

Returns:

  • (Piece)

    the piece at the destination



253
254
255
256
257
258
259
260
# File 'lib/boardgame_engine/board_modules.rb', line 253

def move_piece(start_location, end_location, set_start_to: nil)
  piece = get_piece_at(start_location)
  set_piece_at(start_location, set_start_to)
  destination_piece = get_piece_at(end_location)
  set_piece_at(end_location, piece)

  destination_piece
end