Kings pieces and moves backwords for them

This commit is contained in:
Dan Ballard 2011-09-06 23:05:55 -07:00
parent 1e75bdd77a
commit 8270053048
1 changed files with 14 additions and 10 deletions

View File

@ -187,24 +187,31 @@ class Board
return [ c2[0] + (c1[0]-c2[0])/2, c2[1] + (c1[1]-c2[1])/2 ] return [ c2[0] + (c1[0]-c2[0])/2, c2[1] + (c1[1]-c2[1])/2 ]
end 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 # doesnt validate
def do_move(x, y, move, team) def do_move(x, y, move, team)
puts "MOVES " + move.to_s
if move[0].is_a?(Array) if move[0].is_a?(Array)
# jump # jump
move.each { |jump| move.each { |jump|
enemy = between([x,y], jump) enemy = between([x,y], jump)
set(enemy[0], enemy[1], BOARD_EMPTY) set(enemy[0], enemy[1], BOARD_EMPTY)
@stats[opposite_team(team)]['count'] -= 1 @stats[opposite_team(team)]['count'] -= 1
piece = get(x, y) move_piece([x,y], jump)
set(x, y, BOARD_EMPTY)
set(jump[0], jump[1], piece)
} }
else else
# move # move
piece = get(x, y) move_piece([x,y], move)
set(x, y, BOARD_EMPTY)
set(move[0], move[1], piece)
end end
end end
@ -248,6 +255,3 @@ class Board
end end
end end
b = Board.new()
b.setup()
puts b.to_s