-
-
Save kenju254/922c90d9df80bc17162e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def play_pig(A, B): | |
"""Lets play a small game of pig between two players, represented by | |
their strategy. Each time through the main loop, we ask the current player | |
for one decision which must be 'hold' or 'roll', and we update the state | |
accordingly when one player's score exceeds the goal, return that player""" | |
strategies = [A, B] | |
state = (0,0,0,0) | |
while True: | |
(p, me, you, pending) = state | |
if me >= goal: | |
return strategies[p] | |
elif you >= goal: | |
return strategies[other[p]] | |
elif strategies[p](state) == 'hold': | |
state = hold(state) | |
else: | |
state = roll(state, random.randint(1,6)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment