Class: ChessVwong::Pawn

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

Instance Attribute Summary collapse

Attributes inherited from Piece

#color, #current_space, #ep_kill, #neighbours, #turns

Instance Method Summary collapse

Methods inherited from Piece

#initialize, #valid_space?

Constructor Details

This class inherits a constructor from ChessVwong::Piece

Instance Attribute Details

#doubledObject

Returns the value of attribute doubled.



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

def doubled
  @doubled
end

Instance Method Details

#characterObject



4
5
6
# File 'lib/chess_vwong/pawn.rb', line 4

def character
  color == 'w' ? "\u{2659}" : "\u{265F}"
end

#generate_neighbours(current_space, node1 = nil, node2 = nil) ⇒ Object

Generate all possible Neighbouring Spaces



9
10
11
12
13
14
15
16
# File 'lib/chess_vwong/pawn.rb', line 9

def generate_neighbours(current_space, node1 = nil, node2 = nil)
  color == 'w' ? moves = [[0, -1]] : moves = [[0, 1]]
  first_turn?(current_space, moves)
  kill_move(node1, node2, moves)
  moves.each do |move|
    neigbour_helper(current_space, move[0], move[1])
  end
end

#kill_move(node1, node2, moves) ⇒ Object

if there is a enemy piece nearby, then give option to attack



19
20
21
22
23
24
25
26
27
# File 'lib/chess_vwong/pawn.rb', line 19

def kill_move(node1, node2, moves)
  if color == 'w'
    moves << [-1, -1] if  kill_conditions(node1, 'b') || ep_kill.include?("L")
    moves << [1, -1] if kill_conditions(node2, 'b') || ep_kill.include?("R")
  else
    moves << [-1, 1] if kill_conditions(node1, 'w') || ep_kill.include?("L")
    moves << [1, 1] if kill_conditions(node1, 'w') || ep_kill.include?("R")
  end
end