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-25 19:37:24 +00:00
|
|
|
def is_over? board, cur
|
|
|
|
if board.any_winner? then
|
|
|
|
system "clear"
|
|
|
|
print board.to_s
|
|
|
|
print "\n#{cur} won!\n"
|
|
|
|
return true
|
|
|
|
elsif board.is_full? then
|
|
|
|
system "clear"
|
|
|
|
print board.to_s
|
|
|
|
print "\nGame is done!\n"
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
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
|
2018-01-25 19:37:24 +00:00
|
|
|
|
2018-01-23 01:04:38 +00:00
|
|
|
player.move
|
2018-01-13 22:00:51 +00:00
|
|
|
|
2018-01-25 19:37:24 +00:00
|
|
|
if is_over? @board, player.val then break end
|
2018-01-23 01:04:38 +00:00
|
|
|
|
|
|
|
bot.move @board
|
2018-01-13 22:00:51 +00:00
|
|
|
|
2018-01-25 19:37:24 +00:00
|
|
|
if is_over? @board, bot.val then break end
|
|
|
|
|
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
|