README 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. GNU Chess
  2. Copyright (C) 1986 Stuart Cracraft
  3. (Copying permission notice at the end.)
  4. GNU Chess is your program (as long as you follow the copyright and
  5. licensing rules listed in the file COPYING). Your contribution to GNU
  6. Chess will be retained and given to hundreds of other GNU Chess
  7. devotees. Each improvement you make is important not just to you, but
  8. also to all of us. As such, you must give us your changes. And in
  9. fact, you are required to do so.
  10. This program is one small step toward making generally available a
  11. chess program with source to inspire current and future software
  12. developers. This program is purely experimental. It is not a
  13. strong program.
  14. In the best of all possible worlds, not only would this program play
  15. totally legal chess, but it would also play well. I leave this up to
  16. the recipients of this document, fellow computer chess enthusiasts in
  17. the world at large.
  18. Move generator
  19. --------------
  20. The most important thing in any chess program is the speed of the
  21. legal move generator. How fast can you generate lists of legal moves
  22. for arbitrary chess positions? Research has shown that this is
  23. directly correlated to how many moves ahead you can look and therefore
  24. inextricably linked with the chess strength of the chess program.
  25. This program has an adequate move generator. But it is nothing to
  26. boast about. The move generator is in the module 'gen.c'. An
  27. alternate move generator is contained in the files tbl_*.c. The
  28. latter is a table-driven move generator in which all offsets normally
  29. calculated upon execution are precalculated. It might work faster
  30. than the non-table-driven version unless the memory accessing is
  31. particularly slow. However, tests have shown that overall,
  32. table-driven is inferior due to the increased complexity. (On a Vax
  33. 8650, the GNU Chess move generator produces about 1200 move generations
  34. per second. While this is adequate, it is definitely not fast enough.)
  35. If you can write a move generator that is super-fast, you are well on
  36. your way to writing a skillful artificial chessplayer. But if you
  37. manage to do this, please let me know! I have spent many hours upon
  38. move generators, and still don't have anything I consider speedy.
  39. Opening Book
  40. ------------
  41. GNU Chess has an opening book. It consists of hundreds of master games
  42. from tournament play. The program converts these games into positions,
  43. independent of moves, and then constructs a database such that any
  44. position may be retrieved via a hash-address.
  45. There are currently two styles of syntax supported. The first is
  46. in "bookin". The second is in bookin.xxx, where "xxx" refers to
  47. the type of games in the collection. For example, the syntax of
  48. bookin.tal, reduced algebraic, is the second supported syntax.
  49. We do not support English descriptive syntax.
  50. Transpositions are handled by GNU Chess because the positions are
  51. dealt with independently of the series of moves by which they were
  52. reached. Any position which ever appears in the current game at ply-1
  53. will be retrieved from the opening book along with a move made by the
  54. a master, and more frequently an international master or grandmaster.
  55. It does not matter when the position appears or what sequence of moves
  56. has occurred before. If several suggested moves are available, the
  57. program chooses from amongst these randomly, if -DRANDOM flag is set
  58. within Makefile. Without this flag, GNU Chess selects the first
  59. available variation as it appears in physical order in the
  60. human-readable book.
  61. Now that the opening book C code has been written, our next
  62. project is to type in all of the collected games of a great
  63. master (such as Mikhail Tal or Robert Fischer). Then, GNU Chess
  64. will simply play exactly like the great master in the opening,
  65. assuming that the opponent obliges. You may wonder, but
  66. what happens when the game has clearly gone out of book? What
  67. to do? Just revert to the ordinary search? This is normally
  68. the case. But with GNU Chess, we hope to make the opening
  69. play quite sophisticated. We plan to implement the Fast
  70. Fourier Transform in such a way that the ply-one preprocessor
  71. will use a Fast Fourier as applied to all the Tal or Fischer
  72. games, and hence order its moves, not based on simple child-like
  73. heuristics, but based on the Fast Fourier of the thousands of
  74. Tal and Fischer games. The idea would be to give the program
  75. a chess style by having it duplicate the opening play of a
  76. great master and then mimic the middle and end-game play of
  77. the master once the opening book has been exhausted, backed
  78. up with tactical brute-force search of course. To the best of
  79. our knowledge, this idea is unique. You could help by typing
  80. in all the great games of a Master, or if you know of such
  81. a collection on-line, you could help by telling us about it.
  82. Currently, we have hundreds of games by former world champion
  83. Mikhail Tal (stored in "bookin.tal" in the distribution).
  84. Many of these games involve lovely sacrifices and are
  85. quite interesting to play through.
  86. To teach GNU Chess the games of a Master, simply get a chess
  87. book, run gnuchess, type "neither", and then type in the game,
  88. move by move. You may have to convert the syntax of the published game
  89. (English or Algebraic) to gnuchess syntax (e.g. e2e4, etc.)
  90. After you have typed the game in, use the "enter" command
  91. to enter it in the opening book. You will then need to
  92. use the "book" command to have these changes installed
  93. in the binary database itself.
  94. When you do this, GNU Chess will try to "mail" each new
  95. game you enter to the GNU Chess opening book maintainers.
  96. If you are not on our network, then obviously the mail
  97. will fail -- in this instance, you should send the new
  98. entries to us via postal mail (our postal address is
  99. listed at the end of this document). Please do this so
  100. that we can have your contributions.
  101. Tree Search
  102. -----------
  103. GNU Chess tree search is patterned after the ply-1 preprocessor
  104. search invented by Gillogly and Berliner. This style of search
  105. is not too difficult to implement and carries with it an added bonus.
  106. The search speed is not significantly interfered with by the addition
  107. of chess knowledge.
  108. A ply-1 preprocessor search is simply a 1-ply search, with full
  109. evaluation taking place at ply-1 nodes, sorting the resultant
  110. backed-up values (no need for minimax/alphabeta at this point).
  111. The resulting sorted list is then searched, from most valuable
  112. move to least, with a full-width depth-first alpha-beta minimax search.
  113. A pre-set terminal depth is reached at which the depth-first search
  114. either terminates returning its value to the previous level or
  115. continues with a quiescence search to another pre-set level.
  116. The quiescence search involves the investigation only of captures
  117. or checks. In the case of this program, only captures are investigated
  118. beyond DEPTH nodes (defined in Makefile). These captures are then
  119. searched until MAXQUIES nodes (also defined in Makefile).
  120. Terminal nodes are considered to be either a) MAXQUIES nodes
  121. or b) DEPTH nodes if no captures exist. In either case, the
  122. evaluation consists solely of the difference of material between
  123. White and Black. This evaluation is then backed up in a minimax
  124. fashion using alpha-beta vertically through the tree. At the
  125. root node, a value and best move are returned. These are then
  126. selected as the program's move.
  127. Additionally, a technique called "aspiration search" is used. This
  128. reduces the size of the alpha-beta search window to only two pawns
  129. wide before conducting the search. This results in more cutoffs and a
  130. faster search (3% to 40% faster) than pure alpha-beta. However,
  131. occasionally the returned search value will be outside of the window
  132. and the search is then called "failing high" or "failing low". If this
  133. happens, a second search must be done with a wider window. This may
  134. result in an occasional slower search, but the overall improvement
  135. averaged over many moves is such that "aspiration search" makes the
  136. program somewhat faster.
  137. So, essentially, GNU Chess orders the top level moves from
  138. which it must select using any set of heuristics we devise. Then,
  139. the search merely confirms that the move we choose wins the
  140. most amount of material, or at least remains equal. A tiebreak
  141. of equally valuable moves is based upon the order in which the
  142. moves appear in our heuristically-sorted movelist at the first
  143. ply.
  144. Incremental search is not particularly useful with this scheme.
  145. Parallel Processors
  146. -------------------
  147. GNU Chess can use more than one processor. The PARALLEL flag
  148. in Makefile creates a GNU Chess which uses parallelism.
  149. However, at present, the processors must share the same disk
  150. and communicate over a network using the Berkeley
  151. 'rsh/rlogin/etc' convention. One such configuration is a SUN
  152. network with a central fileserver. The distributed version
  153. of GNU Chess was set up to work with our SUN network
  154. configuration.
  155. This configuration is described in the 'procarray[]' in module
  156. parallel.c. Each host is listed with its corresponding machine
  157. architecture, whether to use it, and if it shares the same disk.
  158. The same disk is assumed to mean the one on which the user
  159. originally invoked GNU Chess intending to eventually use
  160. parallelism.
  161. Parallelism introduces many "sticky" factors into chess computing.
  162. One of these factors is the communications overhead in managing
  163. multiple processors. In our implementation, this overhead is
  164. immense and prevents the search from being nearly as fast as one
  165. would expect. But then again, our implementation is quite young
  166. and has much work ahead of it.
  167. Assuming N processors, the ply-1 move list is divided equally
  168. among the N processors and each processor then searches its own
  169. subset of the tree using the normal search algorithm, slightly
  170. changed from the version in alphabeta.c and called 'psearch'
  171. residing in parallel.c.
  172. A parallel search in GNU Chess usually consumes more terminal
  173. nodes, because good alpha and beta values are not as readily
  174. available. Some processors may get good alpha and beta values,
  175. others may not. Since these latter instances will slow down the
  176. search, the entire parallelism is as strong as its weakest link.
  177. In this case, the search terminates when the last processor
  178. finishes. Needless to say, many improvements can (and will) be
  179. made to this scheme.
  180. We also plan to introduce modifications to allow the use of
  181. processors that don't share the same disk. This will involve
  182. transferring the statistics of the search to the originating
  183. processor after completion by any given processor.
  184. Fancy Displays
  185. --------------
  186. Currently, GNU Chess supports two different styles of windowing
  187. support for a fancy board. Fancy boards make it easier to play
  188. the game, because all the chess-pieces are displayed in lovely
  189. chess fonts on a big bitmap screen. How this generally happens
  190. is as follows: GNU Chess is invoked through the windowing
  191. support program which communicates with GNU Chess as a separate
  192. process, talking with GNU Chess in order to transmit and receive
  193. moves. All communication with GNU Chess, when using a windowing
  194. support program, is done through the windowing support system,
  195. generally via the use of a "mouse".
  196. The first style of chess windowing support is for the X windowing
  197. system. We provide full sources to the X-chess windowing display
  198. manager within the sub-directory 'Xchess' of this distribution.
  199. X-chess has quite a few more features than SUN's chesstool. For
  200. this reason, the truly supported window system for GNU Chess is
  201. X-chess. If you find a bug in X-chess, you may report it to us.
  202. The second style of chess windowing support is SUN's chesstool.
  203. It is fully documented in SUN's manual pages. If you find a bug
  204. in chesstool, you may report it to us, but you should also
  205. report it to SUN so that they can fix it.
  206. Conclusion
  207. ----------
  208. GNU Chess has been semi-debugged as of 1986, seems to play on
  209. a wide variety of machines, but nothing is guaranteed. You can
  210. help this program by making it better.
  211. The file CHANGES contains a complete history of changes made to the
  212. program, ordered chronologically.
  213. The file TODO contains other suggestions for how to improve this program.
  214. Here is a list of the source files and their actual purpose:
  215. alphabeta.c - searches the tree
  216. book.c - implements opening book.
  217. eval.c - evaluates a position
  218. gen.c - generates legal moves
  219. hash.c - tries to do hashing of positions already seen
  220. main.c - accepts commands, executes commands
  221. moves.c - random move routines
  222. parallel.c - parallel processing routines
  223. pps.c - positional pre-sort
  224. tbl_gen.c - table-driven move generation controller
  225. tbl_genpc.c - table-driven move generation for pieces
  226. tbl_genpwn.c - table-driven move generation for pawns
  227. util.c - random utilities
  228. Bitmapper/* - complex bitmap manipulation routines
  229. Xchess/* - the X window interface to GNU Chess
  230. bookin - human-readable book in GNU Chess move format,
  231. parsed via "book" command
  232. bookin.tal - collected games of Mikhail Tal,
  233. parsed via "enter" command
  234. bookin.bdg - additional book games in reduced algebraic format
  235. convert.el - LISP macro (in GNU Emacs Lisp) to convert
  236. Xchess-format games (via 'xchess -i') to
  237. GNU Chess format.
  238. Please note that the following are not considered debugged:
  239. table-driven move generation and hashing of positions during
  240. tree-search.
  241. The Bitmapper code is an experimental idea that would
  242. eventually replace the regular code. It is completely
  243. different in terms of the way it implements data structures
  244. and static evaluation, the idea being that by making the
  245. data structures more complex and informative, the program
  246. could carry along a lot more information from move to move.
  247. The ideas here are loosely based on the work of some Soviets
  248. and some early researchers at Northwestern University. Note
  249. that much of this code is hard-wired to specific machine
  250. word sizes, in this case, a 32-bit word. But it should not
  251. be too hard to change this to work on any given machine,
  252. as long as the word-size perfectly divides 64.
  253. Please remember that GNU Chess is purely experimental and
  254. has not participated in any rated tournaments. You are
  255. welcome to enter it in a tournament, but proper
  256. recognition must be given to the author and the Free
  257. Software Foundation. If any spectators inquire about the
  258. program during the tournament, you are also morally bound
  259. to tell them how you got the program and either to supply
  260. them with the distribution you received from us, or for
  261. the latest version tell the spectator our address so that
  262. he may get it directly from us. We would also like you to
  263. tell us if you are entering it in a tournament.
  264. Only through your contributions to GNU Chess will it
  265. become a stronger program. There is the possibility that
  266. it could become the strongest chess program by the end of
  267. the 20th century if enough people join in and contribute!
  268. Both hardware experts and software experts are needed.
  269. If you have a hardware implementation of some of the functions
  270. normally carried out in software, and if you would like to interface
  271. your special-purpose hardware to GNU Chess, we will be more than happy
  272. to talk with you.
  273. If you have large chess databases, either of patterns, chess
  274. knowledge, or game-listings, and if you feel these could be
  275. of use in the development of GNU Chess, we want to talk with you.
  276. If you make any changes, additions, modifications, improvements,
  277. please be sure to pass along all your modifications to the address
  278. listed below.
  279. We will provide a tape along with GNU Chess, its full and most recent
  280. sources, as well as the opening book(s), but there is a $150 handling
  281. charge if you want to get GNU Chess from us directly. If you are on
  282. our network, we can provide it to you free of charge because the
  283. distribution doesn't take any of our time. If you get GNU Chess from
  284. someone else, obviously they cannot charge you, but you also won't
  285. necessarily be getting the latest copy.
  286. Stuart Cracraft
  287. P.O. Box 13123
  288. Torrance, Ca. 90503
  289. The predecessors of GNU Chess
  290. -----------------------------
  291. GNU Chess by Stuart Cracraft is a descendent of the Technology Chess
  292. Program by Jim Gillogly. A history of the latter is in order. The
  293. original TECH was written years ago by Jim when he was at
  294. Carnegie-Mellon University working for his Ph.D. under Hans Berliner.
  295. The results of his effort was a program called TECH, written in BLISS,
  296. a high-level systems programming language running under the TOPS-10
  297. operating system environment. (Jim provided some helpful theoretical
  298. commentary during the writing of GNU Chess.)
  299. TECH did not play very well. By most standards it was a low class D
  300. player. TECH's chief contribution to computer chess theory was it
  301. showed very little knowledge was necessary in order to play passable
  302. chess. Indeed, TECH used only material evaluation at terminal nodes
  303. in the search tree. The only sophisticated chess knowledge was used
  304. at the very top of the tree to examine the positions after each of the
  305. possible chess moves for the side on move, usually a number no larger
  306. than fifty.
  307. The advantage of this scheme was that huge amounts of chess knowledge
  308. could be embedded in the program without degrading overall
  309. performance. However, one point in Jim's thesis was that the TECH
  310. program eschewed this knowledge but did not forbid it. The bent of
  311. the program, however, was definitely to avoid it. If the knowledge
  312. were made a significant part of the tree-search at the top-level and
  313. because this knowledge was applied in only 50 or so positions, and
  314. would not be subject to the exponential tree-growth, as in the case
  315. where more knowledge would be added to an evaluator used at terminal
  316. nodes, the performance would increase at minimal expense in increased
  317. cpu consumption. This is a non-trivial result, the importance of which
  318. has still not been generally recognized in the computer chess and
  319. artificial intelligence community.
  320. Alan Baisley of MIT liked what he saw in TECH and decided to speed it
  321. up. TECH2 was his successful attempt at writing a new and stronger
  322. TECH. He achieved this by rewriting the program in assembly language
  323. and substantially improving the speed of the move generation
  324. algorithm. Baisley's TECH2 could be considered a class C or low class
  325. B player at best. It ran on a KA-10 processor, and later on KI-10's
  326. and KL-10's (the modern and now defunct DEC-20 architecture).
  327. Neither the TECH developers nor the TECH2 developers spent much time
  328. adding much chess knowledge to the top-level ply-one preprocessor.
  329. This is unfortunate because this is probably the most significant
  330. theoretical contribution of the idea of TECH. While all other
  331. chess developers were using forward pruning (e.g. eliminating
  332. certain subsets of moves before even searching them) or adding
  333. more knowledge to terminal-node evaluators while cringing as
  334. each new addition chewed up a large chunk of cpu and decreased the
  335. effective depth to which the program could search, Gillogly, Baisley
  336. and their colleagues were demonstrating something very significant,
  337. something which I feel will eventually lead to a world-class
  338. computer chess player a few decades from now.
  339. Subsequent development efforts by commerical chess machine marketers
  340. have shown that the addition of this substantial knowledge at the
  341. first ply improves performance. Some of these commerical TECH's are
  342. low class A players and there is one that is probably even a strong A
  343. player (the Constellation Expert marketed by Novag).
  344. Other versions of TECH have existed over the years, some containing a
  345. hardware-assist to do the move generation normally done in hardware.
  346. Sometimes the tree-search, positional evaluation, and move generation
  347. are all done in hardware circuitry. One developer even went so far
  348. as to embed the move generation in VLSI technology, achieving the
  349. distinction of a complete board move generation in 250 nanoseconds.
  350. Not coincidentally, it achieved a very strong chess rating.
  351. Earlier, I mentioned the likelihood of TECH's basic idea eventually
  352. triumphing at the world-class level. My reasons for this are many,
  353. but I will briefly describe a few of them here.
  354. All conventional chess programs are severely limited in the amount of
  355. chess knowledge they can apply within the search. It is not uncommon
  356. for modern programs/hardware to search millions of chess positions in
  357. three minutes while choosing a move in a tournament. This has been
  358. fortunate, because up to about 2200 level chess, tactics predominate.
  359. After that level however, positional considerations become extremely
  360. important. Because the programs search so many nodes, the time spent
  361. at any given node must be minimized if the search is to be conducted
  362. in the allotted time, usually no more than a few minutes. Forcing
  363. the program to become more accurate regarding its evaluation of
  364. a given node requires the addition of more computer instructions to
  365. evaluate the node positionally.
  366. Each additional computer instruction in these conventional programs to
  367. add chess knowledge must be balanced out by lots of new, sophisticated
  368. search techniques to make up for the time lost by adding new
  369. knowledge. It is probably true that in computer chess, knowledge is
  370. even less incrementally useful towards achieving increased strength
  371. than an incremental addition of a small amount of search speed. It is
  372. due to this basic fact that search beats knowledge. However, both are
  373. necessary. The question arises as to where the knowledge is essential
  374. and where it returns the most bang for its buck, inside the tree?
  375. At the bottom of the tree? Or, like TECH, at the top of the tree.
  376. Modern ply-one preprocessors in TECH-like descendents are very
  377. sophisticated. One such implementation has 120 rules, half of which
  378. are pawn heuristics. This vastly exceeds the amount of heuristics in
  379. even the most sophisticated terminal-node evaluators. Because ply-one
  380. preprocessors in TECH-like descendents allow infinite additional chess
  381. knowledge at minimal additional cpu-time expense, it is this
  382. increasing store of chess knowledge that will eventually make the
  383. difference between a 2200 level computer chess player that achieves
  384. that strength due to 2600 level tactics and 1800 level positional
  385. sense versus a 2400 computer chess player that achieves that strength
  386. due to 2600 level tactics and a 2200 level positional sense. The ply-one
  387. preprocessor at that stage will be an expert-level heuristic based
  388. system of some sort, perhaps a massive database of millions of
  389. Master games with a sophisticated pattern matcher. For more information
  390. on this latter idea, see below.
  391. When we reach this point, the point of tying an expert-level system
  392. together with everything else in pure hardware, perhaps VLSI-level, it
  393. is then that we will reach the International Master and even Grand
  394. Master levels of chess play. The amount of work remaining to reach
  395. this point is immense.
  396. Copyright (C) 1986 Stuart Cracraft
  397. Permission is granted to anyone to make or distribute verbatim copies
  398. of this document as received, in any medium, provided that the
  399. copyright notice and permission notice are preserved,
  400. and that the distributor grants the recipient permission
  401. for further redistribution as permitted by this notice.
  402. Modified versions of this document may not be made.