本文整理匯總了Python中chess.Board.push_san方法的典型用法代碼示例。如果您正苦於以下問題:Python Board.push_san方法的具體用法?Python Board.push_san怎麽用?Python Board.push_san使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類chess.Board
的用法示例。
在下文中一共展示了Board.push_san方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: repertoire
# 需要導入模塊: from chess import Board [as 別名]
# 或者: from chess.Board import push_san [as 別名]
def repertoire(id=1):
if request.args.get('practice'):
print(practice(id))
board = Board()
form = MoveForm()
if request.method == 'GET':
position = Position.query.filter_by(id=id).first()
moves = Move.query.join(User.moves).filter(User.id == current_user.id, Move.source_position_id == position.id).all()
return render_template('tools/repertoire.html', fen=position.fen + ' 0 1', moves=moves, form=form, id=id)
if request.method == 'POST':
fen = form.append_fen.data
san = form.append_san.data
quality_id = form.quality.data
board = Board(fen)
board.push_san(san)
source_position = Position.query.filter_by(fen=' '.join(fen.split()[:-2])).first()
end_position_fen = ' '.join(board.fen().split()[:-2])
end_position = Position.query.filter_by(fen=end_position_fen).first()
if end_position is None:
end_position = Position(fen=end_position_fen)
db.session.add(end_position)
move = Move.query.filter_by(source_position_id=source_position.id, destination_position_id=end_position.id).first()
if move is None:
move = Move(source_position_id=source_position.id, destination_position_id=end_position.id, san=san)
um = UserMove(quality_id=quality_id)
um.move = move
current_user.moves.append(um)
db.session.commit()
moves = Move.query.join(User.moves).filter(User.id == current_user.id, Move.source_position_id == source_position.id).all()
return render_template('tools/repertoire.html', fen=source_position.fen + ' 0 1', moves=moves, form=form, id=id)