49 lines
773 B
Ruby
49 lines
773 B
Ruby
# coding: utf-8
|
|
|
|
require './board'
|
|
require './bot'
|
|
require './human'
|
|
|
|
@board = Board.new
|
|
|
|
|
|
def play_game player, bot
|
|
while true do
|
|
system "clear"
|
|
|
|
print @board.to_s
|
|
player.move
|
|
|
|
if @board.is_full? then
|
|
print @board.to_s
|
|
print "\nGame is done!\n"
|
|
break
|
|
end
|
|
|
|
if @board.any_winner? then
|
|
print @board.to_s
|
|
print "\nSomeone won!\n"
|
|
break
|
|
end
|
|
|
|
bot.move @board
|
|
|
|
if @board.is_full? then
|
|
print @board.to_s
|
|
print "\nGame is done!\n"
|
|
break
|
|
end
|
|
|
|
if @board.any_winner? then
|
|
print @board.to_s
|
|
print "\nSomeone won!\n"
|
|
break
|
|
end
|
|
system "clear"
|
|
end
|
|
end
|
|
|
|
player = Human.new @board, " X "
|
|
bot = Bot.new @board, " O "
|
|
play_game player, bot
|