def get_secondary_player_move(player):
        nonlocal turn_hands
        nonlocal turn_players
        self.current_player = self.players.index(player)
        cur_suit = first_hand.suit
        # print("Current suit: " + cur_suit + ", current hand size: " + len(first_hand))
        np_input = self.get_player_input(self.current_player)
        while not self.is_valid_input(
                player, np_input) or not len(first_hand) == len(np_input):
            if self.take_back:
                return reverse(turn_players[len(turn_hands) - 1])
            np_input = self.get_player_input(self.current_player)
        print(np_input)

        np_playhand_list = [
            player.get_hand()[each_index] for each_index in np_input
        ]
        np_playhand = Hand(np_playhand_list, self,
                           first=first_hand)  # Should we pass in suit here?

        np_playhand.check_is_legal_move()
        # Check if it's a legal move
        "To-do: Add points to current_turn_points" \
            "Check if this hand greater than previous biggest hand, update if so"
        self.del_indexes(player, np_input)
        return np_playhand
    def get_first_player_move(first_player):
        nonlocal turn_players
        nonlocal turn_hands
        self.current_player = self.players.index(first_player)
        fp_input = self.get_player_input(self.current_player)

        while not self.is_valid_input(first_player, fp_input):
            fp_input = self.get_player_input(self.current_player)
        print(fp_input)

        fp_playhand_list = [
            first_player.get_hand()[each_index] for each_index in fp_input
        ]
        fp_playhand = Hand(fp_playhand_list,
                           self,
                           suit=self.get_suit(fp_playhand_list[0]))

        if not fp_playhand.check_is_one_suit(fp_playhand.suit):
            return
        '''
        Change to a function of hand in context of round and player's hand eventually
        '''
        # delete cards once everything is processed
        self.del_indexes(first_player, fp_input)
        return fp_playhand
 def one_suit_helper(indices):
     if len(indices) == 0:
         return False
     playhand_list = [
         first_player.get_hand()[each_index] for each_index in indices
     ]
     playhand = Hand(playhand_list,
                     self,
                     suit=self.get_suit(playhand_list[0]))
     return playhand.check_is_one_suit(playhand.suit)
Example #4
0
    def test_init(self):
        sheng_order = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A']
        rank_ids = [0, 0, 0, 0]

        zj_id = 0
        players = [Player("Adam", sheng_order[0]), Player("Andrew", sheng_order[0]),
                   Player("Alan", sheng_order[0]), Player("Raymond", sheng_order[0])]
        players[zj_id].set_is_zhuang_jia(True)

        cur_round = Round(players)
        hand1 = Hand([Card('A', 'clubs'), Card('A', 'clubs')], cur_round)
        hand2 = Hand([Card('A', 'clubs'), Card('K', 'clubs'), Card('A', 'clubs')], cur_round)
        hand3 = Hand([Card('A', 'clubs'), Card('K', 'clubs')], cur_round)
        hand4 = Hand([Card('A', 'clubs'), Card('A', 'spades')], cur_round)
        hand5 = Hand([Card('A', 'clubs'), Card('A', 'spades'), Card('A', 'spades')], cur_round)
        hand6 = Hand([Card('8', 'clubs'), Card('8', 'clubs')], cur_round, 'clubs', hand3)

        # Testing pair retrieval
        self.assertListEqual(hand1.pairs, [Pair(cur_round, Card('A', 'clubs'))])
        self.assertListEqual(hand2.pairs, [Pair(cur_round, Card('A', 'clubs'))])
        self.assertListEqual(hand3.pairs, [])
        self.assertListEqual(hand4.pairs, [])
        self.assertListEqual(hand5.pairs, [Pair(cur_round, Card('A', 'spades'))])
        self.assertListEqual(hand6.pairs, [Pair(cur_round, Card('8', 'clubs'))])

        self.assertEqual(hand1.size_compare, 1)
        self.assertEqual(hand2.size_compare, 1)
        self.assertEqual(hand3.size_compare, 0)
        self.assertEqual(hand4.size_compare, 0)
        self.assertEqual(hand5.size_compare, 1)
        self.assertEqual(hand6.size_compare, 0)

        # Testing tractor retrieval
        hand1 = Hand([Card('A', 'spades'), Card('5', 'spades'), Card('5', 'spades'),
                      Card('4', 'spades'), Card('4', 'spades')], cur_round)
        hand2 = Hand([Card('Q', 'spades'), Card('9', 'spades'), Card('9', 'spades'),
                      Card('6', 'spades'), Card('6', 'spades')], cur_round)
        hand3 = Hand([Card('A', 'spades'), Card('A', 'spades'),
                      Card('K', 'spades'), Card('K', 'spades'),
                      Card('5', 'spades'), Card('5', 'spades'),
                      Card('4', 'spades'), Card('4', 'spades')], cur_round)
        hand4 = Hand([Card('A', 'spades'), Card('A', 'spades'),
                      Card('K', 'spades'), Card('K', 'spades'),
                      Card('Q', 'spades'), Card('J', 'spades'),
                      Card('Q', 'spades'), Card('J', 'spades')], cur_round)

        self.assertEqual(hand1.size_compare, 2, "hand1 size compare")
        self.assertEqual(hand2.size_compare, 1, "hand2 size compare")
        self.assertEqual(hand3.size_compare, 2, "hand3 size compare")
        self.assertEqual(hand4.size_compare, 4, "hand4 size compare")
        self.assertEqual(len(hand3.tractors[2]), 2, "hand3 2-tractors")
        self.assertEqual(len(hand4.tractors[2]), 2, "hand4 2-tractors")
        self.assertEqual(len(hand4.tractors[3]), 1, "hand4 3-tractors")
        # TODO: more tractor cases, test init with first_hands
        pass
