def play_whist(record_game): players, partners = get_players_and_partners() game_state = GameState(players, partners) dealer_index = 0 while not game_state.is_game_over(): play_deal(game_state, dealer_index) dealer_index = (dealer_index + 1) % NUM_PLAYERS print 'The game is over! Final scores:' game_state.print_scores() if record_game: outfile = open(GAME_RECORD_FILE, 'a') outfile.write(game_state.get_team_scores_str()) outfile.close()
def play_oracle_whist(num_iters=1000, silent=True): # random.seed(42) oracles = ['Oracle1', 'Oracle2'] opponents = ['Opponent1', 'Opponent2'] players, partners, oracle_name = get_oracle_players_and_partners(oracles, opponents) oracle_wins = 0 opponent_wins = 0 points_for = 0 points_against = 0 for i in xrange(num_iters): game_state = GameState(players, partners) dealer_index = 0 while not game_state.is_game_over(): play_oracle_deal(game_state, dealer_index, oracle_name, silent=silent) dealer_index = (dealer_index + 1) % NUM_PLAYERS #raw_input() if not silent: print 'The game is over! Final scores:' game_state.print_scores() oracle_score = sum([game_state.scores[oracle] for oracle in oracles]) opp_score = sum([game_state.scores[opp] for opp in opponents]) if oracle_score > opp_score: print "Game %s: oracles win" % (i+1) oracle_wins += 1 else: print "Game %s: opponents win" % (i+1) opponent_wins += 1 points_for += oracle_score points_against += opp_score print "Oracle record: %s-%s" % (oracle_wins, opponent_wins) print "Points for: %s" % points_for print "Points against: %s" % points_against