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 ]
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