def get_first_player_move(self, first_player):
    def one_suit_helper(indices):
        if len(indices) == 0:
            return False
        playhand_list = [
            first_player.get_hand()[each_index] for each_index in indices
        ]
        playhand = Hand(playhand_list,
                        self,
                        suit=self.get_suit(playhand_list[0]))
        return playhand.check_is_one_suit(playhand.suit)

    fp_input = self.get_player_input(self.current_player)
    # print(fp_input)

    while not self.is_valid_input(first_player,
                                  fp_input) or not one_suit_helper(fp_input):
        if self.take_back:
            return self.reverse()
        fp_input = self.get_player_input(self.current_player)
    print(fp_input)

    fp_playhand_list = [
        first_player.get_hand()[each_index] for each_index in fp_input
    ]
    fp_playhand = Hand(fp_playhand_list,
                       self,
                       suit=self.get_suit(fp_playhand_list[0]))
    '''
    Change to a function of hand in context of round and player's hand eventually
    '''
    # delete cards once everything is processed
    self.del_indexes(first_player, fp_input)
    return fp_playhand
Example #6
0
    def test_pair_lead(self):
        sheng_order = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A']
        rank_ids = [0, 0, 0, 0]

        zj_id = 0
        players = [Player("Adam", sheng_order[0]), Player("Andrew", sheng_order[0]),
                   Player("Alan", sheng_order[0]), Player("Raymond", sheng_order[0])]
        players[zj_id].set_is_zhuang_jia(True)

        cur_round = Round(players)
        hand1 = Hand([Card('A', 'clubs'), Card('A', 'clubs')], cur_round)
        hand2 = Hand([Card('8', 'clubs'), Card('8', 'clubs')], cur_round, 'clubs', hand1)
        hand3 = Hand([Card('J', 'clubs'), Card('3', 'clubs')], cur_round, 'clubs', hand1)
        hand4 = Hand([Card('5', 'clubs'), Card('10', 'spades')], cur_round, 'clubs', hand1)
        self.assertTrue(hand1 > hand2)
        self.assertTrue(hand1 > hand3)
        self.assertTrue(hand1 > hand4)
    def get_first_player_move(first_player):
        nonlocal biggest_player
        nonlocal biggest_hand
        nonlocal first_hand
        self.current_player = self.players.index(first_player)
        biggest_player = first_player
        fp_input = self.get_player_input(self.current_player)

        # Check if input is a list of valid indexes
        if not self.is_valid_input(first_player, fp_input):
            return get_first_player_move(first_player)

        fp_hand = Hand(first_player.get_hand(), self)
        fp_playhand_list = [
            fp_hand.hand[each_index] for each_index in fp_input
        ]
        fp_playhand = Hand(fp_playhand_list,
                           self,
                           suit=self.get_suit(fp_playhand_list[0]))

        if not fp_playhand.check_is_one_suit(fp_playhand.suit):
            return get_first_player_move(first_player)

        # FOR NOW, JUST CHECK IF PAIR OR SINGLE
        '''
        Change to a function of hand in context of round and player's hand eventually
        '''
        if not self.is_valid_fpi(fp_playhand):
            return get_first_player_move(first_player)

        # delete cards once everything is processed
        fp_hand.del_indexes(fp_input)
        biggest_hand = fp_playhand
        first_hand = fp_playhand
