Academia.eduAcademia.edu

Anatomy of a chess program

1995

This short paper defines the terminology used to support computer chess work, and introduces the basic concpets behind chess programs. It is intended to be of general interest, providing background information ot new ideas.

From: AAAI Technical Report WS-97-04. Compilation copyright © 1997, AAAI (www.aaai.org). All rights reserved. The Anatomy of Chess Programs T.A. Marsland ComputingScience Department University of Alberta Edmonton, AB Canada T6G 2H1 [email protected] Abstract This short paperdefines the terminologyusedto support computer chess work,andintroducesthe basic concpets behindchess programs.It is intendedto be of general interest, providing background information not newideas. Introduction Logically, chess is a trivial game: at every move,simply follow through each possible reply and its consequences until either a mate or a draw position is reached. In practical terms, however, this strategy is not workable, since an astronomically large numberof chess positions would have to be examined. Thus both humanplayers and computersrely on simplification to build an approximate model of the game. Humanplayers have centuries of tradition and at least two hundredyears of chess literature to draw on in building their personal model, but computer chess is less than fifty years old. Significant amongthe early ideas in computerchess is Claude Shannon’s1.949-50 distinction between a brute force (type-A) strategy for looking at every combination of moves, and the use of chess knowledgeto select and examineonly a subset of the available moves(type-B strategy). Althoughsomeelectromechanical systems to play a subset of chess had been built prior to Shannon’swork, it was the programmingof his ideas that led to the developmentof today’s computer chess machines. Current chess programsview the gameas a tree search in which each position corresponds to a node in the gametree, and each moveis a branch (a transition from one node to the next). Thusthe tree is madeup of alternating layers or levels of movesfor each side. (The term "ply" is used to denote each layer, and refers to one move by one player.) A three-stage tree modelis popular with computer chess programmers. The first stage uses a brute force (Shannontype-A) approach, the second a selective (typeB) search, and the third a strategy knownas a quiescence search, designed to resolve the problemsand conflicts that remain. In this final stage the program evaluates sequences of capturing moves, assesses pawn promotion potentials, examines checking sequences and considers 24 other highly constrained tactical issues. All programsuse the same underlying depth-first alpha-beta search algorithm. What varies from program to program is the length (or "depth", to keep the layer analogy) of search assigned to each of these stages. Ultimately the stage length is not fixed, but varies by small amountsdepending on the current sequence of moves being examined. For example, a search path maybe locally lengthened because one side has attacked the King (given check), leaving the opponent with only a few alternatives to consider. There are so manyoptions here that even programs using the same basic model can achieve a radically different style and speed of play. Tree Searching While the humanmethod of analyzing alternatives seems to involve selecting a few promising lines of play and exploring them, computers are necessarily exhaustive rather than selective, so refinement techniques have been developed. In a technique called "iterative deepening," instead of embarkingon a single search of a certain ply (which might not be completed in the given time) the computerpertbrms a series of increasingly deeper searches (N-ply, then N+I, then N+2, etc.) until the allotted time runs out. Thusit is able to producethe best movethat the time constraint allows--a computer-chesssituation that has manyparallels in real-time applications. The computercan combine iterative deepening with various memory functions, particularly refutation and transposition tables, to reorder moves,so that at the next iteration its selected "principal variation" (best sequence of movesfound during the previous iteration) is explored first. Another movereordering technique is to keep a short list of "killer" moves, which are tried first. Killer movesare those that have successfully "cut oft’’ or prunedthe search elsewhere. Often these killer movesare captures, so a simplification involves considering capture movesbefore all others. This technique is nicely generalized in the "history heuristic table" that many programs use. In its most elementary form a history table has 64x64entries, each containing a Value game positions each side might have close to 80 moves. With today’s technology, programs exhaustively search 7 to 10 ply in the middle game, while at least one programmerclaims to extend searches selectively to 40 ply! Selective extensions are based on heuristics devised by individual programmers to explore the sphere of influence associated with a key move: to examine the movesthat might defend against a mate threat, or that might provide a counter attack and thus indirectly avoid some imminent loss. Selective extensions are not to be confusedwith singular extensions. The latter technique reexaminesany movethat looks singularly good relative to the others. The search depth is increased to determine whether the singular move remains best. In some sense this is a way of extending the principal variation in the small. It is a potentially costly but interesting method. More popular and more widely used is the null move heuristic, where one side provisionally makes two successive moves. If the value of the position remains poor even with the benefit of two movesin a row, then the line of play is abandoned. This is one way to identify situations where an inevitable loss is otherwise being pushed out of sight beyond the search horizon. While manyforward pruning methodsfail too often to be useful, null moveforward pruning is usually beneficial. Brute Force Full-width Layers Selective Layers Quiescent Layers Transposition Value value that measures the frequency with which the corresponding possible move has recently pruned the search. Move-reordering mechanismsenhance the efficiency of the depth-first alpha-beta search algorithm. Three other improvements--Pearl’s Scout algorithm and the related NegaScoutand Principal Variation Search (PVS) methods-share a commontheme: once a principal variation has been found it is sufficient to showthat each alternative is inferior. Anythat is not inferior mustbe re-searched, since it nowconstitutes the preferred path. Another technique for curtailing the search is called aspiration alpha-beta search. In this approach the value of the tree from the current position is estimated and a narrow search window (customarily plus and minus the value of half a pawn around that estimate) is used. Aspiration searching is popular and better understood alternative to the Principal Variation Search method,although not as efficient. It is difficult to be precise about the advantages that moresearching provides. The size of the chess tree for any position is highly variable. In manyendgamesthere are only about 8 movesfor each side, while in complexmiddle 25 Table A transposition table serves as a cache memoryand is used to store information about positions that have been visited before, usually during an earlier part of an iterative deepeningsearch. It is so called because it can be used to recognize transpositions in the order of moves. Stored in the entry associated with a position are important items like the "value" of the position, the best movefrom there, and the length of the previous search. "Value" is computed by applying an evaluation function at the terminal nodes of the tree (the nodes on the horizon where the search is stopping). This evaluation function often includes quiescent search to help resolve existing capture sequences and other uncertainties in the position, such as pending pawnpromotions. Transposition tables are also invaluable as a means of extending search in the endgame,where only a few new movesemerge at each node, the others leading through transposition to positions that have been seen before. These tables do not increase program size or complexity, since the total space allocated to them is simply a matter of cost. Each transposition-table entry requires about 10 bytes of memory, and most programs have tables in the range from 32,000 to 1 million entries, though in 1993 one Supercomputer program boasted a table with a 1,000 million entries! This wide range simply reflects the memoryavailable to the programmer. Program Performance and Rating The Future Despite the underlying similarity in methodsthere is wide variation in performance amongthe programs, even in machines using identical hardware. In some cases this merely reflects the effort put into the program’s development. For example, although every program has an opening book, there is no basic book for them to use. Each team develops its own. At present these books vary in size fl’om about 10,000 chess positions to about 500,000 positions, although one experimental program has 1.7 million book entries. Conversely, only a few people use Ken Thompson’s CD-ROMdatabase of 5 and 6-piece endgames.This is partly for technical reasons related to relatively slow access to the database, but also because most games finish before reaching these knownendings. Perhaps programmersare just being realistic about howto spend their time! Whenit comes to speed of execution, contemporary programs examine between 3,000 and 500,000 positions per second on a single processor. Big differences in speed exist even for programs using identical machines. There are manyexplanations. Those who program in assembler tend to have faster programs, but even for the same programminglanguage, not all compilers (translators) produce equally fast executable code. Muchdepends too on the relative sizes of the brute force, the selective and the quiescent search stages. Extra time is required in the selective stage to assess and identify which moveswill be examined. The extent of this slow, knowledge-based process accounts for muchof the speed difference. One other factor that influences the speed and strength of a programis the size of its transposition table. Althoughmanychess programsare similar to each other, their relative playing strength can still differ greatly. Determining that strength is no easy matter, since programscan be tuned to performwell on any standard test suite. For this reason the group whoproduce the Swedish Rating List use a more traditional approach. All commercially available programs continually and automatically play games against each other, leading to hundredsof statistically valid results. Fromthese data an ELOrating is computed, muchlike the rating system used tor chess-players in Americaand elsewhere. In the USthe average player has a rating over 1500, while experts are in the range 2000-2200 and masters are rated 2200-2400. Above that come the super elite players called Grand Masters, of whomabout 100 are active worldwide. At the Eighth World Computer Chess Championships most programs have an ELOrating in the range 2100-2500. The current Swedishrating list is publishedin each issue of the International ComputerChess Association Journal. 26 These days the top chess machines are challenging the Grandmasters, especially in rapid play where the standalone PC-based machines have an advantage over multiprocessor-based systems. Stand-alone machines are especially fast, because they don’t need the services of a computer network to transmit their moves. Multiprocessor machinesusing 10 to 100 processors are often better at the standard competition rate of play of 40 movesin 2 hours. Soon systems with 1000 processors, each as powerful as a high-performance PC, will be with us. Even if their efficiency is only at the 50%level, they will be able to search 2 or 3 ply deeper in a typical middle-gameposition than any single-processor system. By then computers will be clearly out-searching humans. Whether this will be enough to compensate for the human’s proven strength in long-term planning remains to be seen. Humanchess players are especially skilled at simplifying complex situations and identifying the fundamentalissues. They are also adept at provoking iong-term weaknesses in their opponent’sposition, until it becomesindefensible. Despite these advantages, each year we drawcloser to realizing the perennial prediction that computers will beat the best humansat chess within 5 years. It could certainly take anotherdecadeto achievethat, but the inevitability is clear. References These are general sources about Chess Programs and ProgrammingTechniques. Levy, D. ed. 1988. Computer Chess Compendium, New York: Springer-Verlag. Marsland, T.A. 1992. Computer Chess and Search. In Encyclopediaof Artificial Intelligence, S. Shapiro (editor), 2nd edition, 224-241. NewYork: J. Wiley &Sons. Herik, van den H.J. ed., since 1983. International Computer Chess Association Journal, Universitiet Maastricht, The Netherlands. Marsland, T.A. and Schaeffer, J. eds. 1990 Computers, Chess, and Cognition, NewYork: Springer-Verlag. Various editors, 1997-1994. Advancesin ComputerChess, Volumes1 to 7, wu:ious publishers.