class JustChess::Piece

Piece

A piece that can move on a chess board

Attributes

has_moved[R]

@return [Boolean] determines if the piece has moved.

has_moved?[R]

@return [Boolean] determines if the piece has moved.

Public Class Methods

new(id: , player_number: , type: nil, has_moved: false) click to toggle source
# File lib/just_chess/pieces/piece.rb, line 9
def initialize(id: , player_number: , type: nil, has_moved: false)
  @id = id
  @player_number = player_number
  @has_moved = has_moved
end

Public Instance Methods

as_json() click to toggle source

returns a serialized piece as a hash

@return [Hash]

# File lib/just_chess/pieces/piece.rb, line 36
def as_json
  {
    id: id,
    player_number: player_number,
    type: type,
    has_moved: has_moved?
  }
end
has_not_moved?() click to toggle source

Has the piece not moved yet?

@return [TrueClass, FalseClass]

# File lib/just_chess/pieces/piece.rb, line 29
def has_not_moved?
  !has_moved?
end
moved() click to toggle source

mark the piece as moved

@return [TrueClass]

# File lib/just_chess/pieces/piece.rb, line 22
def moved
  @has_moved = true
end