stockfish.py 在晋升时记录的移动是什么?

huangapple go评论66阅读模式
英文:

What does stockfish.py log as a move when promoting?

问题

I will provide a translation of the code portion you mentioned:

我刚刚在使用stockfish库时做了一些尝试将棋步转换为PGN文本格式时出现了错误

目前每一步棋都以这种格式出现"a1b2"我假设升变可能是这样的"c7c8=Q"但我不确定因为它也可能是这样的"c8=Q"以下是一些代码

best_w = stockfish.get_top_moves(3)
best_w = best_w[random.randint(0,2)]['Move']
fgn_w = getfgn(best_w)

best_b = stockfish.get_top_moves(3)
best_b = best_w[random.randint(0,2)]['Move']
fgn_b = getfgn(best_b)

我之前没有加入这些try语句但现在我加入了它们以便在再次出现错误时打印返回的内容

def getfgn(move):
  try:
    piece = stockfish.get_what_is_on_square(move[:2])
  except:
    print(f'升变? {move}')
    #piece = stockfish.get_what_is_on_square(move[2:2])?? 
  capt = stockfish.will_move_be_a_capture(move)
  try:
    sq1 = move[:2]
  except:
    print(move)
    #sq1 = move[2:2]?? 
  sq1 = sq1[:1]
  sq2 = move[2:]

现在它将返回f'{sq2}'或f'{sq1}x{sq2}'
<br />
c7或bxc7
<br />
但我相当确定它可能返回=Q

Please note that code translation might not always be perfect due to technical terms and context.

英文:

So I was just messing around with the stockfish library and am converting the moves to a PGN text format and errored parsing the move

Right now every move comes in this format "a1b2" and I'm assuming a promotion would be something like this "c7c8=Q" but I'm not sure as it could be "c8=Q" as well. Here's some of the code

best_w = stockfish.get_top_moves(3)
best_w = best_w[random.randint(0,2)][&#39;Move&#39;]
fgn_w = getfgn(best_w)

best_b = stockfish.get_top_moves(3)
best_b = best_w[random.randint(0,2)][&#39;Move&#39;]
fgn_b = getfgn(best_b)

I didn't have it before but I now have these try statements to print what comes back if it ever happens again

def getfgn(move):
  try:
    piece = stockfish.get_what_is_on_square(move[:2])
  except:
    print(f&#39;Promotion? {move}&#39;)
    #piece = stockfish.get_what_is_on_square(move[2:2])?? 
  capt = stockfish.will_move_be_a_capture(move)
  try:
    sq1 = move[:2]
  except:
    print(move)
    #sq1 = move[2:2]??
  sq1 = sq1[:1]
  sq2 = move[2:]

So now it will return f'{sq2}' or f'{sq1}x{sq2}'
<br />
c7 or bxc7
<br />
But I'm pretty sure it probably returned =Q instead

答案1

得分: 1

The stockfish Python package 与 Stockfish Engine 的一个实例之间使用 UCI Protocol 进行通信,该协议使用长代数标记表示棋步,这意味着晋升会被编码为一个由5个字符组成的序列:前两个字符表示出发方格,接下来两个字符表示目标方格,最后一个字符表示兵晋升后的棋子类型。

这可以通过以下的FEN局面进行测试,其中最佳着法是晋升:

from stockfish import Stockfish

stockfish = Stockfish()
stockfish.set_fen_position("8/1KPk4/8/8/8/8/8/8 w - - 0 1")
print(stockfish.get_best_move())

输出:

c7c8q
英文:

The stockfish Python package communicates with an instance of Stockfish Engine using the UCI Protocol, and the the protocol uses Long Algebraic Notation for moves, which means promotions are encoded as a sequence of 5 characters: two for the source square, two for the destination square, and one for the piece that the pawn is being promoted to.

This can be tested using this FEN position where the best move is to promote:

from stockfish import Stockfish

stockfish = Stockfish()
stockfish.set_fen_position(&quot;8/1KPk4/8/8/8/8/8/8 w - - 0 1&quot;)
print(stockfish.get_best_move())

Output:

c7c8q

huangapple
  • 本文由 发表于 2023年6月1日 02:19:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76376311.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定