當前位置: 首頁>>代碼示例>>Python>>正文


Python History.query方法代碼示例

本文整理匯總了Python中models.History.query方法的典型用法代碼示例。如果您正苦於以下問題:Python History.query方法的具體用法?Python History.query怎麽用?Python History.query使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在models.History的用法示例。


在下文中一共展示了History.query方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_game_history

# 需要導入模塊: from models import History [as 別名]
# 或者: from models.History import query [as 別名]
 def get_game_history(self, request):
     """Returns all of the game history"""
     game = get_by_urlsafe(request.urlsafe_game_key, Game)
     if not game:
         raise endpoints.NotFoundException(
                 'A Game with that game key does not exist!')
     qry = History.query(History.game == game.key)
     return HistoryForms(items=[history.to_form() for history in qry])
開發者ID:halee9,項目名稱:HangMan,代碼行數:10,代碼來源:api.py

示例2: get_game_history

# 需要導入模塊: from models import History [as 別名]
# 或者: from models.History import query [as 別名]
	def get_game_history(self, request):
		"""Returns a history of all moves made in game."""
		game = get_by_urlsafe(request.urlsafe_game_key, Game)
		if game:
			history = History.query(ancestor=game.key).order(History.order)
			return HistoryForms(items=[move.to_form() for move in history])
		else:
			raise endpoints.NotFoundException("Game not found!")
開發者ID:afumagalli,項目名稱:design-a-game,代碼行數:10,代碼來源:game.py

示例3: get_game_history

# 需要導入模塊: from models import History [as 別名]
# 或者: from models.History import query [as 別名]
 def get_game_history(self, request):
     """Return game history."""
     game = get_by_urlsafe(request.urlsafe_game_key, Game)
     if not game:
         raise endpoints.NotFoundException('Game not found!')
     histories = History.query(ancestor=game.key)
     histories = histories.order(History.turn)
     histories = histories.order(History.player_turn)
     return HistoryForms(items=[history.to_form() for history in histories])
開發者ID:seyfig,項目名稱:BattleShip,代碼行數:11,代碼來源:api.py

示例4: get_game_history

# 需要導入模塊: from models import History [as 別名]
# 或者: from models.History import query [as 別名]
 def get_game_history(self, request):
     """Return the game history."""
     game = get_by_urlsafe(request.urlsafe_game_key, Game)
     if game:
         histories = History.query(History.game==game.key).order(History.datetime)
         # histories = History.query(History.game==game.key)            
         return HistoryForms(items = [history.to_form() for history in histories])
     else:
         raise endpoints.NotFoundException('Game not found!')
開發者ID:chinaq,項目名稱:FSND-P4-Design-A-Game,代碼行數:11,代碼來源:api.py

示例5: get_game_history

# 需要導入模塊: from models import History [as 別名]
# 或者: from models.History import query [as 別名]
 def get_game_history(self, request):
     """Return a Game history.
         Args:
         request: The GET_GAME_REQUEST objects, which includes
             urlsafe_game_key
         Returns:
             HistoryForm with the history of requested game.
         Raises:
             endpoints.NotFoundException: If the game does not exist.
     """
     game = get_by_urlsafe(request.urlsafe_game_key, Game)
     if game is None:
         raise endpoints.NotFoundException('Game not found!')
     else:
         return History.query(History.game == game.key).get().to_form()
開發者ID:NadiiaLukianenko,項目名稱:tictactoegame,代碼行數:17,代碼來源:api.py

示例6: get

# 需要導入模塊: from models import History [as 別名]
# 或者: from models.History import query [as 別名]
 def get(self):
     PAGESIZE = 50
     contact_name = self.request.get('contact_name')    
     user = users.get_current_user()
     hist = History.query(History.email == user.email().lower())
     if contact_name:
         hist = hist.filter(History.contact_name == contact_name)
     hist = hist.order(-History.created).fetch(PAGESIZE)
     if self.request.headers.get('X-Requested-With') == 'XMLHttpRequest':
         self.response.headers['Content-Type'] = 'application/json'
         hist = [[e.to_dict(), e.key.id()] for e in hist]
         for e,id in hist:
             e['created']=e['created'].isoformat();
             e['id'] = id
         self.response.out.write(json.dumps({'hist':[e[0] for e in hist]}))
     else:
         template = jinja_environment.get_template('templates/history.html')
         self.response.out.write(template.render({'hist':hist}))
開發者ID:spicavigo,項目名稱:onlinesms_server,代碼行數:20,代碼來源:hello_world.py

示例7: make_move

