{"id":51,"date":"2024-12-19T18:52:10","date_gmt":"2024-12-19T10:52:10","guid":{"rendered":"https:\/\/blog.hcha.site\/?p=51"},"modified":"2026-03-07T14:12:22","modified_gmt":"2026-03-07T06:12:22","slug":"%e4%bd%bf%e7%94%a8%e4%ba%91%e7%ab%af%e6%9c%8d%e5%8a%a1%e5%99%a8%e8%bf%90%e8%a1%8c-stockfish","status":"publish","type":"post","link":"https:\/\/blog.hcha.site\/?p=51","title":{"rendered":"\u4f7f\u7528\u4e91\u7aef\u670d\u52a1\u5668\u8fd0\u884c Stockfish"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">tl;dr<\/h2>\n\n\n\n<p>\u6211\u4f7f\u7528\u4e00\u53f0\u963f\u91cc\u4e91\u62a2\u5360\u5f0f\u5b9e\u4f8b\u8fd0\u884c Stockfish \u56fd\u9645\u8c61\u68cb\u5f15\u64ce\uff0c\u5e76\u5728\u672c\u5730GUI\u4e2d\u5b9e\u65f6\u67e5\u770b\u7ed3\u679c\u3002\u8fd9\u4e00\u5b9e\u4f8b\u53ef\u4ee5\u4e0e\u4efb\u4f55\u5141\u8bb8\u81ea\u7531\u914d\u7f6e\u56fd\u9645\u8c61\u68cb\u5f15\u64ce\u7684GUI\uff08\u4f8b\u5982<code>en-croissant<\/code>\u6216\u8005<code>Chessbase<\/code>\uff09\u4ea4\u4e92\u3002\u5728\u6d4b\u8bd5\u4f7f\u7528\u7684\u5b9e\u4f8b\u89c4\u683c\u4e2d\uff0c\u6027\u80fd\u53ef\u8fbe8\u5343\u4e07\u8282\u70b9\u6bcf\u79d2\uff0880MNodes\/s\uff09\uff0c\u6210\u672c\u5728\u622a\u7a3f\u65f6\u7ea6\u4e3a3.2\u5143\/\u5c0f\u65f6\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u80cc\u666f<\/h2>\n\n\n\n<p>\u6211\u5e0c\u671b\u4f7f\u7528\u56fd\u9645\u8c61\u68cb\u5f15\u64ce\u5b9e\u65f6\u65c1\u89c2 2024 FIDE World Chess Championship \u7684\u6bd4\u8d5b\uff0c\u5e76\u5728\u8d5b\u540e\u7acb\u523b\u751f\u6210\u4e00\u4efd\u5f15\u64ce\u5206\u6790\u62a5\u544a\u3002<\/p>\n\n\n\n<p>\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u5982\u679c\u60f3\u8981\u4f7f\u7528\u4e00\u4e2a\u56fd\u9645\u8c61\u68cb\u5f15\u64ce\uff0c\u6211\u4f1a\u5728\u672c\u5730\u8fd0\u884c\u4e00\u4e2a Stockfish \u5b9e\u4f8b\u3002\u7136\u800c\uff0c\u6211\u5f88\u5feb\u53d1\u73b0\u672c\u5730 Stockfish \u4f1a\u5360\u7528\u5927\u91cf\u7684CPU\u8ba1\u7b97\u8d44\u6e90\u548c\u5185\u5b58\u8d44\u6e90\uff0c\u5bfc\u81f4\u7cfb\u7edf\u5361\u987f\uff08\u8fd9\u4e00\u73b0\u8c61\u5728\u5c1d\u8bd5\u4f7f\u7528<code>Chessbase<\/code>\u5f00\u542f\u652f\u62db\u5668\u65f6\uff0c\u5feb\u901f\u79fb\u52a8\u68cb\u5b50\u65f6\u5c24\u4e3a\u660e\u663e\uff09\u3002<\/p>\n\n\n\n<p>\u53e6\u5916\uff0c\u672c\u5730\u8fd0\u884c\u7684 Stockfish \u5b9e\u4f8b\u7684\u641c\u7d22\u901f\u5ea6\u4e5f\u5f88\u6162\uff0c\u5bfc\u81f4\u5f15\u64ce\u5e76\u4e0d\u80fd\u786e\u5207\u5730\u8bc4\u4f30\u5f53\u524d\u7684\u5c40\u9762\u3002<\/p>\n\n\n\n<p>\u5728 2024 FIDE World Chess Championship \u7684\u4e00\u4e2a\u6708\u6bd4\u8d5b\u5185\uff0c\u6211\u6700\u591a\u53ea\u670915\u5929\uff0c\u6bcf\u5929\u6700\u591a5\u5c0f\u65f6\u5de6\u53f3\u7684\u65f6\u95f4\u9700\u8981\u4f7f\u7528\u8fd9\u53f0\u670d\u52a1\u5668\uff0c\u53e6\u5916\uff0c\u7531\u4e8e Stockfish \u7684\u8ba1\u7b97\u662f\u65e0\u72b6\u6001\u7684\uff08\u9664\u4e86\u54c8\u5e0c\u8868\uff0c\u4f46\u8fd9\u65e0\u5173\u7d27\u8981\uff09\uff0c\u6211\u4e5f\u80fd\u63a5\u53d7\u7531\u4e8e\u4ef7\u683c\u6ce2\u52a8\u5bfc\u81f4\u7684\u8ba1\u7b97\u8d44\u6e90\u7a81\u7136\u4e2d\u65ad\u3002<\/p>\n\n\n\n<p>\u6240\u4ee5\uff0c\u6211\u9009\u62e9\u4f7f\u7528\u963f\u91cc\u4e91\u7684\u62a2\u5360\u5f0f\u5b9e\u4f8b\u8fd0\u884c\u6211\u7684 Stockfish \u5b9e\u4f8b\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u542f\u52a8\u4e91\u670d\u52a1\u5668\u5b9e\u4f8b<\/h2>\n\n\n\n<p>\u767b\u5f55<a href=\"https:\/\/ecs.console.aliyun.com\/home#\/\">\u4e91\u670d\u52a1\u5668\u7ba1\u7406\u63a7\u5236\u53f0<\/a>\uff0c\u5e76\u521b\u5efa\u4e00\u4e2a\u5b9e\u4f8b\u3002<\/p>\n\n\n\n<p>\u5bf9\u4e8e\u6211\u7684\u6d4b\u8bd5\uff0c\u6211\u9009\u62e9\u534e\u53175\u533a\uff08\u547c\u548c\u6d69\u7279\uff09\u53ef\u7528\u533aA\u7684 \u5bc6\u96c6\u8ba1\u7b97\u578b ic5.16xlarge \u5b9e\u4f8b\uff0cCPU \/ \u5185\u5b58\u6bd4\u4e3a 1:1\uff0c\u62e5\u6709 64\u4e2a Intel Skylake Xeon Platinum 8163 2.5GHz \u5904\u7406\u5668\u6838\u5fc3\u3002<\/p>\n\n\n\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\u963f\u91cc\u4e91\u5728<a href=\"https:\/\/help.aliyun.com\/zh\/ecs\/user-guide\/overview-of-instance-families\">\u5b9e\u4f8b\u6307\u6807<\/a>\u4e2d\u5e76\u4e0d\u5efa\u8bae\u4f7f\u7528 \u5bc6\u96c6\u8ba1\u7b97\u578b ic5\uff0c\u4f46\u7531\u4e8e\u76f8\u6bd4\u5176\u4ed6 HPC \u5e94\u7528\u573a\u666f\uff0cStockfish \u5bf9\u5185\u5b58\u7684\u9700\u6c42\u975e\u5e38\u5c0f\uff0cStockfish 17 \u6700\u591a\u652f\u63011024\u4e2a\u7ebf\u7a0b\uff0c\u4f46\u662f\u54c8\u5e0c\u8868\u4e00\u822c\u4e0d\u4f1a\u8d85\u8fc78G\uff0c\u800c ic5 \u662f\u552f\u4e00\u4e00\u4e2aCPU \/ \u5185\u5b58\u6bd4\u4e3a1:1\u7684\u5b9e\u4f8b\uff0c\u5176\u4f59\u7684\u5b9e\u4f8b\u90fd\u6216\u591a\u6216\u5c11\u6709\u66f4\u591a\u7684\u5185\u5b58\u88ab\u6d6a\u8d39\u4e86\u3002<\/p>\n\n\n\n<p>\u53e6\u5916\uff0c\u4f7f\u7528\u62a2\u5360\u5f0f\u5b9e\u4f8b\u8981\u6c42\u963f\u91cc\u4e91\u8d26\u6237\u4e2d\u81f3\u5c11\u62e5\u6709100\u5143\u7684\u4f59\u989d\uff0c\u5e76\u4e14\u5728\u521b\u5efa\u62a2\u5360\u5f0f\u5b9e\u4f8b\u540e\u4f1a\u51bb\u7ed3\u8d26\u6237\u7684100\u5143\u4f59\u989d\uff0c\u8fd9\u4e00\u51bb\u7ed3\u4f1a\u5728\u6700\u540e\u4e00\u4e2a\u62a2\u5360\u5f0f\u5b9e\u4f8b\u91ca\u653e\u540e\u768424\u5c0f\u65f6\u89e3\u51bb\u3002<\/p>\n\n\n\n<p>Stockfish \u5bf9\u5b58\u50a8\u6027\u80fd\u8981\u6c42\u5f88\u4f4e\uff0c\u6240\u4ee5\u786c\u76d8\u9009\u62e9\u9ad8\u6548\u4e91\u76d8 20GB\u3002<\/p>\n\n\n\n<p>\u9664\u4e86\u4e0b\u8f7d Stockfish \u548c\u5728\u672c\u5730\u548c\u4e91\u7aef\u4e4b\u95f4\u4f20\u9012UCI\u6307\u4ee4\u548c\u5f15\u64ce\u7ed3\u8bba\u4ee5\u5916\uff0c\u8fd9\u53f0\u5b9e\u4f8b\u51e0\u4e4e\u4e0d\u4f1a\u4f7f\u7528\u522b\u7684\u6d41\u91cf\uff0c\u6240\u4ee5\u6211\u4f7f\u7528\u6309\u91cf\u4ed8\u8d39\uff08CDT\uff09\uff0c\u5cf0\u503c\u5e26\u5bbd100Mbps\u3002<\/p>\n\n\n\n<p>\u7cfb\u7edf\u9009\u62e9 Ubuntu 24.04\uff0c\u5e76\u4f7f\u7528\u5bc6\u94a5\u5bf9\u767b\u5f55\u3002\u4f7f\u7528\u5bc6\u94a5\u5bf9\u767b\u5f55\u5bf9\u540e\u7eed\u7684\u64cd\u4f5c\u975e\u5e38\u91cd\u8981\uff0c\u786e\u4fdd\u4f60\u914d\u7f6e\u4f7f\u7528\u4e86\u5bc6\u94a5\u5bf9\u767b\u5f55\u3002<\/p>\n\n\n\n<p>\u521b\u5efa\u5b9e\u4f8b\u540e\uff0c\u590d\u5236\u5bf9\u5e94\u7684\u516c\u7f51IP\u5730\u5740\uff0c\u7136\u540e\u5728\u7ec8\u7aef\u4e2d\u6267\u884c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ssh -i \"\u79c1\u94a5\u6587\u4ef6\u8def\u5f84\" root@\u516c\u7f51IP\u5730\u5740<\/code><\/pre>\n\n\n\n<p>\u9996\u6b21\u6267\u884c\u8fd9\u4e00\u547d\u4ee4\u65f6\uff0c\u4f60\u53ef\u80fd\u4f1a\u88ab\u63d0\u793a\u786e\u8ba4\u670d\u52a1\u5668\u7684\u6307\u7eb9\uff0c\u6b64\u65f6\uff0c\u8f93\u5165<code>yes<\/code>\u5e76\u56de\u8f66\u5373\u53ef\u7ee7\u7eed\u8fde\u63a5\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u51fa\u73b0\u4e86\u7c7b\u4f3c<code>root@Stockfish:~#<\/code>\u7684\u63d0\u793a\u7b26\uff0c\u8bf4\u660e\u4f60\u5df2\u7ecf\u6210\u529f\u8bbf\u95ee\u4e86\u4f60\u7684\u4e91\u670d\u52a1\u5668\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u51c6\u5907\u73af\u5883<\/h2>\n\n\n\n<p>\u5728root\u8d26\u6237\u4e0b\u6267\u884c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wget -O stockfish.tar.gz https:\/\/github.com\/official-stockfish\/Stockfish\/releases\/latest\/download\/stockfish-ubuntu-x86-64-avx2.tar &amp;&amp; tar -xzf stockfish.tar.gz -C \/root\/ &amp;&amp; rm stockfish.tar.gz &amp;&amp; mv \/root\/stockfish-ubuntu-x86-64-avx2 \/root\/stockfish 2&gt;\/dev\/null<\/code><\/pre>\n\n\n\n<p>\u5982\u679cwget\u62c9\u53d6\u901f\u5ea6\u8fc7\u6162\uff0c\u4f60\u53ef\u4ee5\u81ea\u884c\u914d\u7f6eGithub\u955c\u50cf\u6216\u8005\u624b\u52a8\u4e0b\u8f7d\u5230\u672c\u5730\u7136\u540e\u4e0a\u4f20\u5230\u670d\u52a1\u5668\u4ee5\u7ee7\u7eed\u64cd\u4f5c<\/p>\n\n\n\n<p>\u4f60\u5e94\u8be5\u80fd\u5728<code>\/root\/<\/code>\u4e0b\u53d1\u73b0\u4e00\u4e2a<code>stockfish<\/code>\u6587\u4ef6\u5939\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@Stockfish:~# ls\nstockfish\nroot@Stockfish:~# ls stockfish\/\n AUTHORS   CITATION.cff   CONTRIBUTING.md   Copying.txt   README.md   src   stockfish  'Top CPU Contributors.txt'   wiki<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e91\u670d\u52a1\u5668\u672c\u5730\u6d4b\u8bd5<\/h2>\n\n\n\n<p>\u6267\u884c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/root\/stockfish\/stockfish <\/code><\/pre>\n\n\n\n<p>\u5982\u679c\u4e00\u5207\u987a\u5229\uff0c\u4f60\u80fd\u770b\u5230\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@Stockfish:~# \/root\/stockfish\/stockfish \nStockfish 17 by the Stockfish developers (see AUTHORS file)<\/code><\/pre>\n\n\n\n<p>\u7136\u540e\uff0c\u4f7f\u7528UCI\u547d\u4ee4\u914d\u7f6e\u5f15\u64ce\u6267\u884c\u7ebf\u7a0b\u6570\uff0c\u8fd9\u4e2a\u6570\u6700\u597d\u662f3\u500d\u4f60\u7684CPU\u6838\u5fc3\u6570\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>setoption name Threads value 192<\/code><\/pre>\n\n\n\n<p>\u5e94\u8be5\u80fd\u770b\u5230\u8fd4\u56de\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>info string Using 192 threads<\/code><\/pre>\n\n\n\n<p>\u786e\u8ba4\u5f15\u64ce\u5df2\u7ecf\u51c6\u5907\u597d\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>uci<\/code><\/pre>\n\n\n\n<p>\u5982\u679c\u770b\u5230<code>uciok<\/code>\uff0c\u5c31\u8868\u660e\u5f15\u64ce\u5df2\u7ecf\u51c6\u5907\u597d\u8fd0\u884c\u4e86\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>id name Stockfish 17\nid author the Stockfish developers (see AUTHORS file)\n\noption name Debug Log File type string default &lt;empty&gt;\noption name NumaPolicy type string default auto\noption name Threads type spin default 1 min 1 max 1024\noption name Hash type spin default 16 min 1 max 33554432\noption name Clear Hash type button\noption name Ponder type check default false\noption name MultiPV type spin default 1 min 1 max 256\noption name Skill Level type spin default 20 min 0 max 20\noption name Move Overhead type spin default 10 min 0 max 5000\noption name nodestime type spin default 0 min 0 max 10000\noption name UCI_Chess960 type check default false\noption name UCI_LimitStrength type check default false\noption name UCI_Elo type spin default 1320 min 1320 max 3190\noption name UCI_ShowWDL type check default false\noption name SyzygyPath type string default &lt;empty&gt;\noption name SyzygyProbeDepth type spin default 1 min 1 max 100\noption name Syzygy50MoveRule type check default true\noption name SyzygyProbeLimit type spin default 7 min 0 max 7\noption name EvalFile type string default nn-1111cefa1111.nnue\noption name EvalFileSmall type string default nn-37f18f62d772.nnue\nuciok<\/code><\/pre>\n\n\n\n<p>\u5f00\u59cb\u8ba1\u7b97\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>go infinite<\/code><\/pre>\n\n\n\n<p>\u4f60\u4f1a\u770b\u5230\u5f15\u64ce\u7684\u8ba1\u7b97\u7ed3\u8bba\u3002<\/p>\n\n\n\n<p>\u505c\u6b62\u8ba1\u7b97\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>stop<\/code><\/pre>\n\n\n\n<p>\u5f15\u64ce\u4f1a\u505c\u6b62\u8ba1\u7b97\u5e76\u7ed9\u51fa\u5f53\u524d\u7684\u6700\u4f73\u7ed3\u8bba (1. e4)\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>bestmove e2e4 ponder e7e5<\/code><\/pre>\n\n\n\n<p>\u4f7f\u7528Ctrl+Z\u7ed3\u675fStockfish\u8fd0\u884c\u8fdb\u7a0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>^Z\n&#91;1]+  Stopped                 stockfish\/stockfish\nroot@Stockfish:~# <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u8fdc\u7a0b\u901a\u4fe1\u8f6f\u4ef6\u5236\u4f5c\u539f\u7406<\/h2>\n\n\n\n<p>\u539f\u7406\u4e0a\uff0c\u53ea\u8981\u6267\u884c\u4ee5\u4e0b\u6307\u4ee4\uff0c\u5c31\u80fd\u83b7\u5f97\u4e00\u4e2a\u8fdc\u7a0b\u7684 Stockfish UCI \u754c\u9762\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ssh -i \"\u79c1\u94a5\u6587\u4ef6\u8def\u5f84\" root@\u516c\u7f51IP\u5730\u5740 \/root\/stockfish\/stockfish<\/code><\/pre>\n\n\n\n<p>\u4f46\u662f\uff0c\u8fd9\u4f1a\u6709\u4ee5\u4e0b\u95ee\u9898\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u5927\u90e8\u5206\u7684\u56fd\u9645\u8c61\u68cbGUI\u90fd\u53ea\u5141\u8bb8\u6307\u5b9a\u4e00\u4e2a\u4e0d\u4f20\u53c2\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff08.exe\uff09\u4f5c\u4e3a\u5f15\u64ce\u6267\u884c\u6587\u4ef6\u3002<\/li>\n\n\n\n<li>\u5f88\u591a\u56fd\u9645\u8c61\u68cbGUI\u65e0\u6cd5\u6307\u5b9a\u592a\u591a\u7ebf\u7a0b\u6570\uff08\u4f8b\u5982\u5bf9\u4e8e<code>Chessbase<\/code>\uff0c\u65e0\u6cd5\u6307\u5b9a\u8d85\u8fc716\u7684\u7ebf\u7a0b\u6570\uff09\u3002<\/li>\n\n\n\n<li>\u5bf9\u4e8e<code>Chessbase 17<\/code>\u53ca\u4ee5\u4e0a\u7248\u672c\uff0c\u5b83\u7684Buddy Engine\u5fc5\u987b\u540c\u6837\u4f7f\u7528\u9ed8\u8ba4\u652f\u62db\u5668\uff0c\u5728\u8fd9\u65f6\uff0c\u4f1a\u6709\u4e24\u4e2a\u5f15\u64ce\u5b9e\u4f8b\u540c\u65f6\u6267\u884c\uff0c\u6211\u4eec\u4e0d\u5e0c\u671b\u5c06\u4e91\u670d\u52a1\u5668\u7684\u8d44\u6e90\u5747\u5206\u5728\u8fd9\u4e24\u4e2a\u5b9e\u4f8b\u4e0a\uff0c\u6211\u4eec\u5e0c\u671b\u80fd\u4e3a\u4e3b\u5f15\u64ce\u63d0\u4f9b\u5c3d\u53ef\u80fd\u591a\u7684\u7b97\u529b\u3002<\/li>\n<\/ol>\n\n\n\n<p>\u6240\u4ee5\u6211\u4eec\u9700\u8981\u4e00\u4e9b\u65b9\u6cd5\u6765\u989d\u5916\u914d\u7f6e\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7f16\u5199\u8fdc\u7a0b\u901a\u4fe1\u8f6f\u4ef6<\/h2>\n\n\n\n<p>\u53ef\u4ee5\u4f7f\u7528Python\u5efa\u7acb\u4e00\u4e2a\u5bf9\u6307\u5b9aSSH\u6307\u4ee4\u7684\u53cc\u5411\u901a\u4fe1\uff0c\u7136\u540e\u6253\u5305\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n\n\n\n<p>\u9996\u5148\uff0c\u6307\u5b9aSSH\u547d\u4ee4\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SSH_COMMAND = &#91;\"ssh\", \"-i \u79c1\u94a5\u6587\u4ef6\u8def\u5f84\", \"root@\u516c\u7f51IP\u5730\u5740\", \"\/root\/stockfish\/stockfish\"]<\/code><\/pre>\n\n\n\n<p>\u521b\u5efa\u4e00\u4e2aSSH\u5b50\u8fdb\u7a0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>try:\n    # \u542f\u52a8SSH\u8fdb\u7a0b\n    process = subprocess.Popen(\n        SSH_COMMAND,\n        stdin=subprocess.PIPE,   # \u6807\u51c6\u8f93\u5165\n        stdout=subprocess.PIPE,  # \u6807\u51c6\u8f93\u51fa\n        stderr=subprocess.PIPE,  # \u9519\u8bef\u8f93\u51fa\n        text=True,               # \u6587\u672c\u6a21\u5f0f\n        bufsize=1                # \u884c\u7f13\u51b2\n    )\nexcept Exception as e:\n    print(f\"\u542f\u52a8Stockfish\u8fdb\u7a0b\u5931\u8d25: {e}\", file=sys.stderr)\n    sys.exit(1)<\/code><\/pre>\n\n\n\n<p>\u73b0\u5728\uff0c\u6211\u4eec\u4eceSTDIN\u5411\u5f15\u64ce\u5199\u5165\u547d\u4ee4\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def write_to_engine(process, command):\n    \"\"\"\u5411\u5f15\u64ce\u5199\u5165\u547d\u4ee4\"\"\"\n    try:\n        process.stdin.write(f\"{command}\\n\")\n        process.stdin.flush()\n    except Exception as e:\n        print(f\"\u5199\u5165\u5f15\u64ce\u547d\u4ee4\u5931\u8d25: {e}\", file=sys.stderr)<\/code><\/pre>\n\n\n\n<p>\u6211\u4eec\u4eceSTDOUT\u8bfb\u53d6\u5f15\u64ce\u7684\u8f93\u51fa\uff0c\u5e76\u6253\u5370\u51fa\u6765\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def read_from_engine(process):\n    \"\"\"\u8bfb\u53d6\u5f15\u64ce\u8f93\u51fa\"\"\"\n    try:\n        for line in process.stdout:\n            line = line.strip()\n            if line:\n                print(line, file=sys.stderr)\n    except Exception as e:\n        print(f\"\u8bfb\u53d6\u5f15\u64ce\u8f93\u51fa\u9519\u8bef: {e}\", file=sys.stderr)<\/code><\/pre>\n\n\n\n<p>\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u5355\u72ec\u7684\u7ebf\u7a0b\u6765\u5c06\u5f15\u64ce\u8f93\u51fa\u6253\u5370\u51fa\u6765\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>reader_thread = threading.Thread(target=read_from_engine, args=(process,), daemon=True)\nreader_thread.start()<\/code><\/pre>\n\n\n\n<p>\u5728\u4e3b\u5faa\u73af\u4e2d\uff0c\u6211\u4eec\u4e0d\u65ad\u8bfb\u53d6\u7528\u6237\u7684\u8f93\u5165\uff0c\u5e76\u53d1\u9001\u7ed9\u5f15\u64ce\uff0c\u5f15\u64ce\u7684\u8f93\u51fa\u5c06\u4f1a\u5b9e\u65f6\u6253\u5370\u51fa\u6765\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>while True:\n    command = input()\n    if command.lower() == \"quit\":\n        write_to_engine(process, \"quit\")\n        break\n    write_to_engine(process, command)<\/code><\/pre>\n\n\n\n<p>\u5b8c\u6574\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import subprocess\nimport sys\nimport threading\n\n# SSH\u8fde\u63a5\u914d\u7f6e\nSSH_COMMAND = &#91;\"ssh\", \"-i \u79c1\u94a5\u6587\u4ef6\u8def\u5f84\", \"root@\u516c\u7f51IP\u5730\u5740\", \"\/root\/stockfish\/stockfish\"]\n\ndef write_to_engine(process, command):\n    \"\"\"\u5411\u5f15\u64ce\u5199\u5165\u547d\u4ee4\"\"\"\n    try:\n        process.stdin.write(f\"{command}\\n\")\n        process.stdin.flush()\n    except Exception as e:\n        print(f\"\u5199\u5165\u5f15\u64ce\u547d\u4ee4\u5931\u8d25: {e}\", file=sys.stderr)\n\ndef read_from_engine(process):\n    \"\"\"\u8bfb\u53d6\u5f15\u64ce\u8f93\u51fa\"\"\"\n    try:\n        for line in process.stdout:\n            line = line.strip()\n            if line:\n                print(line, file=sys.stderr)\n    except Exception as e:\n        print(f\"\u8bfb\u53d6\u5f15\u64ce\u8f93\u51fa\u9519\u8bef: {e}\", file=sys.stderr)\n\ndef main():\n    try:\n        # \u542f\u52a8SSH\u8fdb\u7a0b\n        process = subprocess.Popen(\n            SSH_COMMAND,\n            stdin=subprocess.PIPE,\n            stdout=subprocess.PIPE,\n            stderr=subprocess.PIPE,\n            text=True,\n            bufsize=1\n        )\n    except Exception as e:\n        print(f\"\u542f\u52a8Stockfish\u8fdb\u7a0b\u5931\u8d25: {e}\", file=sys.stderr)\n        sys.exit(1)\n\n    # \u521b\u5efa\u8bfb\u53d6\u7ebf\u7a0b\n    reader_thread = threading.Thread(target=read_from_engine, args=(process,), daemon=True)\n    reader_thread.start()\n\n    # \u4e3b\u547d\u4ee4\u5904\u7406\u5faa\u73af\n    try:\n        while True:\n            command = input()\n            if command.lower() == \"quit\":\n                write_to_engine(process, \"quit\")\n                break\n            write_to_engine(process, command)\n    except EOFError:\n        write_to_engine(process, \"quit\")\n    except Exception as e:\n        print(f\"\u5904\u7406\u547d\u4ee4\u65f6\u53d1\u751f\u9519\u8bef: {e}\", file=sys.stderr)\n        write_to_engine(process, \"quit\")\n\n    # \u4e3b\u5faa\u73af\u7ed3\u675f\uff0c\u5c1d\u8bd5\u5173\u95ed\u8fdb\u7a0b\n    try:\n        process.terminate()\n    except Exception:\n        pass\n\n    # \u7b49\u5f85\u8bfb\u53d6\u7ebf\u7a0b\u7ed3\u675f\n    reader_thread.join(timeout=1)\n\nif __name__ == \"__main__\":\n    main()<\/code><\/pre>\n\n\n\n<p>\u5c06\u5176\u4fdd\u5b58\u4e3a<code>app.py<\/code>\uff0c\u7136\u540e\u51c6\u5907\u5c06\u5176\u6253\u5305\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u6253\u5305\u4e3a\u53ef\u6267\u884c\u6587\u4ef6<\/h2>\n\n\n\n<p>\u7f16\u5199\u4e00\u4e2a\u6267\u884c\u5668\uff0c\u5728\u811a\u672c\u76ee\u5f55\u4e0b\u65b0\u5efa\u4e00\u4e2arun.py\u6587\u4ef6\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import subprocess\n\ndef main():\n    subprocess.run(\"python app.py 2&gt;&amp;1\", shell=True)\n\nif __name__ == \"__main__\":\n    main()<\/code><\/pre>\n\n\n\n<p>\u7136\u540e\uff0c\u5728\u811a\u672c\u76ee\u5f55\u4e0b\u6267\u884c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install pyinstaller\npyinstaller --onefile --clean --noconfirm --distpath .\/ --name Stockfish run.py\ndel *.spec\nrmdir \/s \/q build<\/code><\/pre>\n\n\n\n<p>\u4f60\u4f1a\u5728\u811a\u672c\u76ee\u5f55\u4e0b\u53d1\u73b0\u4e00\u4e2aStockfish.exe\uff0c\u5728\u56fd\u9645\u8c61\u68cbGUI\u4e2d\u6307\u5b9a\u8fd9\u4e2a\u6587\u4ef6\u4f5c\u4e3a\u56fd\u9645\u8c61\u68cb\u5f15\u64ce\uff0c\u5373\u53ef\u5f00\u59cb\u4f7f\u7528\u8fdc\u7a0b\u670d\u52a1\u5668\u8fd0\u884c Stockfish\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u8fdb\u9636-\u5145\u5206\u5229\u7528\u670d\u52a1\u5668\u8d44\u6e90<\/h2>\n\n\n\n<p>\u5f53\u524d\u867d\u7136\u5df2\u7ecf\u80fd\u591f\u4f5c\u4e3a\u4e00\u4e2a\u5408\u683c\u7684\u56fd\u9645\u8c61\u68cb\u8fdc\u7a0b\u5f15\u64ce\u4f7f\u7528\uff0c\u7136\u800c\uff0c\u8fd9\u4ecd\u672a\u89e3\u51b3\u95ee\u98982\u548c3\u3002<\/p>\n\n\n\n<p>\u56fd\u9645\u8c61\u68cbGUI\u4e00\u822c\u4e0d\u5141\u8bb8\u914d\u7f6e\u8d85\u8fc716\u4e2a\u7ebf\u7a0b\uff0c\u5373\u4f7f\u53ef\u4ee5\uff0c\u4e5f\u6709\u53ef\u80fd\u5f88\u5feb\u4f1a\u88ab\u8c03\u56de\u6765\u3002<\/p>\n\n\n\n<p>\u7136\u800c\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539\u5b9e\u9645\u5411\u5f15\u64ce\u53d1\u9001\u7684\u7ebf\u7a0b\u6570\uff0c\u4ee5\u8fbe\u5230\u201d\u867d\u7136GUI\u53d1\u9001\u7684\u7ebf\u7a0b\u6570\u5f88\u5c0f\uff0c\u4f46\u5b9e\u9645\u4e0a\u6267\u884c\u7684\u7ebf\u7a0b\u6570\u5f88\u591a\u201c\u7684\u6548\u679c\u3002<\/p>\n\n\n\n<p>\u4fee\u6539<code>app.py<\/code>\u7684\u4e3b\u5faa\u73af\u90e8\u5206\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>command = input()\nif command.lower() == \"quit\":\n    write_to_engine(process, \"quit\")\n    break\nwrite_to_engine(process, command)<\/code><\/pre>\n\n\n\n<p>\u56fd\u9645\u8c61\u68cbGUI\u8c03\u6574\u5f15\u64ce\u7ebf\u7a0b\u6570\u7684\u6307\u4ee4\u662f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>setoption name Threads value \u7ebf\u7a0b\u6570<\/code><\/pre>\n\n\n\n<p>\u6211\u4eec\u8bc6\u522b\u8fd9\u4e2a\u6307\u4ee4\u7279\u5f81\uff0c\u5982\u679c\u56fd\u9645\u8c61\u68cbGUI\u5c1d\u8bd5\u8c03\u6574\u5f15\u64ce\u7ebf\u7a0b\u6570\uff0c\u6211\u4eec\u5411\u5f15\u64ce\u5b9e\u9645\u53d1\u9001\u4e00\u4e2a\u66f4\u5927\u7684\u503c\uff08\u4f8b\u598264\u76843\u500d\uff0c192\uff09\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if command.lower() == \"quit\":\n    write_to_engine(process, \"quit\")\n    break\nelif command.startswith(\"setoption name Threads value \"):\n    write_to_engine(process, \"setoption name Threads value 192\")\nelse:\n    write_to_engine(process, command)<\/code><\/pre>\n\n\n\n<p>\u8fd9\u4f1a\u5bfc\u81f4\u5728<code>Chessbase 17<\/code>\u4e2d\uff0cBuddy Engine\u8ddf\u4e3b\u5f15\u64ce\u5360\u636e\u540c\u6837\u7684\u8d44\u6e90\uff0c\u8fd9\u5e76\u4e0d\u7406\u60f3\uff0c\u6211\u4eec\u5e0c\u671b\u4e3b\u5f15\u64ce\u5360\u7528\u5c3d\u53ef\u80fd\u591a\u7684\u8d44\u6e90\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u8fdb\u4e00\u6b65\u4fee\u6539\u4ee3\u7801\uff0c\u8bc6\u522b\u56fd\u9645\u8c61\u68cbGUI\u5c1d\u8bd5\u8c03\u6574\u7684\u7ebf\u7a0b\u6570\uff0c\u5982\u679c\u8fd9\u4e2a\u7ebf\u7a0b\u6570\u5927\u4e8e10\uff08Buddy Engine\u5360\u7528\u7684\u7ebf\u7a0b\u6570\u4e00\u822c\u4f4e\u4e8e\u8fd9\u4e2a\u503c\uff0c\u57281-7\u5de6\u53f3\uff09\uff0c\u6211\u4eec\u624d\u5411\u5f15\u64ce\u53d1\u9001\u66f4\u5927\u7684\u503c\uff0c\u5426\u5219\uff0c\u5c06\u8c03\u6574\u6307\u4ee4\u539f\u6837\u53d1\u9001\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if command.lower() == \"quit\":\n    write_to_engine(process, \"quit\")\n    break\nelif command.startswith(\"setoption name Threads value \"):\n    threads_value = int(command.split(\" \")&#91;-1])\n    if threads_value &gt; 10:\n        write_to_engine(process, \"setoption name Threads value 192\")\n    else:\n        write_to_engine(process, command)\nelse:\n    write_to_engine(process, command)<\/code><\/pre>\n\n\n\n<p>\u5b8c\u6574\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import subprocess\nimport sys\nimport threading\n\n# SSH\u8fde\u63a5\u914d\u7f6e\nSSH_COMMAND = &#91;\"ssh\", \"-i \u79c1\u94a5\u6587\u4ef6\u8def\u5f84\", \"root@\u516c\u7f51IP\u5730\u5740\", \"\/root\/stockfish\/stockfish\"]\ndef write_to_engine(process, command):\n    \"\"\"\u5411\u5f15\u64ce\u5199\u5165\u547d\u4ee4\"\"\"\n    try:\n        process.stdin.write(f\"{command}\\n\")\n        process.stdin.flush()\n    except Exception as e:\n        print(f\"\u5199\u5165\u5f15\u64ce\u547d\u4ee4\u5931\u8d25: {e}\", file=sys.stderr)\n\ndef read_from_engine(process):\n    \"\"\"\u8bfb\u53d6\u5f15\u64ce\u8f93\u51fa\"\"\"\n    try:\n        for line in process.stdout:\n            line = line.strip()\n            if line:\n                print(line, file=sys.stderr)\n    except Exception as e:\n        print(f\"\u8bfb\u53d6\u5f15\u64ce\u8f93\u51fa\u9519\u8bef: {e}\", file=sys.stderr)\n\ndef main():\n    try:\n        # \u542f\u52a8SSH\u8fdb\u7a0b\n        process = subprocess.Popen(\n            SSH_COMMAND,\n            stdin=subprocess.PIPE,\n            stdout=subprocess.PIPE,\n            stderr=subprocess.PIPE,\n            text=True,\n            bufsize=1\n        )\n    except Exception as e:\n        print(f\"\u542f\u52a8Stockfish\u8fdb\u7a0b\u5931\u8d25: {e}\", file=sys.stderr)\n        sys.exit(1)\n\n    # \u521b\u5efa\u8bfb\u53d6\u7ebf\u7a0b\n    reader_thread = threading.Thread(target=read_from_engine, args=(process,), daemon=True)\n    reader_thread.start()\n\n    # \u4e3b\u547d\u4ee4\u5904\u7406\u5faa\u73af\n    try:\n        while True:\n            command = input()\n            if command.lower() == \"quit\":\n                write_to_engine(process, \"quit\")\n                break\n            elif command.startswith(\"setoption name Threads value \"):\n                threads_value = int(command.split(\" \")&#91;-1])\n                if threads_value &gt; 10:\n                    write_to_engine(process, \"setoption name Threads value 192\")\n                else:\n                    write_to_engine(process, command)\n            else:\n                write_to_engine(process, command)\n    except EOFError:\n        write_to_engine(process, \"quit\")\n    except Exception as e:\n        print(f\"\u5904\u7406\u547d\u4ee4\u65f6\u53d1\u751f\u9519\u8bef: {e}\", file=sys.stderr)\n        write_to_engine(process, \"quit\")\n\n    # \u5c1d\u8bd5\u5173\u95ed\u8fdb\u7a0b\n    try:\n        process.terminate()\n    except Exception:\n        pass\n\n    # \u7b49\u5f85\u8bfb\u53d6\u7ebf\u7a0b\u7ed3\u675f\n    reader_thread.join(timeout=1)\n\nif __name__ == \"__main__\":\n    main()\n<\/code><\/pre>\n\n\n\n<p>\u7531\u4e8e\u6211\u4eec\u6253\u5305\u7684\u53ef\u6267\u884c\u7a0b\u5e8f\u5b9e\u9645\u4e0a\u662f\u4e00\u4e2a\u6267\u884capp.py\u7684\u6267\u884c\u5668\uff0c\u4efb\u4f55\u5bf9<code>app.py<\/code>\u7684\u66f4\u6539\u90fd\u4e0d\u9700\u8981\u91cd\u65b0\u7f16\u8bd1\u8fd9\u4e2a\u6267\u884c\u5668\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>tl;dr \u6211\u4f7f\u7528\u4e00\u53f0\u963f\u91cc\u4e91\u62a2\u5360\u5f0f\u5b9e\u4f8b\u8fd0\u884c Stockfish \u56fd\u9645\u8c61\u68cb\u5f15\u64ce\uff0c\u5e76\u5728\u672c\u5730GUI\u4e2d\u5b9e\u65f6\u67e5\u770b\u7ed3\u679c\u3002\u8fd9 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,4,5],"tags":[10,11,15,17,22],"class_list":["post-51","post","type-post","status-publish","format-standard","hentry","category-ubuntu","category-4","category-5","tag-ubuntu","tag-vps","tag-15","tag-17","tag-22"],"_links":{"self":[{"href":"https:\/\/blog.hcha.site\/index.php?rest_route=\/wp\/v2\/posts\/51","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.hcha.site\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.hcha.site\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.hcha.site\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.hcha.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=51"}],"version-history":[{"count":1,"href":"https:\/\/blog.hcha.site\/index.php?rest_route=\/wp\/v2\/posts\/51\/revisions"}],"predecessor-version":[{"id":451,"href":"https:\/\/blog.hcha.site\/index.php?rest_route=\/wp\/v2\/posts\/51\/revisions\/451"}],"wp:attachment":[{"href":"https:\/\/blog.hcha.site\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=51"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.hcha.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=51"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.hcha.site\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=51"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}