def test_all_fold(self): canWin = [False, False] # no one folded river = ["ST", "SJ", "SQ", "SK", "SA"] hands = [None, None] hands[0] = ["H2", "D4"] hands[1] = ["D2", "C4"] result = score(canWin, river, hands) self.assertEqual(result, [0, 1]) # assert fold doesn't count
def test_four_of_a_kind(self): canWin = [True, True] # no one folded river = ["HK", "DK", "SA", "S5", "D2"] hands = [None, None] hands[0] = ["CK", "SK"] # four of a kind hands[1] = ["DA", "CA"] # full house result = score(canWin, river, hands) self.assertEqual(result, [0])
def test_high_tie(self): canWin = [True, True] # no one folded river = ["ST", "SJ", "SQ", "SK", "SA"] hands = [None, None] hands[0] = ["H2", "D4"] hands[1] = ["D2", "C4"] result = score(canWin, river, hands) self.assertEqual(result, [0, 1]) # assert both our tied
def test_full_house(self): canWin = [True, True] # no one folded river = ["C3", "D3", "D7", "DA", "DJ"] hands = [None, None] hands[0] = ["S3", "SJ"] # full house should beat hands[1] = ["D2", "D5"] # flush should lose result = score(canWin, river, hands) self.assertEqual(result, [0])
def test_high_card(self): canWin = [True, True] # no one folded river = ["D2", "H5", "H3", "S7", "C8"] hands = [None, None] hands[0] = ["HA", "CJ"] # Ace should win out hands[1] = ["DK", "DJ"] result = score(canWin, river, hands) self.assertEqual(result, [0]) # assert fold doesn't count
def test_royal_flush(self): canWin = [True, True] # no one folded river = ["ST", "SJ", "SQ", "SK", "SA"] hands = [None, None] hands[0] = ["H2", "D3"] hands[1] = ["D2", "C5"] # high value of 5 result = score(canWin, river, hands) self.assertEqual(result, [1])
def verb_score(self, player): # not sure how this one will work # make sure this is only return at the end # last player or everyone has gone in the 3rd round so it's the 4th # this does allow the first client to get their score # when they first join last_player_left = len(self.players) == 1 and self.intial_players > 1 # make sure it # isn't the only player to have joined if last_player_left or self.river_rounds == 3: fold = list(self.bets) for n, i in enumerate(fold): fold[n] = False # false means folded; god help me for i in self.players: fold[i - 1] = True # these are the guys that didn't fold # (bidArr, canWin, numPlayers, river, hands): s = score(fold, self.river, self.hands) return s else: raise GameError("Not end of game. Scores not available")
def test_normal_game(self): p = Poker() pn, hand, amount = p.add_player() self.assertEqual(pn, 1) self.assertEqual(len(hand), 2) pn, hand, amount = p.add_player() self.assertEqual(pn, 2) self.assertEqual(len(hand), 2) pn, hand, amount = p.add_player() self.assertEqual(pn, 3) self.assertEqual(len(hand), 2) ## now start the game # round 1 self.assertEqual(len(p.verb("river", 1)), 0) self.assertEqual(p.verb("bet", 1, amount=500), 4500) self.assertEqual(p.verb("end_turn", 1), None) self.assertEqual(p.verb("bet", 2, amount=1000), 4000) self.assertEqual(p.verb("end_turn", 2), None) self.assertEqual(p.verb("bet", 3, amount=700), 4300) self.assertEqual(p.verb("end_turn", 3), None) # round 2 self.assertEqual(len(p.verb("river", 1)), 3) # everyone bets self.assertEqual(p.verb("bet", 1, amount=500), 4000) self.assertEqual(p.verb("end_turn", 1), None) self.assertEqual(p.verb("bet", 2, amount=500), 3500) self.assertEqual(p.verb("end_turn", 2), None) self.assertEqual(p.verb("bet", 3, amount=500), 3800) self.assertEqual(p.verb("end_turn", 3), None) # round 3 self.assertEqual(len(p.verb("river", 1)), 4) # everyone bets self.assertEqual(p.verb("bet", 1, amount=500), 3500) self.assertEqual(p.verb("end_turn", 1), None) self.assertEqual(p.verb("bet", 2, amount=600), 2900) self.assertEqual(p.verb("end_turn", 2), None) self.assertEqual(p.verb("bet", 3, amount=400), 3400) self.assertEqual(p.verb("end_turn", 3), None) # round 4 self.assertEqual(len(p.verb("river", 1)), 5) # everyone bets self.assertEqual(p.verb("bet", 1, amount=600), 2900) self.assertEqual(p.verb("end_turn", 1), None) self.assertEqual(p.verb("bet", 2, amount=1000), 1900) self.assertEqual(p.verb("end_turn", 2), None) self.assertEqual(p.verb("bet", 3, amount=400), 3000) self.assertEqual(p.verb("end_turn", 3), None) # now check score from TexasHoldem import score winner = score([True, True, True], p.verb("river", 1), p.hands) self.assertEqual(p.verb("score", 1), winner)
def test_folds(self): p = Poker() pn, hand, amount = p.add_player() self.assertEqual(pn, 1) self.assertEqual(len(hand), 2) pn, hand, amount = p.add_player() self.assertEqual(pn, 2) self.assertEqual(len(hand), 2) pn, hand, amount = p.add_player() self.assertEqual(pn, 3) self.assertEqual(len(hand), 2) ## now start the game # round 1 self.assertEqual(len(p.verb("river", 1)), 0) self.assertEqual(p.verb("bet", 1, amount=500), 4500) self.assertEqual(p.verb("end_turn", 1), None) self.assertEqual(p.verb("bet", 2, amount=1000), 4000) self.assertEqual(p.verb("end_turn", 2), None) self.assertEqual(p.verb("bet", 3, amount=700), 4300) self.assertEqual(p.verb("end_turn", 3), None) # round 2 self.assertEqual(len(p.verb("river", 1)), 3) # everyone bets self.assertEqual(p.verb("bet", 1, amount=500), 4000) self.assertEqual(p.verb("end_turn", 1), None) self.assertEqual(p.verb("bet", 2, amount=500), 3500) self.assertEqual(p.verb("end_turn", 2), None) self.assertEqual(p.verb("bet", 3, amount=500), 3800) self.assertEqual(p.verb("end_turn", 3), None) # round 3 self.assertEqual(len(p.verb("river", 1)), 4) # everyone bets self.assertEqual(p.verb("bet", 1, amount=500), 3500) self.assertEqual(p.verb("end_turn", 1), None) self.assertEqual(p.verb("fold", 2), None) self.assertEqual(p.verb("fold", 3), None) # round 4 self.assertEqual(len(p.verb("river", 1)), 5) # everyone bets self.assertEqual(p.verb("bet", 1, amount=600), 2900) self.assertEqual(p.verb("end_turn", 1), None) # after you fold you can't bet self.assertRaises(GameError, p.verb, "bet", 2, amount=400) self.assertRaises(GameError, p.verb, "end_turn", 2) self.assertRaises(GameError, p.verb, "bet", 3, amount=400) self.assertRaises(GameError, p.verb, "end_turn", 3) # now check score from TexasHoldem import score winner = score([True, False, False], p.verb("river", 1), p.hands) self.assertEqual(p.verb("score", 1), winner)
def test_errors(self): p = Poker() pn, hand, amount = p.add_player() self.assertEqual(pn, 1) self.assertEqual(len(hand), 2) pn, hand, amount = p.add_player() self.assertEqual(pn, 2) self.assertEqual(len(hand), 2) pn, hand, amount = p.add_player() self.assertEqual(pn, 3) self.assertEqual(len(hand), 2) ## now start the game # round 1 ## test out of order ## test that you must bet for 1 self.assertRaises(GameError, p.verb, "end_turn", 1) # 2 goes before 1 did self.assertRaises(GameError, p.verb, "bet", 2, amount=1000) self.assertRaises(GameError, p.verb, "end_turn", 2) ## test that you must bet for 1 self.assertRaises(GameError, p.verb, "end_turn", 1) ## test too big of a bet for 1 self.assertRaises(GameError, p.verb, "bet", 1, amount=10000) ## test too small of a bet self.assertRaises(GameError, p.verb, "bet", 1, amount=-900) ## test that you must bet for 1 self.assertRaises(GameError, p.verb, "end_turn", 1) ## or fold self.assertEquals(p.verb("fold", 1), None) ## normal code make sure it works self.assertEqual(p.verb("bet", 2, amount=1000), 4000) self.assertEqual(p.verb("end_turn", 2), None) self.assertEqual(p.verb("bet", 3, amount=700), 4300) self.assertEqual(p.verb("end_turn", 3), None) # round 2 self.assertEqual(len(p.verb("river", 1)), 3) # everyone bets self.assertEqual(p.verb("bet", 2, amount=500), 3500) self.assertEqual(p.verb("end_turn", 2), None) self.assertEqual(p.verb("bet", 3, amount=500), 3800) self.assertEqual(p.verb("end_turn", 3), None) # round 3 self.assertEqual(len(p.verb("river", 1)), 4) # everyone bets self.assertEqual(p.verb("bet", 2, amount=600), 2900) self.assertEqual(p.verb("end_turn", 2), None) self.assertEqual(p.verb("bet", 3, amount=400), 3400) self.assertEqual(p.verb("end_turn", 3), None) # round 4 self.assertEqual(len(p.verb("river", 1)), 5) # everyone bets self.assertEqual(p.verb("bet", 2, amount=1000), 1900) self.assertEqual(p.verb("end_turn", 2), None) self.assertEqual(p.verb("bet", 3, amount=400), 3000) self.assertEqual(p.verb("end_turn", 3), None) # now check score # make sure though that 1 can get the river and score # after folding (so they can move to the next game as well) from TexasHoldem import score winner = score([False, True, True], p.verb("river", 1), p.hands) self.assertEqual(p.verb("score", 1), winner)