def test_get_winning_player_returns_both_players_with_true_tie(self): players = [Player(), Player()] game = Game(players) #community cards game.community.append(Card(suit=Suit.CLUB, number=2)) game.community.append(Card(suit=Suit.DIAMOND, number=11)) game.community.append(Card(suit=Suit.SPADE, number=5)) game.community.append(Card(suit=Suit.HEART, number=6)) game.community.append(Card(suit=Suit.DIAMOND, number=7)) #player1 cards player1 = game.players[0] player1.hand.append(Card(suit=Suit.CLUB, number=8)) player1.hand.append(Card(suit=Suit.CLUB, number=9)) #player2 cards player2 = game.players[1] player2.hand.append(Card(suit=Suit.DIAMOND, number=8)) player2.hand.append(Card(suit=Suit.DIAMOND, number=9)) game.set_player_hands() winners = game.get_winning_player() self.assertTrue(player1 in winners) self.assertTrue(player2 in winners)
def test_returns_winners_for_tied_pair(self): players = [Player(), Player()] game = Game(players) game.community.append(Card(suit=Suit.CLUB, number = 12)) game.community.append(Card(suit=Suit.DIAMOND, number = 12)) game.community.append(Card(suit=Suit.SPADE, number = 11)) game.community.append(Card(suit=Suit.HEART, number = 11)) game.community.append(Card(suit=Suit.DIAMOND, number = 11)) player1 = game.players[0] player1.hand.append(Card(suit=Suit.DIAMOND, number = 14)) player1.hand.append(Card(suit=Suit.DIAMOND, number = 3)) player2 = game.players[1] player2.hand.append(Card(suit=Suit.CLUB, number = 14)) player2.hand.append(Card(suit=Suit.DIAMOND, number = 5)) players = [player1, player2] game.set_player_hands() winners = game.break_tie(players) self.assertTrue(player1 in winners) self.assertTrue(player2 in winners) self.assertEqual(player1.best_hand['score'], Hand.FULL_HOUSE) self.assertEqual(player2.best_hand['score'], Hand.FULL_HOUSE)
def test_get_winning_player_returns_player1_with_tie(self): players = [Player(), Player()] game = Game(players) #community cards game.community.append(Card(suit=Suit.CLUB, number=2)) game.community.append(Card(suit=Suit.DIAMOND, number=11)) game.community.append(Card(suit=Suit.SPADE, number=5)) game.community.append(Card(suit=Suit.HEART, number=6)) game.community.append(Card(suit=Suit.DIAMOND, number=7)) #player1 cards player1 = game.players[0] player1.hand.append(Card(suit=Suit.CLUB, number=8)) player1.hand.append(Card(suit=Suit.CLUB, number=9)) #player2 cards player2 = game.players[1] player2.hand.append(Card(suit=Suit.DIAMOND, number=4)) player2.hand.append(Card(suit=Suit.SPADE, number=3)) game.set_player_hands() winner = game.get_winning_player() self.assertEqual(winner[0], player1) self.assertEqual(winner[0].best_hand['score'], Hand.STRAIGHT) self.assertEqual(player2.best_hand['score'], Hand.STRAIGHT) self.assertEqual(player2.best_hand['hand'][0].number, 7) self.assertEqual(player1.best_hand['hand'][0].number, 9)
def test_returns_tie_for_straights(self): players = [Player(), Player()] game = Game(players) game.community.append(Card(suit=Suit.CLUB, number = 9)) game.community.append(Card(suit=Suit.CLUB, number = 10)) game.community.append(Card(suit=Suit.CLUB, number = 11)) game.community.append(Card(suit=Suit.CLUB, number = 12)) game.community.append(Card(suit=Suit.DIAMOND, number = 13)) player1 = game.players[0] player1.hand.append(Card(suit=Suit.DIAMOND, number = 2)) player1.hand.append(Card(suit=Suit.DIAMOND, number = 3)) player2 = game.players[1] player2.hand.append(Card(suit=Suit.DIAMOND, number = 4)) player2.hand.append(Card(suit=Suit.DIAMOND, number = 5)) players = [player1, player2] game.set_player_hands() winners = game.break_tie(players) self.assertTrue(player1 in winners) self.assertTrue(player2 in winners) self.assertEqual(player1.best_hand['score'], Hand.STRAIGHT) self.assertEqual(player2.best_hand['score'], Hand.STRAIGHT)
def test_flush_breaker_returns_single_player(self): players = [Player(), Player(), Player()] game = Game(players) game.community.append(Card(suit=Suit.CLUB, number = 8)) game.community.append(Card(suit=Suit.CLUB, number = 14)) game.community.append(Card(suit=Suit.CLUB, number = 9)) game.community.append(Card(suit=Suit.CLUB, number = 10)) game.community.append(Card(suit=Suit.CLUB, number = 13)) player1 = game.players[0] player1.hand.append(Card(suit=Suit.CLUB, number = 2)) player1.hand.append(Card(suit=Suit.CLUB, number = 14)) player2 = game.players[1] player2.hand.append(Card(suit=Suit.CLUB, number = 4)) player2.hand.append(Card(suit=Suit.CLUB, number = 5)) player3 = game.players[2] player3.hand.append(Card(suit=Suit.CLUB, number = 6)) player3.hand.append(Card(suit=Suit.DIAMOND, number = 7)) players = [player1, player2, player3] game.set_player_hands() winners = game.break_tie(players) self.assertTrue(player1 in winners) self.assertFalse(player2 in winners) self.assertFalse(player3 in winners) self.assertEqual(player1.best_hand['score'], Hand.FLUSH) self.assertEqual(player2.best_hand['score'], Hand.FLUSH) self.assertEqual(player3.best_hand['score'], Hand.FLUSH)
def test_game_creates_shuffled_deck(self): players = [Player(), Player(), Player()] game = Game(players) self.assertTrue(game.deck) self.assertEqual(len(game.deck.cards), 52) self.assertTrue(game.deck.cards[0].number != 2 or game.deck.cards[0].number != 3)
def test_passed_flop_cards_removed_from_deck(self): flop_cards = ['D4', 'C14', 'D13'] players = [Player(), Player()] game = Game(players, flop_cards=flop_cards) self.assertEqual(len(game.deck.cards), 52 - 3) self.assertEqual(len(game.flop_cards), 3)
def test_passed_river_card_removed_from_deck(self): river_card = 'D14' players = [Player(), Player()] game = Game(players, river_card=river_card) self.assertEqual(len(game.deck.cards), 52 - 1) self.assertEqual(game.flop_cards, []) self.assertEqual(repr(game.river_card), 'D14')
def test_set_player_best_hands(self): players = [Player(), Player()] game = Game(players) game.deal() game.deal() game.deal() game.deal() game.set_player_hands() player = game.players[0]
def test_can_create_player(self): players = [Player(), Player()] game = Game(players) game.deal() game.deal() game.deal() game.deal() player = game.players[0] self.assertEqual(len(player.hand), 2)
def test_preflop_deal_gives_each_player_2_cards(self): players = [Player(), Player(), Player()] game = Game(players) game.deal() for player in game.players: self.assertEqual(len(player.hand), 2) self.assertEqual(len(game.deck.cards), 52 - len(game.players) * 2) self.assertEqual(game.stage, Stage.PREFLOP)
def test_flop_deal_puts_3_cards_in_community(self): players = [Player(), Player(), Player()] game = Game(players) game.deal() game.deal() for player in game.players: self.assertEqual(len(player.hand), 2) # Deck length is less the initial deal minus 3 community - 1 burn self.assertEqual(len(game.deck.cards), 52 - len(game.players) * 2 - 3 - 1) self.assertEqual(game.stage, Stage.FLOP)
def test_passing_blank_list_returns_full_community(self): flop_cards = [] players = [Player(), Player()] game = Game(players, flop_cards=flop_cards) self.assertEqual(len(game.deck.cards), 52) self.assertEqual(len(game.flop_cards), 0) game.deal() game.deal() game.deal() game.deal() self.assertEqual(len(game.community), 5)
def test_passed_flop_cards_removed_from_deck_one_card(self): flop_cards = ['D4'] players = [Player(), Player()] game = Game(players, flop_cards=flop_cards) self.assertEqual(len(game.deck.cards), 52 - 1) self.assertEqual(len(game.flop_cards), 1) game.deal() game.deal() game.deal() game.deal() self.assertEqual(len(game.community), 5) self.assertTrue('D4' == repr(game.community[0]))
def test_passed_turn_card_is_in_community(self): turn_card = 'D4' players = [Player(), Player()] game = Game(players, turn_card=turn_card) game.deal() game.deal() self.assertEqual(len(game.community), 3) game.deal() self.assertEqual(len(game.community), 4) game.deal() self.assertEqual(len(game.community), 5) self.assertEqual(turn_card, repr(game.turn_card)) self.assertEqual(repr(game.community[3]), 'D4')
def create(request): raw_id_number = request.GET.get("id","") try: parsed_id_number = int(raw_id_number) player = Player(id_number=parsed_id_number) player.build() response_message = 'done' print "Res: ",response_message response = HttpResponse(response_message) response["Access-Control-Allow-Origin"] = "*" response["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS" response["Access-Control-Max-Age"] = "1000" response["Access-Control-Allow-Headers"] = "*" return response except Exception as e: return HttpResponse("Error: "+str(e))
def test_passed_flop_cards_are_in_community(self): flop_cards = ['D4', 'C14', 'D13'] players = [Player(), Player()] game = Game(players, flop_cards=flop_cards) game.deal() game.deal() self.assertEqual(len(game.community), 3) game.deal() self.assertEqual(len(game.community), 4) game.deal() self.assertEqual(len(game.community), 5) self.assertEqual(3, len(game.flop_cards)) self.assertTrue(repr(game.community[0]) in flop_cards) self.assertTrue(repr(game.community[1]) in flop_cards) self.assertTrue(repr(game.community[2]) in flop_cards)
def test_passed_flop_cards_removed_from_deck_two_cards(self): flop_cards = ['D4', 'C14'] players = [Player(), Player()] game = Game(players, flop_cards=flop_cards) self.assertEqual(len(game.deck.cards), 52 - 2) self.assertEqual(len(game.flop_cards), 2) game.deal() game.deal() game.deal() game.deal() self.assertEqual(len(game.community), 5) self.assertTrue( 'D4' in [repr(game.community[0]), repr(game.community[1])]) self.assertTrue( 'C14' in [repr(game.community[0]), repr(game.community[1])])
def test_deal_maintains_player_start_hands(self): user_hand = ['D4', 'C14'] other_hand = [['D13', 'C13']] player1 = Player(is_user=True, starting_hand=user_hand) player2 = Player(starting_hand=other_hand[0]) players = [player1, player2] game = Game(players) game.deal() self.assertTrue( repr(player1.hand[0]) in [player1.starting_hand[0], player1.starting_hand[1]]) self.assertTrue( repr(player1.hand[1]) in [player1.starting_hand[0], player1.starting_hand[1]]) self.assertTrue( repr(player2.hand[0]) in [player2.starting_hand[0], player2.starting_hand[1]]) self.assertTrue( repr(player2.hand[1]) in [player2.starting_hand[0], player2.starting_hand[1]])