def test_two_straights(self): straightTo8 = '4S 6H 7S 8D 5H'.split() straightTo9 = '5S 7H 8S 9D 6H'.split() self.assertEqual([straightTo9], poker([straightTo8, straightTo9])) straightTo1 = 'AS QH KS TD JH'.split() straightTo5 = '4S AH 3S 2D 5H'.split() self.assertEqual([straightTo1], poker([straightTo1, straightTo5]))
def test_poker(self): t = TestPokerMethods self.assertEqual(poker([t.SF, t.FK, t.FH, t.F, t.S]), [t.SF]) # self.assertEqual(poker([t.S]), [t.S]) # One Player self.assertEqual(poker([t.FK, t.FK, t.FK]), [t.FK, t.FK, t.FK]) # Ties
def testPoker(self): self.assertEqual(poker([straight_flush2, quadra1]), straight_flush2) self.assertEqual(poker([full_house1, quadra1]), quadra1) self.assertEqual(poker([straight_flush2, full_house1]), straight_flush2) # self.assertEqual(poker([straight_flush2, straight_flush2]), None) self.assertEqual(poker[(flush1, straigh1)], flush1) self.assertEqual(poker[(straigh1, um_par1)], straigh1) self.assertEqual(poker[(trinca1, doi_pares1)], trinca1) self.assertEqual(poker[(um_par1, doi_pares1)], doi_pares1) self.assertEqual(poker[(doi_pares1, flush1)], flush1) self.assertEqual(poker[(carta_alta1, um_par1)], um_par1) self.assertEqual(poker[(um_par1, carta_alta1)], um_par1) self.assertEqual(poker[(straight_flush2, trinca1)], straight_flush2) self.assertEqual(poker[(straight_flush2, carta_alta1)], straight_flush2)
def pay(self): """ define o vencedor e paga o dinheiro para ele """ #limpa a variavel best_hand for player in self.players: player.best_hand='' #add as cartas no flop do jogador (7 cartas) map(lambda player: player.cards.extend(self.flop), itertools.ifilter(lambda player: player.active, self.players)) #acha a melhor mão de cada jogador) for player in itertools.ifilter(lambda player: player.active, self.players): player.best_hand = poker([o for o in itertools.combinations(player.cards,5)]) #acha o vencedor _players = filter(lambda player: player.active, self.players) cards = [] map(lambda player: cards.extend(player.best_hand), self.players) win = poker(cards) #acha o vencedor e paga ele _winners = filter(lambda player: player.best_hand[0] in win, self.players) #confere for o in _winners: o.stack += self.pot/len(_winners) self.pot = 0
def test_for_a_deck_with_100_hands(self): """Test poker() with 100 hands""" self.assertEqual(poker([self.fk, self.fh] * 50), [self.fk] * 50)
def test_carta_mais_alta(self): self.assertEqual(1, poker('4C 6P 7P 9P KP', '6C 7O 8O 9O JO')) self.assertEqual(2, poker('6C 7O 8O 9O JO', '4C 6P 7P 9P KP')) self.assertEqual(1, poker('5D 8P 9E JE AP', '2P 5P 7O 8E QC'))
def test_for_straight_flush(self): """Test poker() for straight flush""" self.assertEqual(poker([self.sf, self.fk, self.fh]), [self.sf])
def test_for_full_house(self): """Test poker() for full house""" self.assertEqual(poker([self.fh, self.fh]), [self.fh, self.fh])
def test_nothing_vs_one_pair(self): nothing = '4S 5H 6S 8D JH'.split() pairOf4 = '2S 4H 6S 4D JH'.split() self.assertEqual([pairOf4], poker([nothing, pairOf4]))
def test_one_pair_vs_double_pair(self): pairOf8 = '2S 8H 6S 8D JH'.split() doublePair = '4S 5H 4S 8D 5H'.split() self.assertEqual([doublePair], poker([pairOf8, doublePair]))
def test_three_vs_straight(self): threeOf4 = '4S 5H 4S 8D 4H'.split() straight = '3S 4H 2S 6D 5H'.split() self.assertEqual([straight], poker([threeOf4, straight]))
def test_royal_straigth_flush_ganha_de_todos(self): self.assertEqual(2, poker('9C DC JC QC KC', 'DC JC QC KC AC')) self.assertEqual(2, poker('DC JP QC KC AC', 'DC JC QC KC AC')) self.assertEqual(1, poker('DC JC QC KC AC', 'DC JP QC KC AC'))
def test_double_pair_vs_three(self): doublePair2and8 = '2S 8H 2S 8D JH'.split() threeOf4 = '4S 5H 4S 8D 4H'.split() self.assertEqual([threeOf4], poker([doublePair2and8, threeOf4]))
def test_two_three(self): threeOf2 = '2S 2H 2S 8D JH'.split() threeOf1 = '4S AH AS 8D AH'.split() self.assertEqual([threeOf1], poker([threeOf2, threeOf1]))
def test_for_an_empty_deck(self): '''Test poker() with 0 hands''' self.assertEqual(poker([]), None)
def test_for_a_deck_with_100_hands(self): '''Test poker() with 100 hands''' self.assertEqual(poker([self.fk, self.fh] * 50), [self.fk] * 50)
def test_for_a_one_hand_deck(self): '''Test poker() with 1 hand''' self.assertEqual(poker([self.fh]), [self.fh])
def test_maior_par(self): self.assertEqual(2, poker('5C 5P 2C 3C 4C', '6C 6P 7C 8C 9C')) self.assertEqual(1, poker('7C 7P 2C 3C 4C', '6C 6P 7C 8C 9C')) self.assertEqual(2, poker('5C 5P 6E 7E KO', '2P 3E 8E 8O DO'))
def test_for_straight_flush(self): '''Test poker() for straight flush''' self.assertEqual(poker([self.sf, self.fk, self.fh]), [self.sf])
def test_Flush_ganha_de_Trinca(self): self.assertEqual(2, poker('2O 9P AE AC AP', '3O 6O 7O DO QO'))
def test_straight_vs_flush(self): straightTo8 = '4S 6H 7S 8D 5H'.split() flushTo7 = '2S 4S 5S 6S 7S'.split() self.assertEqual([flushTo7], poker([straightTo8, flushTo7]))
def test_for_full_house(self): '''Test poker() for full house''' self.assertEqual(poker([self.fh, self.fh]), [self.fh, self.fh])
def test_two_flushes(self): flushTo8 = '3H 6H 7H 8H 5H'.split() flushTo7 = '2S 4S 5S 6S 7S'.split() self.assertEqual([flushTo8], poker([flushTo8, flushTo7]))
def test_two_pair(self): pairOf2 = '4S 2H 6S 2D JH'.split() pairOf4 = '2S 4H 6S 4D JH'.split() self.assertEqual([pairOf4], poker([pairOf2, pairOf4]))
def test_flush_vs_full(self): flushTo8 = '3H 6H 7H 8H 5H'.split() full = '4S 5H 4S 5D 4H'.split() self.assertEqual([full], poker([full, flushTo8]))
def test_two_double_pair(self): doublePair2and8 = '2S 8H 2S 8D JH'.split() doublePair4and5 = '4S 5H 4S 8D 5H'.split() self.assertEqual([doublePair2and8], poker([doublePair2and8, doublePair4and5]))
def test_two_fulls(self): fullOf4by9 = '4H 4S 4D 9S 9D'.split() fullOf5by8 = '5H 5S 5D 8S 8D'.split() self.assertEqual([fullOf5by8], poker([fullOf4by9, fullOf5by8]))
def test_for_four_of_kind(self): """Test poker() for four of kind""" self.assertEqual(poker([self.fk, self.fh]), [self.fk])
def test_full_vs_square(self): full = '4S 5H 4S 5D 4H'.split() squareOf3 = '3S 3H 2S 3D 3H'.split() self.assertEqual([squareOf3], poker([full, squareOf3]))
def test_for_a_one_hand_deck(self): """Test poker() with 1 hand""" self.assertEqual(poker([self.fh]), [self.fh])
def test_two_square(self): squareOf2 = '2S 2H 2S 8D 2H'.split() squareOf5 = '4S 5H 5S 5D 5H'.split() self.assertEqual([squareOf5], poker([squareOf2, squareOf5]))
def test_for_an_empty_deck(self): """Test poker() with 0 hands""" self.assertEqual(poker([]), None)
def test_square_vs_straight_flush(self): squareOf5 = '4S 5H 5S 5D 5H'.split() straightFlushTo9 = '5S 7S 8S 9S 6S'.split() self.assertEqual([straightFlushTo9], poker([squareOf5, straightFlushTo9]))
def test_um_par(self): self.assertEqual(1, poker('5C 5P 2C 3C 4C', '6C 7O 8C 9C AC')) self.assertEqual(2, poker('6C 7O 8C 9C AC', '5C 5P 2C 3C 4C'))
import random from poker import * from poker_pro import * def deal(numhands, n=5, deck=[r+s for r in '23456789TJQKA' for s in 'SHDC']): random.shuffle(deck) return [deck[n*i:n*(i+1)] for i in range(numhands)] hands = deal(2) print(hands) print(poker(hands)) print(poker_pro(hands)) hands = deal(2, 7) print(hands)
def test_pares_iguais(self): self.assertEqual(1, poker('4O 6E 9C QC QP', '3O 6O 7C QO QE'))
def test_three_hand_with_tie(self): spadeStraightTo9 = "9S 8S 7S 6S 5S".split() diamondStraightTo9 = "9D 8D 7D 6D 5D".split() threeOf4 = "4D 4S 4H QS KS".split() self.assertEqual([spadeStraightTo9, diamondStraightTo9], poker([spadeStraightTo9, diamondStraightTo9, threeOf4]))
def test_FullHouse_com_Trinca_de_4_ganha_FullHouse_com_Trinca_de_3(self): self.assertEqual(1, poker('2C 2O 4P 4O 4E', '3P 3O 3E 9E 9O'))
def test_one_hand(self): hand = '4S 5S 7H 8D JC'.split() self.assertEqual([hand], poker([hand]))
def test_two_straight_flushes(self): straightFlushTo8 = '4H 6H 7H 8H 5H'.split() straightFlushTo9 = '5S 7S 8S 9S 6S'.split() self.assertEqual([straightFlushTo9], poker([straightFlushTo8, straightFlushTo9]))
def test_for_four_of_kind(self): '''Test poker() for four of kind''' self.assertEqual(poker([self.fk, self.fh]), [self.fk])