Ejemplo n.º 1
0
 def move(cls, board):
     board = board.board
     for c1 in board:
         for c2 in board:
             for c3 in board:
                 if c1 == c2 or c1 == c3 or c2 == c3:
                     continue
                 if Set.is_set((c1, c2, c3)):
                     return (c1, c2, c3)
     return None
Ejemplo n.º 2
0
def update_while_playing(message, model):
    if is_start_game_message(model.bot_user_id, message):
        return (model,
                [chat_message("We're already in the middle of a game!")])

    elif is_set_call_message(message):
        message_text = message['text']
        cards_called_in = Set.letter_codes_to_cards(model.board, message_text)

        if Set.is_set(*cards_called_in):
            board = Set.remove_cards_from_board(model.board, cards_called_in)

            model.user_to_set_count[message['user']] += 1

            if len(board) > 12:
                board = Set.coalesce_empty_spaces(board)
                deck = model.deck
            elif len(model.deck) > 0:
                board, deck = Set.deal_cards_into_empty_spaces(
                    board, model.deck)
            elif len(board) == 0:
                return (Model._replace(
                    model,
                    board=board,
                    deck=[],
                    is_playing=False,
                ), [
                    chat_message('SET called by <@{}>!'.format(
                        message['user'])),
                    chat_message(generate_statistics(model.user_to_set_count)),
                    chat_message(GAME_OVER_MESSAGE)
                ])
            else:
                board = Set.coalesce_empty_spaces(board)
                deck = []

            return (Model._replace(
                model,
                board=board,
                deck=deck,
            ), [
                chat_message('SET called by <@{}>!'.format(message['user'])),
                chat_message(generate_statistics(model.user_to_set_count)),
                set_board_image_upload(board),
            ])

        else:
            return (model,
                    [chat_message("`{}` is not a set.".format(message_text))])

    elif is_no_sets_call_message(message):
        a_set = Set.find_set(model.board)

        if a_set:
            return (model,
                    [chat_message("Nope, there's at least one set here.")])
        else:
            board, deck = Set.deal_more_cards(model.board, model.deck)
            if Set.is_game_over(board, deck):
                return (Model._replace(
                    model,
                    board=board,
                    deck=[],
                    is_playing=False,
                ), [
                    chat_message(generate_statistics(model.user_to_set_count)),
                    chat_message(GAME_OVER_MESSAGE)
                ])
            else:
                return (Model._replace(model, board=board, deck=deck), [
                    chat_message("Dealing more cards..."),
                    set_board_image_upload(board),
                ])

    return (model, [])
Ejemplo n.º 3
0
 def remove_cards(self, cards):
     if not len(cards) == constants.GAME_AMOUNT:
         return
     if Set.is_set(cards):
         for card in cards:
             self.board.remove(card)