Skip to content

Instantly share code, notes, and snippets.

@brenorb
Created June 13, 2019 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brenorb/a82b8e760080de872484460d5885fe34 to your computer and use it in GitHub Desktop.
Save brenorb/a82b8e760080de872484460d5885fe34 to your computer and use it in GitHub Desktop.
Simple way to keep track of results printed but not returned
# from https://www.kaggle.com/kmader/july-24-micro-challenge
from contextlib import redirect_stdout
from io import StringIO
def simulate_game(verbose=False):
out_buffer = StringIO()
with redirect_stdout(out_buffer):
blackjack.simulate_one_game()
out_str = out_buffer.getvalue()
if verbose:
print(out_str)
return any(['Player wins' in x for x in out_str.split('\n')]) # if any lines say player wins then we won
simulate_game(True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment