def make_game_easier(cls, game, hint_num): cards = Card.get_cards_for_game(game) unmatched_cards = filter(lambda c: not c.matched, cards) hint_histories = [] while game.matched != 52 and hint_num > 0: card_1 = unmatched_cards[0] card_2 = filter(lambda c: c != card_1 and c.value == card_1.value, unmatched_cards)[0] # Update game state card_1.matched = True card_2.matched = True game.matched += 2 game.attempts += 1 hint_num -= 1 # Update card state unmatched card list unmatched_cards.remove(card_1) unmatched_cards.remove(card_2) card_1.put() card_2.put() # Create history log history = History.create_history(game=game, card_1=card_1, card_2=card_2, message='Hint Match') hint_histories.append(history) game.put() return hint_histories
def get_game_card(self, request): """Return card information of given game.""" game = get_by_urlsafe(request.urlsafe_game_key, Game) if not game: raise endpoints.NotFoundException('Game not found!') if game.game_over: raise endpoints.ForbiddenException('Illegal action: Game is already over.') cards = Card.get_cards_for_game(game) return CardForms(items=[c.to_form() for c in cards])