Micro-Max, 一个短小精干的棋类引擎(仅133行 )
Micro-Max 中文翻译
micromax One shortest chess (xiangqi) engine
我最初的目标是写一个不到1024字符的棋类引擎程序,迄今为止,尚未成功。
甚至当我放弃了国际棋联各种细节规则,比如王車易位(入堡,castling)和吃过路兵,我都未能将程序大小控制在1200字符内。
My original aim was to write a chess program smaller than 1024 characters.
I could not do it, so far.
Even when I dropped the nitty gritty details of the FIDE rules, like castling and en-passant capture, I could not get the size much below 1200 characters.
所以我改变我的目标,完成了一个不到2000字符的棋类引擎程序。 这也给我足够的空间去实现哈希转移表,走法正确性验证,完整国际棋类规则。 但是不包括兵的升变,因为程序是永远不可能发现自己在那样一个有用的情况下,所以这个我认为是一个的无趣输入问题。
So I shifted my aim somewhat, and wrote something less minimalistic in up to 2000 characters of source-code.
This gave me enough space to implement a (hash) transposition table, checking of the legality of the input moves, and full FIDE rules.
Except for under-promotions, which I considered a dull input problem, since the program is unlikely to ever find itself in a situation where it would be useful to play one.
(对于真正的棋手:一个接近最小的版本,并完全遵守国际棋联规则包括兵的升变,可以在这里找到。它只有1433个字符。 实现兵的升变用了一行代码,32个字符。要玩这个,输入1,2,3作为输入的移动第五个字符,可分别晋升为车,像,马。如果不输入任何字符或者输入0,则晋升为后)
(For real purists: a close-to-minimal version that does understand full FIDE rules including under-promotion can be found here. It measures 1433 characters. The under-promotions are implemented in a single line that wastes 32 characters. To play one, type 1, 2, or 3 as the 5th character of the input move, for promotion to R, B, or N, respectively.
If you type nothing, or 0, promotion is to Q.)
据我所知,这使得micro-Max任何是目前最小的C语言的棋类引擎程序。有一个竞争对手,托莱多,仅有2168个字符。 尽管它的体积小,micor-Max似乎很容易击败托莱多。)
接下来,将从如下方面介绍micro-Max:
As far as I am aware, this still makes micro-Max the smallest C Chess program in existence.
A close competitor for this honor, Toledo, measures 2168 characters.
Despite its smaller size, micro-Max seems to beat Toledo easily.
On these pages various aspects of micro-Max are described:
-
基本数据表示 Basic Data Representations
-
棋法 Move Generation
基础走法 Basic Moves
过路吃兵 En Passant Capture
王车易位 Castling
兵的升变 Pawn Promotions -
搜索算法
Alpha-Beta Minimax
Quiescence搜索 Quiescence Search
进一步&退一步 Do and Undo Move
迭代深入搜索 Iterative Deepening
棋法排序 Move Sorting -
转移表 transposition_table
-
棋局评估(Evaluation)
Material
Piece-Square Table
[将死与偷子] (Checkmate and Stalemate)
Delay Penalty -
The Interface
Move Legality Checking
其它
程序中所有变量定义说明:地址
An overview of the meaning of all variables in the program can be found here.
为了使得想研究该算法的童鞋更容易,有一个变量名更有可读(也更长)的版本提供:地址
To make it easier for those who want to study the algorithm, there now also is a version that uses more meaningful (and much longer…) variable names. Downloading
如果你想在自己的电脑上运行 micro-max,你得拷贝代码到本地,并且编译它。
关于如何编译,更多细节见此
If you want to try micro-Max on your PC, you can copy-paste the source and compile it yourself.
Details on how to do this can be found here.
未来 Future
There are still plenty places where I can scavenge a few characters off the source code.
(E.g. A->K in stead of A[0].K, and a->X&M^M in stead of (a->X&M)!=M, and perhaps combining the two Zobrist keys in a 64-bit type.)
The castling code is also rather dumb and bulky.
I hope to be able to compact the code enough (without loss of functionality) to make room for new features,
in particular null-move threat detection.
I will post the progress of this project regularly on separate pages,
so that it does not mess up the tutorial on micro-Max 3.2.
If some clearly defined feature is added to future versions of micro-Max, the page explaining it will be included in the index above.
Below is the complete source code of micro-Max 3.2.
(Click on the various code lines to go directly to their explanation.)
If you want to copy-paste it, it is recommended you do it from here,
because if I correct a small bug or typo I am generally too lazy to do it on all other pages where the source occurs.
So I do it here, and on the page where the particular feature needing the correction is discussed and highlighted.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
|