diff --git a/checkers.rb b/checkers.rb index 9d36479..6ebb8a6 100644 --- a/checkers.rb +++ b/checkers.rb @@ -323,6 +323,7 @@ class Board return [x,y] end + # todo: deal with loss when no move avail def play() setup() color = '' @@ -358,23 +359,33 @@ class Board valid = false while !valid print "Move piece: " - from = gets + from = gets().strip! print "to: " - to = gets - + to = gets().strip! from = parse_coords(from) to = parse_coords(to) + puts to.to_s + " or " + from.to_s if !to or !from next end - if team(to[0], to[y]) != team + if team(from[0], from[1]) != team + next + end + if !piece_valid_moves(from[0], from[1], team).include?(to) next end valid = true end + do_move(from[0], from[1], to, team) else puts "AI MOVE" end + + if @stats[TEAM_1]['count'] == 0 + puts "Black wins!" + elsif @stats[TEAM_2]['count'] == 0 + puts "White wins!" + end team = opposite_team(team) turn += 1 end