Пример #1
0
    def maybeEnablePlay(self, plus: int) -> bool:
        partner = (self.position + plus) % self.game.numPlayers
        assert partner != self.position

        lowest_value: int = 5
        best_index: int = -1

        i: int
        for i in range(len(self.hand)):
            card: CardInfo = gameCards[self.hand[i]]
            if card.value.value >= lowest_value:
                continue
            if len(self.game.playedCards[card.color]) + 1 != card.value.value:
                continue

            nextCard: CardInfo = CardInfo(card.color, Value(card.value + 1))
            cards: List[CardInfo] = [
                gameCards[h] for h in self.game.players[partner].hand
            ]
            if countValues(cards, nextCard) != 0:
                lowest_value = card.value.value
                best_index = i

        if best_index != -1:
            assert 1 <= lowest_value <= 4
            self.play_card(best_index)
            return True
        return False
Пример #2
0
 def noWorthlessOrDuplicateCardsVisible(self):
     discards: List[CardInfo] = [gameCards[d] for d in self.game.discards]
     p: Player
     h: int
     for h in chain(*[p.hand for p in self.game.players]):
         card: CardInfo = gameCards[h]
         score: int = len(self.game.playedCards[card.color])
         if card.value.value <= score:
             return False
         v: int
         for v in range(score + 1, card.value.value):
             earlier_card: CardInfo = CardInfo(card.color, Value(v))
             if countValues(discards, earlier_card) == Value(v).num_copies:
                 return False
         if self.visibleCopiesOf(card) >= 2:
             return False
     return True
Пример #3
0
 def isWorthless(self, color, value):
     playableValue = len(self.game.playedCards[color]) + 1
     if value < playableValue:
         return True
     while (value > playableValue):
         value = Value(value - 1)
         if self.playedCount[color][value] == value.num_copies:
             return True
     return False
Пример #4
0
 def maybeDiscardWorthlessCard(self, can_discard: bool) -> bool:
     discards: List[CardInfo] = [gameCards[d] for d in self.game.discards]
     cardHand: List[CardInfo] = [gameCards[h] for h in self.hand]
     i: int
     for i in range(len(self.hand)):
         card: CardInfo = gameCards[self.hand[i]]
         score: int = len(self.game.playedCards[card.color])
         if card.value <= score:
             return self.tryHardToDisposeOf(i, can_discard)
         elif countValues(cardHand, card) >= 2:
             return self.tryHardToDisposeOf(i, can_discard)
         else:
             assert card.value.value > score
             for v in range(score + 1, card.value.value):
                 earlier_card: CardInfo = CardInfo(card.color, Value(v))
                 discardCopies: int = countValues(discards, earlier_card)
                 if discardCopies == Value(v).num_copies:
                     return self.tryHardToDisposeOf(i, can_discard)
     return False
Пример #5
0
 def give_value_clue(self, who: int, value: Value) -> None:
     if self.debug:
         print('Sending Value Clue {value} to {who}'.format(
             value=value, who=self.game.players[who].name))
     rank = value.rank()
     self.game.send(
         'action', {
             'type': Action.Clue.value,
             'target': who,
             'clue': {
                 'type': Clue.Rank.value,
                 'value': rank.value
             }
         })
