Class: Bchess::King

Inherits:
Piece
  • Object
show all
Defined in:
lib/bchess/king.rb

Constant Summary collapse

KINGS_REACH =
1

Instance Attribute Summary collapse

Attributes inherited from Piece

#color, #column, #row

Instance Method Summary collapse

Methods inherited from Piece

#additional_info?, #at?, #black?, #by_diagonal, #by_line, #can_be_promoted?, #can_en_passant?, #can_make_move?, #can_move?, #can_move_or_take?, #can_take?, #can_take_on_field?, #clear_path?, #initialize, #to_s, #valid?, #valid_position_after?, #white?

Methods included from FieldBetweenHelpers

#column_fields, #diagonal_fields, #fields_between, #row_fields

Methods included from BoardHelpers

#castle_detected?, #en_passant_detected?, #field, #invalid_data?, #kings_present?, #pawn_long_move_detected?, #promotion_detected?, #to_column, #to_row

Constructor Details

This class inherits a constructor from Bchess::Piece

Instance Attribute Details

#movedObject (readonly)

Returns the value of attribute moved.



6
7
8
# File 'lib/bchess/king.rb', line 6

def moved
  @moved
end

Instance Method Details

#can_move_to_field?(dcolumn, drow) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
# File 'lib/bchess/king.rb', line 22

def can_move_to_field?(dcolumn, drow)
  super &&
    (
      (dcolumn, drow, KINGS_REACH) ||
      by_diagonal(dcolumn, drow, KINGS_REACH)
  )
end

#initiialize(*args) ⇒ Object



8
9
10
11
# File 'lib/bchess/king.rb', line 8

def initiialize(*args)
  super(args)
  @moved = false
end

#move(dcolumn, drow) ⇒ Object



17
18
19
20
# File 'lib/bchess/king.rb', line 17

def move(dcolumn, drow)
  super(dcolumn, drow)
  @moved = true
end

#nameObject



13
14
15
# File 'lib/bchess/king.rb', line 13

def name
  'K'
end