本文整理汇总了Python中models.Move.query方法的典型用法代码示例。如果您正苦于以下问题:Python Move.query方法的具体用法?Python Move.query怎么用?Python Move.query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Move
的用法示例。
在下文中一共展示了Move.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: resetGameState
# 需要导入模块: from models import Move [as 别名]
# 或者: from models.Move import query [as 别名]
def resetGameState(self, request):
# Remove move ownership for all users
# Resets move availablities to True
game_id = request.game_id
# for the moment, resets every move for provided game_id
moves = Move.query().fetch()
moves_deleted = Move.query(Move.game_id == game_id).fetch()
game = Game.query(Game.game_id == game_id).get()
if game == None:
return StringMessage(message = "No Game found for ID: {0} ".format(game_id))
print("game id is {0} {1}".format(game_id, moves[0].game_id ))
# Deleting Game
game.key.delete()
# Deleting Moves
for move in moves_deleted:
print("Deleting moves, {0}".format(move))
move.key.delete()
return StringMessage(message = "Game Reset Complete, deleted {0} moves for Game: {1} ".format(len(moves_deleted), game_id))
示例2: _check_game_state
# 需要导入模块: from models import Move [as 别名]
# 或者: from models.Move import query [as 别名]
def _check_game_state(game_id):
""" Checks whether there's a victory condition, losing condition, or no more available moves """
print("\n\nInside check game state, game_id: " + game_id)
moves = Move.query(Move.game_id == game_id).fetch()
available_moves = Move.query(Move.available == True, Move.game_id == game_id).fetch()
if len(moves) == 0:
print("\n\n game_id not found {0} \n\n".format(game_id))
return "game_id_not_found"
winner_id = GuessANumberApi._check_winning_condition(game_id)
if winner_id != False:
print("\n\n############### Game won by:" + winner_id + " ###############\n\n")
return winner_id
if len(available_moves) == 0:
print("\n\n Game Ended, No more moves left {0} \n\n".format(game_id))
return "no_more_moves"
print("\n\nNo winners yet for game: {0} \n\n".format(game_id))
return "no_winners_yet"
示例3: makeMove
# 需要导入模块: from models import Move [as 别名]
# 或者: from models.Move import query [as 别名]
def makeMove(self, request):
""" Asigns specific move to a user for a specific game_id, as long as its available """
x = request.x
y = request.y
game_id = request.game_id
user_id = request.user_id
game = Game.query(Game.game_id == game_id).get()
queried_move = Move.query(Move.x == x, Move.y == y,
Move.game_id == game_id).fetch(1)
if game == None :
print("\n\nInvalid Move, Wrong Game ID\n\n")
return StringMessage(message = "Invalid Move, Wrong Game ID" )
winner_id = GuessANumberApi._check_winning_condition(game_id)
if winner_id != False:
print("\n\n Game Won By {0} \n\n".format(winner_id))
return StringMessage(message = "\n\n Game Won By {0} \n\n".format(winner_id))
available_moves = Move.query(Move.available == True, Move.game_id == game_id).fetch()
if len(available_moves) == 0:
print("\n\n Game Ended, No more moves left {0} \n\n".format(game_id))
return "no_more_moves"
if user_id == None or user_id not in [game.player1, game.player2]:
print("\n\nInvalid move parameters\n\n")
return StringMessage(message = "Invalid Move, Wrong User ID" )
if len(queried_move) == 0:
print("\n\nInvalid move parameters\n\n")
return StringMessage(message = "Invalid move parameters, Wrong Game ID or Move out of range" )
if user_id == game.last_play_user_id:
print("\n\n This Player already moved\n\n")
return StringMessage(message = "Invalid move, This Player already moved" )
move = queried_move[0]
if move.available != True:
print("\n\nMove already done by: {0} \n\n".format(move.user_id))
return StringMessage(message = "Move {0} has already been made by User with ID: : {1}"
.format(move.description, move.user_id) )
move.user_id = user_id
move.available = False
move.put()
game.last_play_user_id = user_id
game.put()
GuessANumberApi._show_game_picture(game_id)
GuessANumberApi._check_game_state(game_id)
return StringMessage(message = "Move {0} assign to {1} for game_id: {2}, x:{3} and y:{4}".format(move.description, user_id, game_id, x, y) )
示例4: _show_game_picture
# 需要导入模块: from models import Move [as 别名]
# 或者: from models.Move import query [as 别名]
def _show_game_picture(game_id):
""" Print visual representation of game state """
moves = Move.query(Move.game_id == game_id).order(Move.x, Move.y).fetch()
if len(moves) == 0:
print("\n\nCant print game state, Invalid game_id {0}\n\n".format(game_id))
return StringMessage(message = "Invalid move parameters. no game found" )
player1,player2 = GuessANumberApi._get_players_in_game(game_id)
print("Current Players for Game ID {0}: {1}, {2}".format(game_id, player1, player2) )
m_00 = Move.query(Move.x == 0, Move.y == 0,
Move.game_id == game_id).fetch(1)[0]
m_01 = Move.query(Move.x == 0, Move.y == 1,
Move.game_id == game_id).fetch(1)[0]
m_02 = Move.query(Move.x == 0, Move.y == 2,
Move.game_id == game_id).fetch(1)[0]
m_10 = Move.query(Move.x == 1, Move.y == 0,
Move.game_id == game_id).fetch(1)[0]
m_11 = Move.query(Move.x == 1, Move.y == 1,
Move.game_id == game_id).fetch(1)[0]
m_12 = Move.query(Move.x == 1, Move.y == 2,
Move.game_id == game_id).fetch(1)[0]
m_20 = Move.query(Move.x == 2, Move.y == 0,
Move.game_id == game_id).fetch(1)[0]
m_21 = Move.query(Move.x == 2, Move.y == 1,
Move.game_id == game_id).fetch(1)[0]
m_22 = Move.query(Move.x == 2, Move.y == 2,
Move.game_id == game_id).fetch(1)[0]
m_00 = m_00.user_id or m_00.description
m_01 = m_01.user_id or m_01.description
m_02 = m_02.user_id or m_02.description
m_10 = m_10.user_id or m_10.description
m_11 = m_11.user_id or m_11.description
m_12 = m_12.user_id or m_12.description
m_20 = m_20.user_id or m_20.description
m_21 = m_21.user_id or m_21.description
m_22 = m_22.user_id or m_22.description
print("\n\n\n")
print("TIC TAC TOE GAME")
print("\n")
print(" {0} | {1} | {2} ".format(m_00, m_01, m_02))
print("-----------------------------")
print(" {0} | {1} | {2} ".format(m_10, m_11, m_12))
print("-----------------------------")
print(" {0} | {1} | {2} ".format(m_20, m_21, m_22))
print("\n\n\n")
示例5: historyForGame
# 需要导入模块: from models import Move [as 别名]
# 或者: from models.Move import query [as 别名]
def historyForGame(self, game):
"""return list of moves from this game"""
list = Move.query(Move.gameKey == game.key).fetch()
for move in list:
move.game = game
move.user = self.getPlayer(game, move)
return list
示例6: _get_players_in_game
# 需要导入模块: from models import Move [as 别名]
# 或者: from models.Move import query [as 别名]
def _get_players_in_game(game_id):
moves = Move.query(Move.game_id == game_id).fetch()
if len(moves) == 0:
return StringMessage(message = "Invalid move parameters. no game found" )
print("Getting players in game...")
user_ids = []
for move in moves:
user_id = move.user_id
# print("checking for ID: {0}".format( user_id) )
if user_id not in user_ids and user_id != None:
# print("ID: {0} was inserted".format( user_id) )
user_ids.append(user_id)
print(user_ids)
if len(user_ids) == 2:
player1 = user_ids[0]
player2 = user_ids[1]
elif len(user_ids) == 1:
player1 = user_ids[0]
player2 = None
else:
player1 = None
player2 = None
print(player2, player1)
return [player1, player2]
示例7: _prepReminder
# 需要导入模块: from models import Move [as 别名]
# 或者: from models.Move import query [as 别名]
def _prepReminder():
games = Game.query(
Game.gameCurrentMove < 9 and Game.gameCurrentMove > 0).fetch()
remindees = ''
if games:
# If there are games ready for sign up,
# format announcement and set it in memcache for each game
for game in games:
last_move = Move.query(
Move.moveNumber==game.gameCurrentMove-1).get()
if last_move:
current_time = datetime.utcnow()
if last_move.moveTime and (current_time - last_move.moveTime > timedelta(days=5)):
next_player = Player.query(Player.displayName == game.nextPlayer).get()
if next_player.mainEmail:
print 'next_player.mainEmail', next_player.mainEmail
remindees.join(next_player.displayName)
mail.send_mail(
'[email protected]{}.appspotmail.com' .format(
app_identity.get_application_id()),
next_player.mainEmail,
'Coming back to tic-tac-toe?',
'It has been 5 days since the last move on:\r\n\r\n{}' .format(
game.name)
)
return remindees
示例8: getGameHistory
# 需要导入模块: from models import Move [as 别名]
# 或者: from models.Move import query [as 别名]
def getGameHistory(self, request):
""" shows a list of all the moves for each game"""
game_key = ndb.Key(urlsafe=request.websafeGameKey)
moves = Move.query(ancestor=game_key).fetch()
if not moves:
raise endpoints.NotFoundException('No moves found')
else:
return MovesForm(items=[move._copyMoveToForm for move in moves])
示例9: get_game_history
# 需要导入模块: from models import Move [as 别名]
# 或者: from models.Move import query [as 别名]
def get_game_history(self, request):
"""get moves history for each game requested"""
url_safe_key = request.urlsafe_game_key
game = get_by_urlsafe(url_safe_key, Game)
moves = Move.query(Move.game == game.key)
moves_list = []
for move in moves:
moves_list.append(move.to_form())
return MoveForms(items=moves_list)
示例10: cancel_game
# 需要导入模块: from models import Move [as 别名]
# 或者: from models.Move import query [as 别名]
def cancel_game(self, request):
""" Delete an unfinished game """
game_id = request.game_id
game = Game.query(Game.game_id == game_id).get()
if game == None:
return StringMessage(message = "No Game found for ID: {0} ".format(game_id))
if game.finished == True:
return StringMessage(message = "Can't delete a game thats already finished")
# for the moment, resets every move for provided game_id
moves = Move.query().fetch()
moves_deleted = Move.query(Move.game_id == game_id).fetch()
print("game id is {0} {1}".format(game_id, moves[0].game_id ))
# Deleting Game
game.key.delete()
# Deleting Moves
for move in moves_deleted:
move.key.delete()
return StringMessage(message = "Game Reset Complete, deleted {0} moves for Game: {1} ".format(len(moves_deleted), game_id))
示例11: _get_players_in_game
# 需要导入模块: from models import Move [as 别名]
# 或者: from models.Move import query [as 别名]
def _get_players_in_game(game_id):
""" returns player ids from a game """
moves = Move.query(Move.game_id == game_id).fetch()
if len(moves) == 0:
return StringMessage(message = "Invalid move parameters. no game found" )
print("Getting players in game...")
user_ids = []
game = Game.query(Game.game_id == game_id).get()
user_ids.append(game.player1)
user_ids.append(game.player2)
return user_ids
示例12: startGame
# 需要导入模块: from models import Move [as 别名]
# 或者: from models.Move import query [as 别名]
def startGame(self, request):
""" Initializes all 9 posible moves using provided game_id """
game_id = request.game_id
player1 = request.player1
player2 = request.player2
if request.game_id == None:
return StringMessage(message = "Failed, Empty game_id. Please enter a valid unique game_id")
if request.player1 == None or request.player2 == None:
return StringMessage(message = "Failed, Missing Players. Make sure both player ids are present")
if request.player1 == request.player2:
return StringMessage(message = "Failed, Player Ids must be different")
game_exists = len(Move.query(Move.game_id == game_id).fetch()) > 0
if game_exists:
return StringMessage(message = "Game Creation Failed, Game ID already exists: {0}".format( game_id ) )
# Creating Game
game = Game(game_id = game_id, player1 = request.player1, player2 = request.player2)
game.put()
print("New Game Created: {0}".format(game))
mv1 = Move(x = 0, y = 0, game_id = game_id, available = True, description = "[0,0]")
mv2 = Move(x = 0, y = 1, game_id = game_id, available = True, description = "[0,1]")
mv3 = Move(x = 0, y = 2, game_id = game_id, available = True, description = "[0,2]")
mv4 = Move(x = 1, y = 0, game_id = game_id, available = True, description = "[1,0]")
mv5 = Move(x = 1, y = 1, game_id = game_id, available = True, description = "[1,1]")
mv6 = Move(x = 1, y = 2, game_id = game_id, available = True, description = "[1,2]")
mv7 = Move(x = 2, y = 0, game_id = game_id, available = True, description = "[2,0]")
mv8 = Move(x = 2, y = 1, game_id = game_id, available = True, description = "[2,1]")
mv9 = Move(x = 2, y = 2, game_id = game_id, available = True, description = "[2,2]")
# ndb.put_multi([ mv1, mv2, mv3, mv4, mv5, mv6, mv7, mv8, mv9])
for m in [ mv1, mv2, mv3, mv4, mv5, mv6, mv7, mv8, mv9]:
print(" saving: {0}".format(m) )
m.put()
return StringMessage(message = "New Game Created, ID: {0} | Player 1: {1} | Player 2: {2}".format( game_id, player1, player2 ) )
示例13: show_game_ids
# 需要导入模块: from models import Move [as 别名]
# 或者: from models.Move import query [as 别名]
def show_game_ids(self, request):
moves = Move.query().fetch()
game_ids = []
for move in moves:
game_id = move.game_id
if game_id not in game_ids:
game_ids.append(game_id)
#Showing game moves per game
GuessANumberApi._show_game_picture(game_id)
GuessANumberApi._check_game_state(game_id)
print( "\n\n Total Game IDS: {0}, IDS: {1} \n\n".format( len(game_ids), str(game_ids) ) )
return StringMessage(message= "Total Moves: {0}, Total Game IDS: {1}, IDS: {2}".format( len(moves), len(game_ids), str(game_ids) ) )
示例14: get_game_history
# 需要导入模块: from models import Move [as 别名]
# 或者: from models.Move import query [as 别名]
def get_game_history(self, request):
"""Return a game's move history.
Args:
urlsafe_game_key (str): The game URL.
Returns:
moves (Move[]): An array of Move instances containing the game's
move history.
Raises:
NotFoundException: If game does not exist.
"""
game = get_by_urlsafe(request.urlsafe_game_key, Game)
if not game:
raise endpoints.NotFoundException('Game not found!')
moves = Move.query(Move.game == game.key).order(Move.created_at)
return HistoryForms(items=[move.to_form() for move in moves])
示例15: show_game_history
# 需要导入模块: from models import Move [as 别名]
# 或者: from models.Move import query [as 别名]
def show_game_history(self, request):
"""Shows the history of a particular game"""
game = utils.get_by_urlsafe(request.urlsafe_game_key, Game)
moves = Move.query(Move.game == game.key).order(Move.move_index)
return MoveForms(items=[move.to_form() for move in moves])