Example #8
0
    def test_tractor_lead(self):
        # TODO: with all tractors, with trumping
        sheng_order = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A']
        rank_ids = [0, 0, 0, 0]

        zj_id = 0
        players = [Player("Adam", sheng_order[0]), Player("Andrew", sheng_order[0]),
                   Player("Alan", sheng_order[0]), Player("Raymond", sheng_order[0])]
        players[zj_id].set_is_zhuang_jia(True)

        cur_round = Round(players)
        hand1 = Hand([Card('A', 'spades'), Card('5', 'spades'), Card('5', 'spades'),
                      Card('4', 'spades'), Card('4', 'spades')], cur_round)
        hand2 = Hand([Card('A', 'spades'), Card('Q', 'spades'), Card('J', 'spades'),
                      Card('8', 'spades'), Card('7', 'spades')], cur_round, 'spades', hand1)
        hand3 = Hand([Card('K', 'spades'), Card('J', 'spades'), Card('10', 'spades'),
                      Card('3', 'spades'), Card('6', 'clubs')], cur_round, 'spades', hand1)
        hand4 = Hand([Card('Q', 'spades'), Card('9', 'spades'), Card('9', 'spades'),
                      Card('6', 'spades'), Card('6', 'spades')], cur_round, 'spades', hand1)
        self.assertEqual(hand1.size_compare, 2, "hand1 size compare")
        self.assertEqual(hand4.size_compare, 2, "hand4 size compare")
        self.assertTrue(hand1 > hand2)
        self.assertTrue(hand1 > hand3)
        self.assertTrue(hand1 > hand4)
    def get_secondary_player_move(player):
        nonlocal biggest_hand
        nonlocal biggest_player
        self.current_player = self.players.index(player)
        cur_suit = first_hand.suit
        print("Current suit: " + cur_suit + ", current hand size: " +
              len(first_hand))
        np_input = self.get_player_input(self.current_player)
        if not self.is_valid_input(
                player, np_input) or not len(first_hand) == len(np_input):
            return get_secondary_player_move(player)

        np_hand = Hand(player.get_hand(), self)
        np_playhand_list = [
            np_hand.hand[each_index] for each_index in np_input
        ]
        np_playhand = SecondaryHand(first_hand, np_playhand_list, self,
                                    cur_suit)  #Should we pass in suit here?

        np_playhand.check_is_legal_move()
        # Check if it's a legal move
        "To-do: Add points to current_turn_points" \
        " Check if this hand greater than previous biggest hand, update if so"
Example #10
0
    def test_check_is_one_suit(self):
        # TODO: all trumps, all non-trump suit, mixed suits
        sheng_order = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A']
        rank_ids = [0, 0, 0, 0]

        zj_id = 0
        players = [Player("Adam", sheng_order[0]), Player("Andrew", sheng_order[0]),
                   Player("Alan", sheng_order[0]), Player("Raymond", sheng_order[0])]
        players[zj_id].set_is_zhuang_jia(True)

        cur_round = Round(players)
        hand1 = Hand([Card('A', 'clubs'), Card('A', 'clubs')], cur_round)
        hand2 = Hand([Card('8', 'clubs'), Card('8', 'clubs')], cur_round, 'clubs', hand1)
        print(hand2.first_hand.suit)
        hand3 = Hand([Card('J', 'clubs'), Card('3', 'clubs')], cur_round, 'clubs', hand1)
        hand4 = Hand([Card('5', 'clubs'), Card('10', 'clubs')], cur_round, 'clubs', hand1)

        self.assertTrue(hand1.check_is_one_suit('clubs'))
        self.assertTrue(hand2.check_is_one_suit('clubs'))
        self.assertTrue(hand3.check_is_one_suit('clubs'))
        self.assertTrue(hand4.check_is_one_suit('clubs'))
        pass