当前位置: 首页>>代码示例>>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;未经允许,请勿转载。