# 需要導入模塊: from models import History [as 別名]
# 或者: from models.History import query [as 別名]
    def make_move(self, request):
        """Make move.
            Args:
            request: The MAKE_MOVE_REQUEST objects, which includes
                urlsafe_game_key, row, col - coordinates of cell the in grid,
                user - player who makes move.
            Returns:
                GameForm with the current game state.
            Raises:
                endpoints.ForbiddenException: If the game is already over.
                                              If the cell is already used.
                                              If it is not move of the user.
        """
        msg = 'Next move!'
        game = get_by_urlsafe(request.urlsafe_game_key, Game)
        history = History.query(History.game == game.key).get()
        if game.game_over:
            raise endpoints.ForbiddenException('Illegal action: '
                                               'Game is already over.')

        game_field_list = list(game.game_field)
        dim_size = int(math.sqrt(len(game_field_list)))
        row = request.row
        col = request.col

        msg = 'user is %s, and user_o is %s' % (request.user,
                                                game.user_o.get().name)
        if game_field_list[col + row * dim_size] != ' ':
            raise endpoints.ForbiddenException('Illegal action: '
                                               'the cell is already used.')

        if request.user == game.user_o.get().name:
            if game_field_list.count('x') - game_field_list.count('o') == 1:
                game_field_list[col + row * dim_size] = 'o'
                game_field_str = ''.join(game_field_list)
                msg = 'Game_field is %s' % (game_field_str,)
                game.game_field = game_field_str
                game.put()
                game = get_by_urlsafe(request.urlsafe_game_key, Game)
                # Check whether game is over and winner
                if check_winner(game_field_str, 'o', row, col):
                    game.end_game(game.user_o, game.user_x)
                    msg = 'Game is over! Winner-%s' % (game.user_o.get().name,)
                    # Task queue to update the leader
                    taskqueue.add(url='/tasks/_cache_current_leader')
                history.update_history(msg, game.user_o.get().name, row,
                                       col)
            else:
                return game.to_form('It is not your move!')
        elif request.user == game.user_x.get().name:
            if game_field_list.count('x') - game_field_list.count('o') == 0:
                game_field_list[col + row * dim_size] = 'x'
                game_field_str = ''.join(game_field_list)
                msg = 'Game_field is %s' % (game_field_str,)
                game.game_field = game_field_str
                game.put()
                game = get_by_urlsafe(request.urlsafe_game_key, Game)
                # Check whether game is over and winner
                if check_winner(game_field_str, 'x', row, col):
                    game.end_game(game.user_x, game.user_o)
                    msg = 'Game is over! Winner-%s' % (game.user_x.get().name,)
                    # Task queue to update the leader
                    taskqueue.add(url='/tasks/_cache_current_leader')
                history.update_history(msg, game.user_x.get().name, row, col)
            else:
                raise endpoints.ForbiddenException('Illegal action: '
                                                   'It is not your move!')

        if game.game_field.count(' ') == 0:
            game.end_game_draw(game.user_x, game.user_o)
            msg = 'Game is over! Draw game!'
            # Task queue to update the leader
            taskqueue.add(url='/tasks/_cache_current_leader')
            history.update_history(msg, '', row, col)
        return game.to_form(msg)
開發者ID:NadiiaLukianenko,項目名稱:tictactoegame,代碼行數:77,代碼來源:api.py

示例8: play_game

# 需要導入模塊: from models import History [as 別名]
# 或者: from models.History import query [as 別名]
    def play_game(self, request):
        """Choose an action in the current game"""

        game = Game.query(Game.game_id == request.game_id).get()
        if game is None:
            raise endpoints.BadRequestException(
                'specified game_id {} not found'.format(request.game_id))

        # handle if game status is finished
        if game.won is not None:
            raise endpoints.ForbiddenException('that game is finished')

        # check if player exists and is valid for this game
        contender = Player.query(Player.player_id == request.player_id).get()

        if contender is None:
            raise endpoints.BadRequestException(
                'specified player_id not found')

        elif game.player_id != contender.player_id:
            raise endpoints.UnauthorizedException(
                'specified player_id not valid for this game')

        # --- game logic ---
        hint = None
        hints = [
            "McCree stares with accusing blue eyes, baring your soul",
            "McCree asks if Lady Luck has visited recently, flexing his gun hand",
            "McCree holds his cap against the blazing sun, checking his watch",
            "McCree chews on a piece of unidentified jerky, smirking through a ghastly grin",
            "McCree reloads his revolver with a flick of the wrist, preparing to send you to the clearing at the end of the path"
        ]

        # roll a random action for mcree

        actions = ['retreat', 'pursue', 'showdown']
        botAction = random.choice(actions)

        if request.action in actions:
            action = request.action
        else:
            raise endpoints.BadRequestException(
                'that action is not a possible choice')

        # increment round counter
        game.round_count = game.round_count + 1

        if (botAction == "pursue" and action == "retreat") \
                or (botAction == "showdown" and action == "pursue") \
                or (botAction == "retreat" and action == "showdown"):
                # McCree won the round, increment ultie meter
            game.highnoon = game.highnoon + 25
            if game.highnoon >= 70:
                hint = random.choice(hints)

        if (action == "pursue" and botAction == "retreat") \
                or (action == "showdown" and botAction == "pursue") \
                or (action == "retreat" and botAction == "showdown"):
            # You won the round, roll for damage
            game.health = game.health - random.randint(20, 30)

        else:
            # stalemate, which helps McCree a bit
            game.highnoon = game.highnoon + 15

        # check if mccree is dead
        if game.health <= 0:
            contender.wins = contender.wins + 1
            game.won = True

        # ultie meter is full - roll to see if high noon procs
        if game.highnoon >= 100:
            # 1/9 chance for first time, then 1/6 until guaranteed at fourth
            # meter refill
            if random.randint(0, game.fun_quotient) == 0:
                hint = "ITS HIGH NOON - a red mist fills your eyes"
                contender.needs_taunted = True
                game.won = False
            else:
                # narrowly avoided certain demise
                hint = "Luckily you're behind cover when you hear ITS HIGH NOON"
                # make the game even more fun by increasing the odds of
                # insta-death
                game.fun_quotient = game.fun_quotient - 3
                # reset ultie meter
                game.highnoon = 0

        moves = History.query(History.game == game.key).get()

        # build dict of round outcomes
        action_dict = {
            "player_action": action,
            "ai_action": botAction,
            "health": game.health,
            "highnoon_meter": game.highnoon,
            "fun_quotient": game.fun_quotient,
            "won": game.won,
            "round_count": game.round_count
        }

#.........這裏部分代碼省略.........
開發者ID:bschmoker,項目名稱:highnoon,代碼行數:103,代碼來源:api.py


注:本文中的models.History.query方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。