Stockfish 每次对于给定的位置都会做相同的动作

发布于 2025-01-13 00:33:25 字数 283 浏览 0 评论 0原文

使用 Stockfish 编写国际象棋程序。对于任何位置,它每次都会给出相同的动作。它甚至以相同的动作打开。

我正在使用 python-chess 库与 stockfish 进行通信,我不确定这是否是问题所在,或者是否是其他问题。

engine = chess.engine.SimpleEngine.popen_uci(
        r"engine/stockfish_14.1_win_x64_popcnt/stockfish_14.1_win_x64_popcnt.exe")

Using stockfish for a chess program. It gives the same moves every time for any position. It even opens with the same moves.

I'm using the python-chess library for communicating with stockfish I'm not sure if that's where the issue lies or if it's something else.

engine = chess.engine.SimpleEngine.popen_uci(
        r"engine/stockfish_14.1_win_x64_popcnt/stockfish_14.1_win_x64_popcnt.exe")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

淑女气质 2025-01-20 00:33:25

Stockfish 会采取它认为在任何特定位置上最好的动作。这就是为什么如果你给它同样的位置并给它同样的思考量,它总是会给你同样的动作。

在引擎对引擎锦标赛中,他们经常根据给定的开局位置进行比赛。因此,给出了前 X 个动作,然后引擎将从那里开始自行运行。这样大多数时候游戏都会有所不同,否则无论玩多少次游戏看起来都一样。

Stockfish plays the move it thinks is best in any given position. That is why it will always give you the same move if you feed it the same position and give it the same amount to think.

In engine vs engine tournaments they often play according to given opening positions. The first X moves are therefore given and then the engines will play on from there by themselves. This way the games will be different most of the times, otherwise the games would look the same no matter how many times they played.

深居我梦 2025-01-20 00:33:25

像 Stockfish 这样的国际象棋引擎会尝试为给定的位置下最好的棋步。引擎找到的走法主要取决于时间限制和搜索线程数量 - 如果这些参数相同,您可以预期返回的最佳走法是相同的 - 特别是当引擎在单个线程上搜索时。

Chess engines like Stockfish try to play the best move for a given position. The move found by an engine depends mainly on time constraints and number of threads searching - if those parameters are the same, you can expect the returned best move to be the same - especially when the engine is searching on a single thread.

反差帅 2025-01-20 00:33:25

关于OP的评论

“玩家在chess.com上对战的国际象棋引擎会下各种动作,尤其是在开局中。我意识到这可能不是引擎本身的内置功能,有没有一个好的方法来实现这一点?”

您可以传递 multipv 选项,例如

variations = engine.analyse(board, chess.engine.Limit(time=0.1), multipv=5)

消除错误(设置例如 thresh = 100 并减少以使引擎发挥更强)

variations = [info for info in variations if
        variations[0]['score'].relative.score() - info['score'].relative.score() < thresh]

并随机选择一个动作

move = random.choice(variations)['pv'][0]

这样您不必费力打开书籍,并且您可以稍微限制引擎的强度:)

好的,我现在要测试它,看看我可以击败多少 thresh 值。 ..

About the OP's comment

" chess engines that players play against like on chess.com play various moves, especially in the opening. I realize that this may not be an inbuilt feature of the engine itself, is there a good way to implement this? "

You could pass multipv option, like

variations = engine.analyse(board, chess.engine.Limit(time=0.1), multipv=5)

maybe eliminate blunders (set e.g. thresh = 100 and decrese to make engine play stronger)

variations = [info for info in variations if
        variations[0]['score'].relative.score() - info['score'].relative.score() < thresh]

and pick a move at random

move = random.choice(variations)['pv'][0]

This way you wouldn't have to mess with opening books and you can throttle the strength of the engine a bit :)

Ok, I'm going to test it now, to see what value of thresh I can beat ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文