Exemple #1
0
 def play_turn(self, state, hand, all_is_win=False):
     legal = legal_moves(state, hand)
     if not len(legal):
         print 'hand: ', Card.show_summarized(hand)
         print 'table:', Card.show_summarized(state.table_cards())
         raise Exception('no legal cards to play; should not be possible!')
     return choice(legal)
Exemple #2
0
 def play_card(self, state, player_nr, card):
     ''' Check if no card played yet '''
     try:
         if state._cards_played[state._round][player_nr]:
             raise Exception(
                 'there is already a card for player %d in round %d' %
                 (player_nr, state._round))
     except IndexError:
         ''' no card found (which is okay, though it should be None) '''
     ''' No need to check if it's player's turn, this function is only called if it is '''
     ''' Check if card in hand '''
     if card not in self.player_cards[player_nr]:
         raise Exception(
             u'tried to play %s, which is not in player #%s hand' %
             (unicode(card), player_nr))
     ''' Check if legal move '''
     if card not in legal_moves(state, self.player_cards[player_nr]):
         raise Exception(
             u'tried to play %s, which is not a legal move at this time for player #%s'
             % (unicode(card), player_nr))
     ''' If it's in hand, it can't secretly be a new instance '''
     ''' Remove from hand '''
     self.player_cards[player_nr].remove(card)
     ''' Put on stack '''
     state._cards_played[state._round][player_nr] = card
Exemple #3
0
    def play_turn(self, state, hand, all_is_win=False):
        ''' keep track of opponents if not already '''
        if self.opponents is None:
            self.opponents = []
            for opp_nr in range(4):
                if not opp_nr == self.number:
                    self.opponents.append(Opponent(opp_nr, state, hand))
            for opp in self.opponents:
                opp.add_opponents(self.opponents)
        for opp in self.opponents:
            opp.filter()
            opp.show_opponent_state()  #tmp
        ''' get all legal moves '''
        legal = sort_by_value(legal_moves(state, hand))
        #self.show_game_state(state, hand)
        return legal[-1]

        for card in legal:
            self.lose_chance(card, state, hand)
        legal = sort_by_value(legal_moves(state, hand))
        return legal[-1]
Exemple #4
0
 def play_turn(self, state, hand, all_is_win = False):
     legal = legal_moves(state, hand)
     print 'it is your turn to play a card'
     self.show_cards(state.table_cards(), 'table')
     self.show_short(hand, 'hand')
     if len(legal) > 1:
         card = self.input_choose_card(legal, 'possible')
     else:
         card = legal[0]
         print 'your only possible move %s was selected automatically' % card
     print 'you are playing %s' % card
     return card
Exemple #5
0
 def play_turn(self, state, hand, all_is_win = False):
     legal = self.sort_by_value(legal_moves(state, hand))
     if state.is_round_opening():
         ''' opening player; play lowest '''
         return legal[0]
     else:
         non_win = self.non_win_cards(state, legal)
         if len(non_win):
             ''' react with the highest card that can't win '''
             return non_win[-1]
         else:
             ''' have no cards to dodge '''
             return legal[0]
Exemple #6
0
 def play_turn(self, state, hand, all_is_win=False):
     legal = sort_by_value(legal_moves(state, hand))
     if not legal[0].colour == state.current_colour():
         ''' lose colour if good option (1-2 cards), else just play '''
         lose_colours = [
             pair[1] for pair in self.colour_lose_order(hand)
             if 1 <= pair[0] <= 2
         ]
         play_cards = []
         for colour in lose_colours:
             play_cards += sort_by_value(filter_colour(legal, colour),
                                         reverse=True)
         if len(play_cards):
             return play_cards[-1]
     ''' if recognizing or nothing to get rid of, just play '''
     return super(IsolateColour, self).play_turn(state=state,
                                                 hand=hand,
                                                 all_is_win=all_is_win)
Exemple #7
0
 def play_turn(self, state, hand, all_is_win = False):
     legal = self.sort_by_value(legal_moves(state, hand))
     if state.is_round_opening():
         ''' opening player; play lowest '''
         return legal[0]
     elif state.turn_nr() == 3:
         if state.round_points() == 0:
             ''' last player and no points; dump high cards '''
             return legal[-1]
     elif state.rounds_completed() == 0:
         ''' first round; no points allowed; dump highest '''
         return legal[-1]
     ''' there are or could be points '''
     non_win = self.non_win_cards(state, legal)
     if len(non_win):
         ''' react with the highest card that can't win '''
         return non_win[-1]
     else:
         ''' we can't dodge; might as well dump high card '''
         return legal[-1]
Exemple #8
0
 def play_turn(self, state, hand, all_is_win=False):
     legal = self.sort_by_value(legal_moves(state, hand))
     return legal[-1]