Class: Bchess::Pawn

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

Instance Attribute Summary

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?, #clear_path?, #initialize, #move, #moved, #to_s, #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 Method Details

#can_move_to_field?(dcolumn, drow) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
# File 'lib/bchess/pawn.rb', line 15

def can_move_to_field?(dcolumn, drow)
  super &&
    pawn_move(dcolumn, drow)
end

#can_take_on_field?(dcolumn, drow) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
# File 'lib/bchess/pawn.rb', line 20

def can_take_on_field?(dcolumn, drow)
  direction = white? ? 1 : -1
  by_diagonal(dcolumn, drow, 1) && (drow - row) == direction
end

#initiialize(*args) ⇒ Object



3
4
5
# File 'lib/bchess/pawn.rb', line 3

def initiialize(*args)
  super(args)
end

#nameObject



7
8
9
# File 'lib/bchess/pawn.rb', line 7

def name
  ''
end

#valid?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/bchess/pawn.rb', line 11

def valid?
  super && pawn_position?
end