backgammon/game.py

35 lines
979 B
Python
Raw Normal View History

2018-02-07 15:08:59 +00:00
from human import Human
2018-02-05 21:31:34 +00:00
from board import Board
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
self.p1 = Human(1)
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):
while True:
2018-02-07 15:27:03 +00:00
roll = self.roll()
print("{} rolled: {}".format(self.p1.get_sym(), roll))
2018-02-13 13:38:49 +00:00
self.board = self.p1.do_move(self.board, roll)
if Board.is_winner(board, self.p1.get_sym()):
print("{} won!".format(self.p1.get_sym()))
break
2018-02-07 15:27:03 +00:00
roll = self.roll()
print("{} rolled: {}".format(self.p1.get_sym(), roll))
2018-02-13 13:38:49 +00:00
self.board = self.p2.do_move(self.board, roll)
if Board.is_winner(board, self.p2.get_sym()):
print("{} won!".format(self.p2.get_sym()))
break
2018-02-05 21:31:34 +00:00
g = Game()
g.play()