backgammon/game.py
Anders Ladefoged 275689c002 Bot reimplemented with new representation.
Fixed bug where black could not bear off.
More tests written.
2018-02-22 14:01:28 +01:00

53 lines
1.4 KiB
Python

import time
from human import Human
from board import Board
from bot import Bot
from network import Network
from cup import Cup
class Game:
def __init__(self):
self.board = Board.initial_state
self.p1 = Bot(1)
self.p2 = Bot(-1)
self.cup = Cup()
def roll(self):
return self.cup.roll()
def play(self):
count = 0
while Board.outcome(self.board) == None:
count += 1
print("Turn:",count)
roll = self.roll()
#print("type of board: ", type(self.board))
print("Board:",self.board)
print("{} rolled: {}".format(self.p1.get_sym(), roll))
self.board = self.p1.make_move(self.board, self.p1.get_sym(), roll)
print(self.board)
print()
count += 1
roll = self.roll()
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))
g = Game()
g.play()