本文整理汇总了Python中chess.Board.fen方法的典型用法代码示例。如果您正苦于以下问题:Python Board.fen方法的具体用法?Python Board.fen怎么用?Python Board.fen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类chess.Board
的用法示例。
在下文中一共展示了Board.fen方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: repertoire
# 需要导入模块: from chess import Board [as 别名]
# 或者: from chess.Board import fen [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)
示例2: DialogEnterPosition
# 需要导入模块: from chess import Board [as 别名]
# 或者: from chess.Board import fen [as 别名]
#.........这里部分代码省略.........
hbox = QHBoxLayout()
hbox.addWidget(self.displayBoard)
hbox.addLayout(vbox_config)
vbox = QVBoxLayout()
vbox.addLayout(hbox)
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
vbox.addWidget(self.buttonBox)
self.setLayout(vbox)
self.connect(self.buttonBox, SIGNAL("accepted()"), self, SLOT("accept()"))
self.connect(self.buttonBox, SIGNAL("rejected()"), self, SLOT("reject()"))
self.cbWhiteShort.toggled.connect(self.set_castling_rights)
self.cbWhiteLong.toggled.connect(self.set_castling_rights)
self.cbBlackShort.toggled.connect(self.set_castling_rights)
self.cbBlackLong.toggled.connect(self.set_castling_rights)
self.rbWhite.toggle()
self.rbWhite.toggled.connect(self.set_turn)
self.rbBlack.toggled.connect(self.set_turn)
self.buttonInit.clicked.connect(self.initial_position)
self.buttonClear.clicked.connect(self.clear_board)
self.buttonCurrent.clicked.connect(self.set_current)
# reset who's current turn it is and the current
# castling rights of the position
self.set_castling_rights()
self.set_turn()
def set_castling_rights(self):
self.displayBoard.board.castling_rights = 0
if self.cbWhiteShort.isChecked():
self.displayBoard.board.castling_rights = self.displayBoard.board.castling_rights | chess.BB_H1
if self.cbWhiteLong.isChecked():
self.displayBoard.board.castling_rights = self.displayBoard.board.castling_rights | chess.BB_A1
if self.cbBlackShort.isChecked():
self.displayBoard.board.castling_rights = self.displayBoard.board.castling_rights | chess.BB_H8
if self.cbBlackLong.isChecked():
self.displayBoard.board.castling_rights = self.displayBoard.board.castling_rights | chess.BB_A8
if self.displayBoard.board.status() == chess.STATUS_VALID:
self.enable_ok_button()
else:
self.disable_ok_button()
def set_turn(self):
if self.rbWhite.isChecked():
self.displayBoard.board.turn = WHITE
else:
self.displayBoard.board.turn = BLACK
if self.displayBoard.board.status() == 0:
self.enable_ok_button()
else:
self.disable_ok_button()
def clear_board(self):
self.displayBoard.board.clear()
self.set_castling_rights()
self.set_turn()
self.update()
def initial_position(self):
self.displayBoard.board.reset()
self.set_castling_rights()
self.set_turn()
self.update()
def set_current(self):
fen = self.current.fen()
board = Board(fen)
self.displayBoard.board = board
self.set_castling_rights()
self.set_turn()
self.update()
# creates a deep copy of the given
# board into a clean new board, resetting
# all move histories, castling rights, etc.
def deep_copy_board_pos(self, board):
fresh = Board()
for i in range(0, 8):
for j in range(0, 8):
piece = board.piece_at(j * 8 + i)
if piece:
sym = piece.symbol()
fresh.set_piece_at(j * 8 + i, Piece.from_symbol(sym))
else:
fresh.remove_piece_at(j * 8 + i)
return fresh
def enable_ok_button(self):
self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(True)
self.update()
def disable_ok_button(self):
self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False)
self.update()