Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
    def __init__(self, room):
        Thread.__init__(self)
        self.isPlaying = False
        self.channel_layer = get_channel_layer()
        self.room = room
        self.roomName = room.name
        self.groupName = "chat_%s" % str(room.id)
        self.members = json.loads(room.members)  # id
        self.wolfs = []  # id
        self.hunter = ""
        self.witch = ""
        self.prophet = ""
        self.villagers = []  # id
        self.count = len(self.members)
        self.wolfCount = 0
        self.alive = {}  # index = id
        self.db = Game(name=room.id)
        self.seperate()
        self.occupation = {}
        self.db.save()
        for each in self.members:
            userName = getUsername(each)
            if each in self.villagers:
                self.occupation[userName] = '村民'
            elif each in self.wolfs:
                self.occupation[userName] = '狼人'
            elif each == self.hunter:
                self.occupation[userName] = '猎人'
            elif each == self.witch:
                self.occupation[userName] = '女巫'
            elif each == self.prophet:
                self.occupation[userName] = '预言家'

        random.shuffle(self.members)
Ejemplo n.º 7
0
    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)
Ejemplo n.º 8
0
    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)
Ejemplo n.º 9
0
    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')
Ejemplo n.º 10
0
    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]
Ejemplo n.º 11
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)
Ejemplo n.º 12
0
    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)
Ejemplo n.º 13
0
    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)
Ejemplo n.º 14
0
    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)
Ejemplo n.º 15
0
    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]))
Ejemplo n.º 16
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')
Ejemplo n.º 17
0
    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)
Ejemplo n.º 18
0
    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])])
Ejemplo n.º 19
0
    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]])