Пример #6
0
    def decide_move(self, can_clue, can_discard):
        colorOrder = self.game.variant.pile_colors

        print('Time To Decide a Move')
        print('Can Clue: {}'.format(can_clue))
        print('Can Discard: {}'.format(can_discard))
        while True:
            print()
            print('Options:')
            print('(0) Play a card')
            print('(1) Discard a card')
            print('(2) Clue a color')
            print('(3) Clue a number')
            print('(4) Print All Hands')
            print('(5) Check clues on card in own hand')
            print('(6) Check clues on card in other hands')
            print('(7) Print played cards')
            print('(8) Print trashed cards')
            print('(9) Print score, clues, strikes, deck count')
            try:
                i = int(input('--> '))
                if i < 0 or i > 9:
                    raise ValueError()
            except ValueError:
                continue
            if i == 0:
                try:
                    print('0 is Oldest')
                    print(str(len(self.hand) - 1) + ' is Newest')
                    i = int(input('Which Card --> '))
                    if i < 0 or i >= len(self.hand):
                        raise ValueError()
                except ValueError:
                    continue
                self.play_card(i)
                break
            elif i == 1:
                if not can_discard:
                    continue
                try:
                    print('0 is Oldest')
                    print(str(len(self.hand) - 1) + ' is Newest')
                    i = int(input('Which Card --> '))
                    if i < 0 or i >= len(self.hand):
                        raise ValueError()
                except ValueError:
                    continue
                self.discard_card(i)
                break
            elif i == 2:
                if not can_clue:
                    continue
                try:
                    print('Which Player?')
                    for p in self.game.players:
                        if p == self:
                            continue
                        print('({}) {}'.format(p.position, p.name))
                    w = int(input('--> '))
                    if (w < 0 or w >= len(self.game.players)
                            or w == self.position):
                        raise ValueError()
                except ValueError:
                    continue
                try:
                    print('Which Color?')
                    for i, c in enumerate(self.game.variant.clue_colors):
                        colorName = c.full_name(self.game.variant)
                        print('({}) {}'.format(i, colorName))
                    i = int(input('--> '))
                    if i < 0 or i >= len(self.game.variant.clue_colors):
                        raise ValueError()
                except ValueError:
                    continue
                if self.can_color_clue(w, self.game.variant.clue_colors[i]):
                    self.give_color_clue(w, self.game.variant.clue_colors[i])
                    break
                else:
                    print('The clue does not mark any cards')
            elif i == 3:
                if not can_clue:
                    continue
                try:
                    print('Which Player?')
                    for p in self.game.players:
                        if p == self:
                            continue
                        print('({}) {}'.format(p.position, p.name))
                    w = int(input('--> '))
                    if (w < 0 or w >= len(self.game.players)
                            or w == self.position):
                        raise ValueError()
                except ValueError:
                    continue
                try:
                    i = int(input('Which Number (1-5) --> '))
                    if i < 1 or i > 5:
                        raise ValueError()
                except ValueError:
                    continue
                v = Value(i)
                if self.can_value_clue(w, v):
                    self.give_value_clue(w, v)
                    break
                else:
                    print('The clue does not mark any cards')
                break
            elif i == 4:
                print('Player Hands (From Oldest to Newest)')
                playerOrder = ((i + self.position + 1) % self.game.numPlayers
                               for i in range(self.game.numPlayers - 1))
                for i in playerOrder:
                    player = self.game.players[i]
                    cards = []
                    for d in player.hand:
                        card = self.game.deck[d]
                        cards.append(str(card))
                    print('{}: {}'.format(player.name, ', '.join(cards)))
            elif i == 5:
                for i in range(len(self.hand)):
                    extra = ''
                    if i == 0:
                        extra = '(Oldest)'
                    if i == len(self.hand) - 1:
                        extra = '(Newest)'
                    print('Card Index ' + str(i) + ' ' + extra)
                    card = self.game.deck[self.hand[i]]
                    if card.positiveClueColors or card.positiveClueValue:
                        clues = [
                            c.full_name(self.game.variant)
                            for c in card.positiveClueColors
                        ]
                        if card.positiveClueValue:
                            clues.append(str(card.positiveClueValue))
                        print('POSITIVE: ' + ', '.join(c for c in clues))
                    if card.negativeClueColors or card.negativeClueValue:
                        clues = [
                            c.full_name(self.game.variant)
                            for c in card.negativeClueColors
                        ]
                        clues.extend(str(n) for n in card.negativeClueValue)
                        print('negative: ' + ', '.join(c for c in clues))
                    if not (card.positiveClueColors or card.positiveClueValue
                            or card.negativeClueColors
                            or card.negativeClueValue):
                        print('No Clues')
                    print()
            elif i == 6:
                try:
                    print('Which Player?')
                    for p in self.game.players:
                        if p == self:
                            continue
                        print('({}) {}'.format(p.position, p.name))
                    w = int(input('--> '))
                    if (w < 0 or w >= len(self.game.players)
                            or w == self.position):
                        raise ValueError()
                except ValueError:
                    continue
                player = self.game.players[w]
                for i in range(len(player.hand)):
                    extra = ''
                    if i == 0:
                        extra = '(Oldest)'
                    if i == len(player.hand) - 1:
                        extra = '(Newest)'
                    print('Card Index ' + str(i) + ' ' + extra)
                    card = self.game.deck[player.hand[i]]
                    if card.positiveClueColors or card.positiveClueValue:
                        clues = [
                            c.full_name(self.game.variant)
                            for c in card.positiveClueColors
                        ]
                        if card.positiveClueValue:
                            clues.append(str(card.positiveClueValue))
                        print('POSITIVE: ' + ', '.join(c for c in clues))
                    if card.negativeClueColors or card.negativeClueValue:
                        clues = [
                            c.full_name(self.game.variant)
                            for c in card.negativeClueColors
                        ]
                        clues.extend(str(n) for n in card.negativeClueValue)
                        print('negative: ' + ', '.join(c for c in clues))
                    if not (card.positiveClueColors or card.positiveClueValue
                            or card.negativeClueColors
                            or card.negativeClueValue):
                        print('No Clues')
                    print()
            elif i == 7:
                for c in colorOrder:
                    if self.game.playedCards[c]:
                        topCard = str(self.game.playedCards[c][-1])
                    else:
                        topCard = 'Empty'
                    colorName = c.full_name(self.game.variant)
                    print('{}: {}'.format(colorName, topCard))
            elif i == 8:
                cards = {c: [] for c in self.game.variant.pile_colors}
                for c in self.game.discards:
                    cards[c.suit].append(c.rank)
                for pile in cards.values():
                    pile.sort()
                for co in colorOrder:
                    print('{}: {}'.format(co.full_name(self.game.variant),
                                          ', '.join(str(c)
                                                    for c in cards[co])))
            elif i == 9:
                print('Score: {}'.format(self.game.scoreCount))
                print('Clues: {}'.format(self.game.clueCount))
                print('Strikes: {}'.format(self.game.strikeCount))
                print('Deck Count: {}'.format(self.game.deckCount))
                print('Turn Count: {}'.format(self.game.turnCount))
                print('Drawn Count: {}'.format(len(self.game.deck)))