source/client/Controller.py
def processCards(self, visible_scards):
        """ Combine prepared cards and cards already on shared board.

         Runs must be processed a fair bit to determine location of wilds--this is done in processRuns.
         Some rule checking is performed here (before prepared and cards on shared board are combined:
         (i) Players cannot commence play by another player &  (ii) must have all groups required to Meld.
         processRuns also enforces some rules (e.g. runs are continuous).
         Remaining rules are enforced by Ruleset.py.
        """
        # before combining prepared cards with played cards, check that player is not BEGINNING
        # another player's groups.
        played_groups = []    # will contain list of keys corresponding to card groups that have been begun.
        for key, card_group in visible_scards[0].items():
            if len(card_group) > 0:
                played_groups.append(key)
        for key, card_group in self.prepared_cards.items():
            if len(card_group) > 0:
                group_key = key
                if not group_key[0] == self._state.player_index and group_key not in played_groups:
                    raise Exception("You are not allowed to begin another player's sets or runs.")
        # check to see if player has previously melded, if not, check if can.
        if (self._state.player_index, 0) not in played_groups:
            hl = len(self._state.hand_cards)
            self._state.rules.canMeld(self.prepared_cards, self._state.round, self._state.player_index, hl)
        # Unlike in HandAndFoot, where self.played_cards was used to check rules,
        # in Liverpool and other shared board games need to consider all of the played cards.
        numsets = self._state.rules.Meld_Threshold[self._state.round][0]
        self.played_cards = restoreRunAssignment(visible_scards[0], self._state.rules.wild_numbers, numsets)
        combined_cards = self._state.rules.combineCardDicts(self.played_cards, self.prepared_cards)
        self.processed_full_board = {}
        self.unassigned_wilds_dict = {}
        for k_group, card_group in combined_cards.items():
            # process runs from combined_cards (if k_group[1] > numsets, then it is a run).
            if k_group[1] >= numsets:
                processed_group, wild_options, unassigned_wilds = processRuns(card_group, self._state.rules.wild_numbers)
                if len(unassigned_wilds) > 0:
                    # wild is unassigned only when it can be played at either end. Hence there should be only 1.
                    if len(unassigned_wilds) > 1:
                        print("How odd --wild is unassigned only when it can be played at either end. Hence there should be only 1.")
                        print(processed_group)
                    else:
                        self.unassigned_wilds_dict[k_group] = [processed_group, wild_options, unassigned_wilds]
            else:
                # Cards are a set.  Code below sorts set by suit. Jokers have no suit, and
                # if wild won't sort properly with others, so wilds are split off separately.
                wilds_in_group = []
                not_wilds = []
                for card in card_group:
                    if card.number in  self._state.rules.wild_numbers:
                        wilds_in_group.append(card)
                    else:
                        not_wilds.append(card)
                not_wilds.sort(key=lambda wc:wc.suit)
                processed_group = wilds_in_group + not_wilds
            # unlike HandAndFoot, self.played_cards includes cards played by everyone.
            # have gone through all prepared cards w/o error, will use processed_full_board to update
            # _state.played_cards once all wilds assigned (unassigned wilds found in self.unassigned_wilds_dict)
            self.processed_full_board[k_group] = processed_group
        return
 Combine prepared cards and cards already on shared board.

         Runs must be processed a fair bit to determine location of wilds--this is done in processRuns.
         Some rule checking is performed here (before prepared and cards on shared board are combined:
         (i) Players cannot commence play by another player &  (ii) must have all groups required to Meld.
         processRuns also enforces some rules (e.g. runs are continuous).
         Remaining rules are enforced by Ruleset.py.
        
Combine prepared cards and cards already on shared board.
Runs must be processed a fair bit to determine location of wilds--this is done in processRuns.
Some rule checking is performed here (before prepared and cards on shared board are combined:
(i) Players cannot commence play by another player &  (ii) must have all groups required to Meld.
processRuns also enforces some rules .
Remaining rules are enforced by Ruleset.py.
Combine prepared cards and cards already on shared board . Runs must be processed a fair bit to determine location of wilds -- this is done in processRuns . Some rule checking is performed here ( before prepared and cards on shared board are combined : ( i ) Players cannot commence play by another player & ( ii ) must have all groups required to Meld . processRuns also enforces some rules . Remaining rules are enforced by Ruleset . py .
def processCards(self, visible_scards):
        played_groups = []    
        for key, card_group in visible_scards[0].items():
            if len(card_group) > 0:
                played_groups.append(key)
        for key, card_group in self.prepared_cards.items():
            if len(card_group) > 0:
                group_key = key
                if not group_key[0] == self._state.player_index and group_key not in played_groups:
                    raise Exception("You are not allowed to begin another player's sets or runs.")
        if (self._state.player_index, 0) not in played_groups:
            hl = len(self._state.hand_cards)
            self._state.rules.canMeld(self.prepared_cards, self._state.round, self._state.player_index, hl)
        numsets = self._state.rules.Meld_Threshold[self._state.round][0]
        self.played_cards = restoreRunAssignment(visible_scards[0], self._state.rules.wild_numbers, numsets)
        combined_cards = self._state.rules.combineCardDicts(self.played_cards, self.prepared_cards)
        self.processed_full_board = {}
        self.unassigned_wilds_dict = {}
        for k_group, card_group in combined_cards.items():
            if k_group[1] >= numsets:
                processed_group, wild_options, unassigned_wilds = processRuns(card_group, self._state.rules.wild_numbers)
                if len(unassigned_wilds) > 0:
                    if len(unassigned_wilds) > 1:
                        print("How odd --wild is unassigned only when it can be played at either end. Hence there should be only 1.")
                        print(processed_group)
                    else:
                        self.unassigned_wilds_dict[k_group] = [processed_group, wild_options, unassigned_wilds]
            else:
                wilds_in_group = []
                not_wilds = []
                for card in card_group:
                    if card.number in  self._state.rules.wild_numbers:
                        wilds_in_group.append(card)
                    else:
                        not_wilds.append(card)
                not_wilds.sort(key=lambda wc:wc.suit)
                processed_group = wilds_in_group + not_wilds
            self.processed_full_board[k_group] = processed_group
        return
def processCards ( self , visible_scards ) : played_groups = [ ] for key , card_group in visible_scards [ 0 ] . items ( ) : if len ( card_group ) > 0 : played_groups . append ( key ) for key , card_group in self . prepared_cards . items ( ) : if len ( card_group ) > 0 : group_key = key if not group_key [ 0 ] == self . _state . player_index and group_key not in played_groups : raise Exception ( "You are not allowed to begin another player's sets or runs." ) if ( self . _state . player_index , 0 ) not in played_groups : hl = len ( self . _state . hand_cards ) self . _state . rules . canMeld ( self . prepared_cards , self . _state . round , self . _state . player_index , hl ) numsets = self . _state . rules . Meld_Threshold [ self . _state . round ] [ 0 ] self . played_cards = restoreRunAssignment ( visible_scards [ 0 ] , self . _state . rules . wild_numbers , numsets ) combined_cards = self . _state . rules . combineCardDicts ( self . played_cards , self . prepared_cards ) self . processed_full_board = { } self . unassigned_wilds_dict = { } for k_group , card_group in combined_cards . items ( ) : if k_group [ 1 ] >= numsets : processed_group , wild_options , unassigned_wilds = processRuns ( card_group , self . _state . rules . wild_numbers ) if len ( unassigned_wilds ) > 0 : if len ( unassigned_wilds ) > 1 : print ( "How odd --wild is unassigned only when it can be played at either end. Hence there should be only 1." ) print ( processed_group ) else : self . unassigned_wilds_dict [ k_group ] = [ processed_group , wild_options , unassigned_wilds ] else : wilds_in_group = [ ] not_wilds = [ ] for card in card_group : if card . number in self . _state . rules . wild_numbers : wilds_in_group . append ( card ) else : not_wilds . append ( card ) not_wilds . sort ( key = lambda wc : wc . suit ) processed_group = wilds_in_group + not_wilds self . processed_full_board [ k_group ] = processed_group return
Combine prepared cards and cards already on shared board.
Combine prepared cards and cards already on shared board .
""" Combine prepared cards and cards already on shared board.

         Runs must be processed a fair bit to determine location of wilds--this is done in processRuns.
         Some rule checking is performed here (before prepared and cards on shared board are combined:
         (i) Players cannot commence play by another player &  (ii) must have all groups required to Meld.
         processRuns also enforces some rules (e.g. runs are continuous).
         Remaining rules are enforced by Ruleset.py.
        """ # before combining prepared cards with played cards, check that player is not BEGINNING # another player's groups. # will contain list of keys corresponding to card groups that have been begun. # check to see if player has previously melded, if not, check if can. # Unlike in HandAndFoot, where self.played_cards was used to check rules, # in Liverpool and other shared board games need to consider all of the played cards. # process runs from combined_cards (if k_group[1] > numsets, then it is a run). # wild is unassigned only when it can be played at either end. Hence there should be only 1. # Cards are a set.  Code below sorts set by suit. Jokers have no suit, and # if wild won't sort properly with others, so wilds are split off separately. # unlike HandAndFoot, self.played_cards includes cards played by everyone. # have gone through all prepared cards w/o error, will use processed_full_board to update # _state.played_cards once all wilds assigned (unassigned wilds found in self.unassigned_wilds_dict)
self
visible_scards