本文整理汇总了Python中models.Game.current方法的典型用法代码示例。如果您正苦于以下问题:Python Game.current方法的具体用法?Python Game.current怎么用?Python Game.current使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Game
的用法示例。
在下文中一共展示了Game.current方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: next_move
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import current [as 别名]
def next_move():
game = Game.current()
last_state = GameState.get(
game_id=game.id,
seq=game.current_seq - 1
)
if last_state is None:
GameState.insert(
game_id=game.id,
seq=0,
black_captures=0,
white_captures=0,
illegal=json.dumps([]),
board=json.dumps([[0] * 19] * 19),
sgf=DEFAULT_SGF,
)
return True
top_moves = Vote.summary(game.id, game.current_seq)
if not top_moves:
return False
top_move = top_moves[0].move
result = call_gnugo(
last_state.sgf,
game.current_seq,
top_move,
)
next_state = parse_gnugo(result)
next_state['black_captures'] += last_state['black_captures']
next_state['white_captures'] += last_state['white_captures']
GameState.insert(
game_id=game.id,
seq=game.current_seq,
move=top_move,
**next_state
)
Game.insert_or_update(
keys=('id',),
id=game.id,
current_seq=game.current_seq + 1,
)
message = 'Move %d, %s plays %s.' % (
game.current_seq,
game.current_seq % 2 and "Black" or "White",
Pretty.pos(top_move),
)
for room_id in (1, 2):
ChatMessage.insert(
room_id=room_id,
user_id=0,
message=message,
)
signal_message(room_id, 'send')
示例2: GET
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import current [as 别名]
def GET(self):
game = Game.current()
web.header(
'Content-Disposition',
'attachment; filename="ConGo-game-%s.sgf"' % (game.id,),
)
web.header('Content-Type', 'application/x-go-sgf')
data = [
'(;GM[1]FF[4]CA[UTF-8]AP[ConGo:0.1]ST[2]',
'RU[Japanese]SZ[19]KM[6.50]',
'GN[ConGo Game %s]PW[White Team]PB[Black Team]' % (game.id,),
'CP[2015 Jay Chan]RO[%s]' % (game.id),
]
end_seq = game.current_seq + 1
for seq in range(1, end_seq):
vote_counts = Vote.summary(game.id, seq)
show_current_move = seq < end_seq - 1
if seq > 1:
data.append(';%s[%s]' % (
(seq - 1) % 2 == 1 and 'B' or 'W',
prev_chosen_move,
))
if show_current_move:
data.append('LB')
vote_data = []
for i, vote in enumerate(list(vote_counts)[:7]):
label = chr(i + 65)
if i == 0:
chosen_move = vote.move
if vote.move != 'tt':
if show_current_move:
data.append('[%s:%s]' % (vote.move, label))
vote_data.append('%s: %s votes\n' % (label, vote.cnt))
else:
vote_data.append('Pass: %s votes\n' % (vote.cnt,))
if seq == 1:
data.append('C[con-go.net\n\n')
else:
data.append('C[')
votes = Vote.details(game.id, seq - 1, prev_chosen_move)
for vote in list(votes)[:5]:
data.append('%s (%s)\\: ' % (vote.name, Pretty.rating(vote.rating)))
notes = re.sub('\n', ' ', vote.notes)
notes = re.sub('\[', '(', notes)
notes = re.sub('\]', ')', notes)
notes = re.sub(r'\\', '\\\\', notes)
notes = re.sub(r':', '\\:', notes)
data.append(notes + '\n\n')
data.append('\n')
if show_current_move:
data.extend(vote_data)
data.append(']')
prev_chosen_move = chosen_move
data.append(')')
return ''.join(data)