def setupGame(self,config): """Game configuration is stored in a dict() in the following format: config = { gameType --> TODO p1 --> Player List One : [Player] p2 --> Player List Two : [Player] rule --> GO_Rule.CHINESE | GO_Rule.JAPANESE boardSize --> int in 9,13,19 handicap --> int in 0-13 komi --> double in 0-10 mainTime --> (hours,minutes) overTime --> TODO overTimeCount --> TODO """ self.config = config self.BLACK = config["p1"] self.WHITE = config["p2"] self.board = GO_Board(config["boardSize"]) self.turn = self.BLACK self.moves = [] self.result = None self.isOver = False
class GO_Game: defaultConfig = dict(p1=GO_Player("X"),p2=GO_Player("O"),rule=GO_Rule.JAPANESE, boardSize=19,handicap=0,\ komi=6.5,mainTime=(0,20)) def setupGame(self,config): """Game configuration is stored in a dict() in the following format: config = { gameType --> TODO p1 --> Player List One : [Player] p2 --> Player List Two : [Player] rule --> GO_Rule.CHINESE | GO_Rule.JAPANESE boardSize --> int in 9,13,19 handicap --> int in 0-13 komi --> double in 0-10 mainTime --> (hours,minutes) overTime --> TODO overTimeCount --> TODO """ self.config = config self.BLACK = config["p1"] self.WHITE = config["p2"] self.board = GO_Board(config["boardSize"]) self.turn = self.BLACK self.moves = [] self.result = None self.isOver = False def getResult(self,deaths): if self.config["rule"] == GO_Rule.JAPANESE: rule = JapaneseRule(self.board,deaths) else: rule = ChineseRule(self.board,deaths) self.result = rule.gameResult() return self.result def printResult(self): if self.result: return "{}: {},{}: {}".format(self.config["p1"].name,self.result["black"], \ self.config["p2"].name,self.result["white"]) else: return None def whoseTurn(self): """ Player whoseTurn() """ return self.turn def whoseTurn_color(self): if self.turn == self.BLACK: return GO_Stone.BLACK else: return GO_Stone.WHITE def getPlayerStone(self,player): if player in self.BLACK: return GO_Stone.BLACK else: return GO_Stone.WHITE def makeMove(self,row,col): if self.turn == self.BLACK: color = GO_Stone.BLACK else: color = GO_Stone.WHITE try: self.board.updateBoard(row, col, color) self._advanceTurn() except RuleException as e: print("Invalid move: {}".format(e.args)) def forfeitMove(self): self._advanceTurn() self.board.KO = (-1,-1) def resign(self,player): #should produce a Result Object self.isOver = True return "{} won the game".format(player.toStr()) def isGameOver(self): return self.isOver def display(self): self.board.printBoard() #######private helper functions for GO_Game########### def _advanceTurn(self): if self.turn == self.BLACK: self.turn = self.WHITE else: self.turn = self.BLACK