def test_simulate_game_empty_deck(self): mock_deck = Deck() mock_deck.deal = MagicMock(return_value=([], [])) game = Egrt(0.5, deck=mock_deck) winner, turns = game.simulate_game() self.assertEqual(winner, 'T') self.assertEqual(turns, 0)
def main(): parser = ArgumentParser(description='play a game of Egyptian Rat Tail') parser.add_argument('--a_slap_probability', type=float, required=True) parser.add_argument('--debug_print', action='store_true') args = parser.parse_args() game = Egrt(args.a_slap_probability) result_tuple = game.simulate_game(args.debug_print) if args.debug_print: print(result_tuple) return result_tuple
def test_simulate_queen_wins(self): mock_deck = Deck() mock_deck.deal = MagicMock(return_value=([ Card(Rank.SIX, Suit.DIAMOND), Card(Rank.SEVEN, Suit.CLUB), Card(Rank.EIGHT, Suit.SPADE) ], [Card(Rank.QUEEN, Suit.HEART), Card(Rank.TWO, Suit.SPADE)])) game = Egrt(0.5, deck=mock_deck) winner, turns = game.simulate_game() self.assertEqual(winner, 'B') self.assertEqual(turns, 4)
def test_simulate_game_king_and_jack_win(self): mock_deck = Deck() mock_deck.deal = MagicMock(return_value=( [Card(Rank.KING, Suit.CLUB), Card(Rank.JACK, Suit.CLUB)], [ Card(Rank.TWO, Suit.CLUB), Card(Rank.SEVEN, Suit.DIAMOND), Card(Rank.FOUR, Suit.CLUB), Card(Rank.NINE, Suit.SPADE) ])) game = Egrt(0.5, deck=mock_deck) winner, turns = game.simulate_game() self.assertEqual(winner, 'A') self.assertEqual(turns, 6)
def main(): print('output file is {}'.format(FILE_NAME)) filew = open(FILE_NAME, 'w') filew.write('A_SLAP_PROBABILITY,A_WIN_PERCENTAGE,TURNS_MEAN,TURNS_STDEV\n') for prob in probabilities: winners = [] turns = [] for x in range(int(N)): game = Egrt(prob) victor, counter = game.simulate_game() winners.append(victor) turns.append(counter) a_win_percentage = winners.count('A') / float(N) mean_turns = round(mean(turns)) stdev_turns = round(stdev(turns)) print('A slap win probability is {}%'.format(prob)) print('A wins {}%'.format(a_win_percentage)) print(mean_turns, '+/-', stdev_turns) filew.write('{},{},{},{}\n'.format(prob, a_win_percentage, mean_turns, stdev_turns)) filew.close()