basic play interface

This commit is contained in:
Dan Ballard 2011-09-13 21:54:01 -07:00
parent e383c27a8d
commit 5b1d69ebfe
1 changed files with 15 additions and 4 deletions

View File

@ -323,6 +323,7 @@ class Board
return [x,y] return [x,y]
end end
# todo: deal with loss when no move avail
def play() def play()
setup() setup()
color = '' color = ''
@ -358,23 +359,33 @@ class Board
valid = false valid = false
while !valid while !valid
print "Move piece: " print "Move piece: "
from = gets from = gets().strip!
print "to: " print "to: "
to = gets to = gets().strip!
from = parse_coords(from) from = parse_coords(from)
to = parse_coords(to) to = parse_coords(to)
puts to.to_s + " or " + from.to_s
if !to or !from if !to or !from
next next
end 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 next
end end
valid = true valid = true
end end
do_move(from[0], from[1], to, team)
else else
puts "AI MOVE" puts "AI MOVE"
end end
if @stats[TEAM_1]['count'] == 0
puts "Black wins!"
elsif @stats[TEAM_2]['count'] == 0
puts "White wins!"
end
team = opposite_team(team) team = opposite_team(team)
turn += 1 turn += 1
end end