def playGame(self, fileName = None, load = False): # Reinitialize all of the internal states self.state_.reset() if load: self.loadStateFromFile(fileName) while not self.state_.isEnd(): playerNumber = 1 if (self.state_.getTurn() == 1) else 2 if self.verbose_ >= 3: util.printGame(self.state_) print "Player %d: " % (playerNumber) print "Score: %d" % self.state_.getScore() if (playerNumber == 1): move = self.playerOneAgent_.getAction(self.state_) else: move = self.playerTwoAgent_.getAction(self.state_) self.state_ = self.state_.generateSuccessor(move) if self.state_.getScore() < 0: self.winner_ = -1 self.playerOneAgent_.isWinner(False) self.playerTwoAgent_.isWinner(True) elif self.state_.getScore() > 0: self.winner_ = 1 self.playerOneAgent_.isWinner(True) self.playerTwoAgent_.isWinner(False) else: # Tie self.winner_ = 0 if self.verbose_ >= 2: print "Winner is: ", 1 if self.winner_ > 0 else 2 print "Score: %d" % self.state_.getScore() util.printGame(self.state_)
def __printInternalScores(self, score, move, depth, alpha, beta, successor): if self.verbose_ >= 3: print "Calculated score for agent: ", score, move print "Depth: ", depth print "Alpha: ", alpha print "Beta: ", beta if self.verbose_ >= 4: util.printGame(successor)