2018-02-22 13:01:28 +00:00
|
|
|
import time
|
2018-02-07 15:08:59 +00:00
|
|
|
from human import Human
|
2018-02-05 21:31:34 +00:00
|
|
|
from board import Board
|
2018-02-05 22:50:31 +00:00
|
|
|
from bot import Bot
|
2018-02-07 14:31:05 +00:00
|
|
|
from network import Network
|
2018-02-07 15:27:03 +00:00
|
|
|
from cup import Cup
|
2018-02-05 21:31:34 +00:00
|
|
|
|
|
|
|
class Game:
|
|
|
|
def __init__(self):
|
2018-02-13 13:38:49 +00:00
|
|
|
self.board = Board.initial_state
|
2018-02-22 13:01:28 +00:00
|
|
|
self.p1 = Bot(1)
|
2018-02-13 13:38:49 +00:00
|
|
|
self.p2 = Bot(-1)
|
2018-02-07 15:27:03 +00:00
|
|
|
self.cup = Cup()
|
2018-02-07 14:31:05 +00:00
|
|
|
|
2018-02-07 15:27:03 +00:00
|
|
|
def roll(self):
|
|
|
|
return self.cup.roll()
|
2018-02-05 21:31:34 +00:00
|
|
|
|
|
|
|
def play(self):
|
2018-02-22 13:01:28 +00:00
|
|
|
count = 0
|
|
|
|
while Board.outcome(self.board) == None:
|
|
|
|
count += 1
|
|
|
|
|
|
|
|
print("Turn:",count)
|
|
|
|
|
2018-02-07 15:27:03 +00:00
|
|
|
roll = self.roll()
|
2018-02-22 13:01:28 +00:00
|
|
|
|
|
|
|
#print("type of board: ", type(self.board))
|
|
|
|
print("Board:",self.board)
|
2018-02-07 15:27:03 +00:00
|
|
|
print("{} rolled: {}".format(self.p1.get_sym(), roll))
|
|
|
|
|
2018-02-22 13:01:28 +00:00
|
|
|
self.board = self.p1.make_move(self.board, self.p1.get_sym(), roll)
|
|
|
|
|
|
|
|
print(self.board)
|
|
|
|
|
|
|
|
print()
|
|
|
|
|
|
|
|
count += 1
|
|
|
|
|
2018-02-07 15:27:03 +00:00
|
|
|
roll = self.roll()
|
2018-02-22 13:01:28 +00:00
|
|
|
print("{} rolled: {}".format(self.p2.get_sym(), roll))
|
|
|
|
self.board = self.p2.make_move(self.board, self.p2.get_sym(), roll)
|
|
|
|
|
|
|
|
|
|
|
|
if Board.outcome(self.board)[1] > 0:
|
|
|
|
print_winner = "1: White, " + str(Board.outcome(self.board))
|
|
|
|
else:
|
|
|
|
print_winner = "-1: Black " + str(Board.outcome(self.board))
|
|
|
|
print("The winner is {}!".format(print_winner))
|
|
|
|
print("Final board:",Board.pretty(self.board))
|
2018-02-05 21:31:34 +00:00
|
|
|
|
2018-02-22 13:01:28 +00:00
|
|
|
g = Game()
|
2018-02-05 21:31:34 +00:00
|
|
|
g.play()
|