Kings pieces and moves backwords for them
This commit is contained in:
parent
1e75bdd77a
commit
8270053048
24
checkers.rb
24
checkers.rb
|
@ -187,24 +187,31 @@ class Board
|
|||
return [ c2[0] + (c1[0]-c2[0])/2, c2[1] + (c1[1]-c2[1])/2 ]
|
||||
end
|
||||
|
||||
def move_piece(c1, c2)
|
||||
piece = get(c1[0], c1[1])
|
||||
set(c1[0], c1[1], BOARD_EMPTY)
|
||||
set(c2[0], c2[1], piece)
|
||||
if team(c2[0], c2[1]) == TEAM_1 and c2[1] == BOARD_SIZE-1
|
||||
set(c2[0], c2[1], TEAM_1_KING)
|
||||
elsif (team(c2[0], c2[1]) == TEAM_2 and c2[1] == 0)
|
||||
set(c2[0], c2[1], TEAM_2_KING)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# doesnt validate
|
||||
def do_move(x, y, move, team)
|
||||
puts "MOVES " + move.to_s
|
||||
if move[0].is_a?(Array)
|
||||
# jump
|
||||
move.each { |jump|
|
||||
enemy = between([x,y], jump)
|
||||
set(enemy[0], enemy[1], BOARD_EMPTY)
|
||||
@stats[opposite_team(team)]['count'] -= 1
|
||||
piece = get(x, y)
|
||||
set(x, y, BOARD_EMPTY)
|
||||
set(jump[0], jump[1], piece)
|
||||
move_piece([x,y], jump)
|
||||
}
|
||||
else
|
||||
# move
|
||||
piece = get(x, y)
|
||||
set(x, y, BOARD_EMPTY)
|
||||
set(move[0], move[1], piece)
|
||||
move_piece([x,y], move)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -248,6 +255,3 @@ class Board
|
|||
end
|
||||
end
|
||||
|
||||
b = Board.new()
|
||||
b.setup()
|
||||
puts b.to_s
|
||||
|
|
Loading…
Reference in New Issue