Beispiel #1
0
def nil_protect(player, cards_played):
    teammate = player.knowledge.teammate
    if c.numberInSuit(c.validOptions(player.hand, None, spades_broke), 'Spades') != 0:
        return cardsLeftInSuit(c.validOptions(player.hand, None, spades_broke), 'Spades')[-1]
    
    for suit in [x.type() for x in c.validOptions(player.hand, None, spades_broke)]:
        if (teammate[c.Card.SUITS.index(suit) + 1] == True) or cardsLeftInSuit(player.hand, suit) == cardsLeftInSuit(cardsLeft, suit):
            return c.highestInSuit(player.hand, suit, spades_broke)
    
    if list(filter(lambda x: x in winners(cardsLeft), c.validOptions(player.hand, None, spades_broke))) != []:
        return list(filter(lambda x: x in winners(cardsLeft), player.hand))[0]
    
    last_resort = c.validOptions(player.hand, None, spades_broke)[-1]
    for card in c.validOptions(player.hand, None, spades_broke):
        if card.number() > last_resort.number():
            last_resort = card
    return last_resort
Beispiel #2
0
def decide_move(player, cards_played):
    global cardsLeft

    cardsLeft = player.knowledge.cards_left

    index = len(cards_played)
    
    if player.knowledge.teammate[0] == 0 and player.knowledge.teammate[6] == 0:
        if index == 0:
            return nil_protect(player, cards_played)

        elif index == 1:
            if cards_played[0] in winners(cardsLeft) or player.knowledge.teammate[2 + c.Card.SUITS.index(cards_played[0].type())] == True:
                return protect(player, cards_played)
            elif c.numberInSuit(player.hand, cards_played[0].type()) == 0:
                return take(player, cards_played)
            elif list(filter(lambda x: c.Card.VALUES.index(x.number()) > c.Card.VALUES.index(cards_played[0].number()), c.validOptions(player.hand, cards_played[0].type(), spades_broke))) == []:
                return protect(player, cards_played)
            else:
                return c.highestInSuit(player.hand, cards_played[0].type(), spades_broke)
        else:
            if s.trick_winner(cards_played) != cards_played[0]:
                return protect(player, cards_played)
            else:
                return take(player, cards_played)
                        
    elif player.knowledge.opponent2[0] == 0 and player.knowledge.opponent2[6] == 0:
        if index == 3:
            if s.trick_winner(cards_played+[dump(player, cards_played)]) == cards_played[0]:
                return dump(player, cards_played)
            else:
                return c.validOptions(player.hand, cards_played[0].type(), spades_broke)[-1]
        else:
            return dump(player, cards_played)

    elif player.knowledge.opponent1[0] == 0 and player.knowledge.opponent1[6] == 0:
        if index != 0:
            if s.trick_winner(cards_played+[dump(player, cards_played)]) == cards_played[index - 1]:
                return dump(player, cards_played)
            else:
                return c.validOptions(player.hand, cards_played[0].type(), spades_broke)[-1]
        else:
            return dump(player, cards_played)
    else:
        return normal_move(player, cards_played)
Beispiel #3
0
def trick_winner(cards_played):
    card = c.highestInSuit(cards_played, 'Spades', spades_broken)
    if card != None:
        return card
    else:
        return c.highestInSuit(cards_played, cards_played[0].type(), spades_broken)