本文整理汇总了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)