def play(self): """Simulates a game of Hog by calling hog.play with the GUI strategies. If the player destroys the window prematurely (i.e. in the middle of a game), a HogGUIException is raised to exit out of play's loop. Otherwise, the widget will be destroyed, but the strategy will continue waiting. """ self.turn = 1 - self.turn self.switch(0) self.s_labels[0].text = "0" self.s_labels[1].text = "0" self.status_label.text = "" try: commentary = hog.both( hog.announce_highest(0), hog.both(hog.announce_highest(1), hog.announce_lead_changes())) score, opponent_score = hog.play(self.strategy, self.strategy, dice=self.make_dice(6), say=commentary) except HogGUIException: pass else: self.s_labels[0].text = score self.s_labels[1].text = opponent_score winner = 0 if score > opponent_score else 1 self.status_label.text = "Game over! {} wins!".format(name(winner))
def RunGame(): """ A wrapper function that runs the Hog game. """ self.score0, self.score1 = play(Strategy0, Strategy1) self.state = -1 self.HasScore = True
def winner(strategy0, strategy1): """Return 0 if strategy0 wins against strategy1, and 1 otherwise.""" score0, score1 = play(strategy0, strategy1) if score0 > score1: return 0 else: return 1
def play(self): """Simulates a game of Hog by calling hog.play with the GUI strategies. If the player destroys the window prematurely (i.e. in the middle of a game), a HogGUIException is raised to exit out of play's loop. Otherwise, the widget will be destroyed, but the strategy will continue waiting. """ self.turn = 1 - self.turn self.switch(0) self.s_labels[0].text = '0' self.s_labels[1].text = '0' self.status_label.text = '' try: commentary = hog.both(hog.announce_highest(0), hog.both(hog.announce_highest(1), hog.announce_lead_changes())) score, opponent_score = hog.play(self.strategy, self.strategy, dice=self.make_dice(6), say=commentary) except HogGUIException: pass else: self.s_labels[0].text = score self.s_labels[1].text = opponent_score winner = 0 if score > opponent_score else 1 self.status_label.text = 'Game over! {} wins!'.format( name(winner))
def play(self): self.turn = 1 - self.turn self.switch(0) self.s_labels[0].text = '0' self.s_labels[1].text = '0' self.status_label.text = '' try: score, opponent_score = hog.play(self.strategy, self.strategy) except HogGUIException: pass else: self.s_labels[0].text = score self.s_labels[1].text = opponent_score winner = 0 if score > opponent_score else 1 self.status_label.text = 'Game over! {} wins!'.format(name(winner))
def play(self): """Simulates a game of Hog by calling hog.play with the GUI strategies. If the player destroys the window prematurely (i.e. in the middle of a game), a HogGUIException is raised to exit out of play's loop. Otherwise, the widget will be destroyed, but the strategy will continue waiting. """ self.turn = 1 - self.turn self.switch(0) self.s_labels[0].text = '0' self.s_labels[1].text = '0' self.status_label.text = '' try: score, opponent_score = hog.play(self.strategy, self.strategy) except HogGUIException: pass else: self.s_labels[0].text = score self.s_labels[1].text = opponent_score winner = 0 if score > opponent_score else 1 self.status_label.text = 'Game over! {} wins!'.format(name(winner))
def play(self): """Simulates a game of Hog by calling hog.play with the GUI strategies. If the player destroys the window prematurely (i.e. in the middle of a game), a HogGUIException is raised to exit out of play's loop. Otherwise, the widget will be destroyed, but the strategy will continue waiting. """ self.turn = 1 - self.turn self.switch(0) self.s_labels[0].text = '0' self.s_labels[1].text = '0' self.status_label.text = '' try: score, opponent_score = hog.play(self.strategy, self.strategy) except HogGUIException: pass else: self.s_labels[0].text = score self.s_labels[1].text = opponent_score self.switch() self.status_label.text = 'Game over! {} wins!'.format( name(self.who))
from hog import play, always_roll, both, announce_lead_changes, say_scores from dice import make_test_dice dice = make_test_dice(1, 2, 3, 3) always = always_roll strat0 = strat1 = always(3) s0, s1 = play(strat0, strat1, dice=dice, goal=8, say=both(say_scores, announce_lead_changes()))