2018-01-13 22:00:51 +00:00
|
|
|
# coding: utf-8
|
|
|
|
|
2018-01-23 01:04:38 +00:00
|
|
|
require './board'
|
|
|
|
require './bot'
|
|
|
|
require './human'
|
2018-01-13 22:00:51 +00:00
|
|
|
|
2018-01-23 01:04:38 +00:00
|
|
|
@board = Board.new
|
2018-01-13 22:00:51 +00:00
|
|
|
|
|
|
|
|
2018-01-23 01:04:38 +00:00
|
|
|
def play_game player, bot
|
2018-01-13 22:00:51 +00:00
|
|
|
while true do
|
2018-01-23 01:13:50 +00:00
|
|
|
system "clear"
|
2018-01-13 22:00:51 +00:00
|
|
|
|
2018-01-23 01:04:38 +00:00
|
|
|
print @board.to_s
|
|
|
|
player.move
|
2018-01-13 22:00:51 +00:00
|
|
|
|
2018-01-23 01:04:38 +00:00
|
|
|
if @board.is_full? then
|
|
|
|
print @board.to_s
|
2018-01-23 01:13:50 +00:00
|
|
|
print "\nGame is done!\n"
|
2018-01-23 01:04:38 +00:00
|
|
|
break
|
2018-01-13 22:00:51 +00:00
|
|
|
end
|
2018-01-23 01:04:38 +00:00
|
|
|
|
|
|
|
if @board.any_winner? then
|
|
|
|
print @board.to_s
|
2018-01-23 01:13:50 +00:00
|
|
|
print "\nSomeone won!\n"
|
2018-01-23 01:04:38 +00:00
|
|
|
break
|
|
|
|
end
|
|
|
|
|
|
|
|
bot.move @board
|
2018-01-13 22:00:51 +00:00
|
|
|
|
2018-01-23 01:04:38 +00:00
|
|
|
if @board.is_full? then
|
|
|
|
print @board.to_s
|
2018-01-23 01:13:50 +00:00
|
|
|
print "\nGame is done!\n"
|
2018-01-23 01:04:38 +00:00
|
|
|
break
|
|
|
|
end
|
|
|
|
|
|
|
|
if @board.any_winner? then
|
|
|
|
print @board.to_s
|
2018-01-23 01:13:50 +00:00
|
|
|
print "\nSomeone won!\n"
|
2018-01-23 01:04:38 +00:00
|
|
|
break
|
|
|
|
end
|
2018-01-23 01:13:50 +00:00
|
|
|
system "clear"
|
2018-01-13 22:00:51 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-23 01:04:38 +00:00
|
|
|
player = Human.new @board, " X "
|
|
|
|
bot = Bot.new @board, " O "
|
|
|
|
play_game player, bot
|