本文整理汇总了Python中pychess.Utils.lutils.LBoard.LBoard.asFen方法的典型用法代码示例。如果您正苦于以下问题:Python LBoard.asFen方法的具体用法?Python LBoard.asFen怎么用?Python LBoard.asFen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pychess.Utils.lutils.LBoard.LBoard
的用法示例。
在下文中一共展示了LBoard.asFen方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testFEN
# 需要导入模块: from pychess.Utils.lutils.LBoard import LBoard [as 别名]
# 或者: from pychess.Utils.lutils.LBoard.LBoard import asFen [as 别名]
def testFEN(self):
"""Testing board-FEN conversion with several positions"""
for i, fenstr in enumerate(self.positions[1:]):
board = LBoard()
board.applyFen(fenstr)
fenstr2 = board.asFen()
self.assertEqual(fenstr, fenstr2)
示例2: testFEN
# 需要导入模块: from pychess.Utils.lutils.LBoard import LBoard [as 别名]
# 或者: from pychess.Utils.lutils.LBoard.LBoard import asFen [as 别名]
def testFEN(self):
"""Testing board-FEN conversion with several positions"""
print
board = LBoard(Board)
for i, fenstr in enumerate(self.positions[1:]):
sys.stdout.write("#")
board.applyFen(fenstr)
fenstr2 = board.asFen()
self.assertEqual(fenstr, fenstr2)
print
示例3: create_fen
# 需要导入模块: from pychess.Utils.lutils.LBoard import LBoard [as 别名]
# 或者: from pychess.Utils.lutils.LBoard.LBoard import asFen [as 别名]
def create_fen(pieces):
""" Create a random FEN position using given pieces """
pos = pieces.rfind("k")
pieces = pieces[:pos], pieces[pos:]
ok = False
while not ok:
lboard = LBoard()
lboard.applyFen("8/8/8/8/8/8/8/8 w - - 0 1")
bishop_cords = [[], []]
bishop_colors_ok = True
cords = list(range(0, 64))
pawn_cords = list(range(0 + 8, 64 - 8))
# Order of color is important here to prevent offering
# positions with trivial captures in first move
for color in (WHITE, BLACK):
for char in pieces[color]:
piece = chrU2Sign[char.upper()]
attacked = True
limit = 100
while attacked and limit > 0:
cord = random.choice(pawn_cords if char == "p" else cords)
attacked = isAttacked(lboard, cord, 1 - color)
limit -= 1
lboard._addPiece(cord, piece, color)
cords.remove(cord)
if cord in pawn_cords:
pawn_cords.remove(cord)
if char == "b":
bishop_cords[color].append(cord)
# 2 same color bishop is not ok
if len(bishop_cords[color]) == 2 and bishop_colors_ok:
b0, b1 = bishop_cords[color]
b0_color = BLACK if RANK(b0) % 2 == FILE(b0) % 2 else WHITE
b1_color = BLACK if RANK(b1) % 2 == FILE(b1) % 2 else WHITE
if b0_color == b1_color:
bishop_colors_ok = False
break
ok = (not lboard.isChecked()) and (not lboard.opIsChecked()) and bishop_colors_ok
fen = lboard.asFen()
return fen
示例4: OLVFile
# 需要导入模块: from pychess.Utils.lutils.LBoard import LBoard [as 别名]
# 或者: from pychess.Utils.lutils.LBoard.LBoard import asFen [as 别名]
class OLVFile(ChessFile):
def __init__(self, handle):
ChessFile.__init__(self, handle)
self.games = self.read_games(handle)
self.count = len(self.games)
def read_games(self, handle):
""" We don't return games if stipulation is not 'mate in #' """
games = []
rec = None
rec_id = 1
contains_fairy_pieces = False
# authors is a more line list (each line starts with "-")
in_authors = False
# piece list are usually in one line list inside []
# but sometimes given in more line lists
in_white = False
in_black = False
for line in handle:
line = line.rstrip()
if in_authors and ":" in line:
in_authors = False
elif in_white and ":" in line:
in_white = False
elif in_black and ":" in line:
in_black = False
rec["FEN"] = self.lboard.asFen()
# New record start
if line == "---":
if rec is not None and rec["Black"].startswith("Mate in ") and not contains_fairy_pieces:
games.append(rec)
rec_id += 1
contains_fairy_pieces = False
self.lboard = LBoard()
self.lboard.applyFen("8/8/8/8/8/8/8/8 w - - 0 1")
rec = collections.defaultdict(str)
rec["Id"] = rec_id
rec["Offset"] = 0
elif line.startswith("authors:"):
in_authors = True
elif line.startswith("source:"):
rec["Event"] = line[8:]
elif line.startswith("source-id:"):
rec["Event"] = "%s (%s)" % (rec["Event"], line[12:])
elif line.startswith("date:"):
parts = line[6:].split("-")
parts_len = len(parts)
if parts_len >= 3:
rec["Day"] = parts[2]
if parts_len >= 2:
rec["Month"] = parts[1]
if parts_len >= 1:
rec["Year"] = parts[0]
elif line.startswith("distinction:"):
rec["Site"] = line[12:]
elif line.startswith("algebraic:"):
pass
elif line.startswith(" white:"):
parts = line.split("[")
if len(parts) > 1:
pieces = parts[1][:-1]
for piece in pieces.split(", "):
if piece.startswith("Royal") or piece[0] not in chr2piece:
contains_fairy_pieces = True
else:
cord = Cord(piece[1:3]).cord
piece = chr2piece[piece[0]]
self.lboard._addPiece(cord, piece, WHITE)
else:
in_white = True
elif line.startswith(" black:"):
parts = line.split("[")
if len(parts) > 1:
pieces = parts[1][:-1]
for piece in pieces.split(", "):
if piece.startswith("Royal") or piece[0] not in chr2piece:
contains_fairy_pieces = True
else:
cord = Cord(piece[1:3]).cord
piece = chr2piece[piece[0]]
self.lboard._addPiece(cord, piece, BLACK)
#.........这里部分代码省略.........