Ejemplo n.º 1
0
    def opp_move(self, opp_name):

        #Getting the row for the previous game
        data = {}
        start_row = self.records.iloc[-1]
        for player in self.players:
            data[player] = start_row[player]

        #Getting the opponent's move from the user
        data['Place'] = UI.get_card('Discarded card:')
        count = UI.get_number('Number discarded:')
        choice = UI.get_from_list(['S', 'D'], 'Stack or Deck [S/D]: ')

        #Generating new data for the opponent
        data[opp_name] = start_row[opp_name] - count + 1
        data['Count'] = count
        data['Move'] = opp_name

        #If the opponent took from the stack...
        if choice == 'S':
            data['Take'] = start_row['Place']
            data['From'] = 'Pile'

        #If the opponent took from the deck...
        else:
            data['Take'] = '?'
            data['From'] = 'Deck'

        #Updating the records
        self.records = self.records.append(data, ignore_index=True)

        #Getting the next player
        index = self.players.index(opp_name)
        next = (index + 1) % len(self.players)
        return self.players[next]
Ejemplo n.º 2
0
    def start_move(self):

        #Getting the first move
        move = UI.get_from_list(self.players, 'Player start ')
        discard = UI.get_card('Discarded card:')

        #Getting info from the first row
        start_row = self.records.iloc[-1]
        take = start_row['Place']

        #If the player took the card
        if self.agent.name == move:

            #Getting the player's hand
            hand = self.records[self.agent.name].iloc[-1]
            start_len = len(hand)
            hand = filter(lambda x: x != discard, hand)
            end_len = len(hand)
            count = start_len - end_len
            hand.append(take)
            hand = sorted(hand)

            #Populating the new row
            data = {}
            for player in self.players:
                data[player] = start_row[player]
            data[self.agent.name] = hand
            data['Move'] = self.agent.name
            data['Place'] = discard
            data['Count'] = count
            data['Take'] = take
            data['From'] = 'Pile'

            #Updating the records
            self.records = self.records.append(data, ignore_index=True)

        #If the opponent took the card
        else:

            count = UI.get_number('Number discarded:')

            #Populating the new row
            data = {}
            for player in self.players:
                data[player] = start_row[player]
            data[move] = start_row[move] - count + 1
            data['Move'] = move
            data['Place'] = discard
            data['Count'] = count
            data['Take'] = take
            data['From'] = 'Pile'

            #Updating the records
            self.records = self.records.append(data, ignore_index=True)

        #Getting the next player
        index = self.players.index(move)
        next = (index + 1) % len(self.players)
        return self.players[next]