basic play interface
This commit is contained in:
parent
e383c27a8d
commit
5b1d69ebfe
19
checkers.rb
19
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
|
||||
|
|
Loading…
Reference in New Issue