From 82700530484f95865e7e9a1628e0e4520eb5aee6 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Tue, 6 Sep 2011 23:05:55 -0700 Subject: [PATCH] Kings pieces and moves backwords for them --- checkers.rb | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/checkers.rb b/checkers.rb index 1d899be..50bc3f2 100644 --- a/checkers.rb +++ b/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