From: AAAI Technical Report WS-97-04. Compilation copyright © 1997, AAAI (www.aaai.org). All rights reserved. The Anatomy of Programs

T.A. Marsland

ComputingScience Department University of Alberta Edmonton, AB Canada T6G 2H1 Tony.Marsland@ ualberta.ca

Abstract other highly constrained tactical issues. All programsuse This short paperdefines the terminologyused to support the same underlying depth-first alpha-beta search computerchess work,and introduces the basic concpets algorithm. What varies from program to program is the behindchess programs.It is intendedto be of general length (or "depth", to keep the layer analogy) of search interest, providingbackground information not newideas. 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 Introduction example, a search path maybe locally lengthened because one side has attacked the (given ), leaving the Logically, chess is a trivial game: at every move, simply opponent with only a few alternatives to consider. There follow through each possible reply and its consequences are so manyoptions here that even programs using the until either a mate or a position is reached. In same basic model can achieve a radically different style practical terms, however, this strategy is not workable, and speed of play. since an astronomically large numberof chess positions would have to be examined. Thus both humanplayers and computersrely on simplification to build an approximate Tree Searching model of the game. Humanplayers have centuries of While the humanmethod of analyzing alternatives seems tradition and at least two hundredyears of chess literature to involve selecting a few promising lines of play and to draw on in building their personal model, but computer exploring them, computers are necessarily exhaustive chess is less than fifty years old. Significant amongthe rather than selective, so refinement techniques have been early ideas in computerchess is Claude Shannon’s1.949-50 developed. In a technique called "iterative deepening," distinction between a brute force (type-A) strategy for instead of embarkingon a single search of a certain ply looking at every of moves, and the use of (which might not be completed in the given time) the chess knowledgeto select and examineonly a subset of the computerpertbrms a series of increasingly deeper searches available moves(type-B strategy). Althoughsome electro- (N-ply, then N+I, then N+2, etc.) until the allotted time mechanical systems to play a subset of chess had been runs out. Thus it is able to producethe best movethat the built prior to Shannon’swork, it was the programmingof time constraint allows--a computer-chesssituation that has his ideas that led to the developmentof today’s computer manyparallels in real-time applications. The computercan chess machines. combine iterative deepening with various memory Current chess programs view the gameas a tree search in which each position corresponds to a node in the game- functions, particularly refutation and transposition tables, tree, and each moveis a branch (a transition from one node to reorder moves,so that at the next iteration its selected to the next). Thus the tree is madeup of alternating layers "principal variation" (best sequence of movesfound during or levels of movesfor each side. (The term "ply" is used the previous iteration) is explored first. Another move- to denote each layer, and refers to one move by one reordering technique is to keep a short list of "killer" player.) A three-stage tree model is popular with computer moves, which are tried first. Killer movesare those that chess programmers. The first stage uses a brute force have successfully "cut oft’’ or pruned the search elsewhere. (Shannontype-A) approach, the second a selective (type- Often these killer movesare captures, so a simplification B) search, and the third a strategy knownas a quiescence involves considering capture movesbefore all others. This search, designed to resolve the problemsand conflicts that technique is nicely generalized in the "history heuristic remain. In this final stage the program evaluates table" that many programs use. In its most elementary sequences of capturing moves, assesses potentials, examines checking sequences and considers form a history table has 64x64 entries, each containing a

24 Value game positions each side might have close to 80 moves. With today’s technology, programs exhaustively search 7 Brute Force to 10 ply in the middle game, while at least one Full-width programmerclaims to extend searches selectively to 40 Layers 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 re- examines any movethat looks singularly good relative to the others. The search depth is increased to determine Selective whether the singular move remains best. In some sense Layers 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 Quiescent manyforward pruning methods fail too often to be useful, Layers null moveforward pruning is usually beneficial.

Transposition Table A transposition table serves as a cache memoryand is used to store information about positions that have been visited Value before, usually during an earlier part of an iterative deepeningsearch. It is so called because it can be used to value that measures the frequency with which the recognize transpositions in the order of moves. Stored in corresponding possible move has recently pruned the the entry associated with a position are important items search. like the "value" of the position, the best movefrom there, Move-reordering mechanismsenhance the efficiency of and the length of the previous search. "Value" is computed the depth-first alpha-beta search algorithm. Three other by applying an evaluation function at the terminal nodes of improvements--Pearl’s Scout algorithm and the related the tree (the nodes on the horizon where the search is NegaScoutand Principal Variation Search (PVS) methods- stopping). This evaluation function often includes -share a commontheme: once a principal variation has quiescent search to help resolve existing capture sequences been found it is sufficient to showthat each alternative is and other uncertainties in the position, such as pending inferior. Anythat is not inferior mustbe re-searched, since pawnpromotions. Transposition tables are also invaluable it nowconstitutes the preferred path. Another technique as a means of extending search in the endgame,where only for curtailing the search is called aspiration alpha-beta a few new movesemerge at each node, the others leading search. In this approach the value of the tree from the through transposition to positions that have been seen current position is estimated and a narrow search window before. These tables do not increase program size or (customarily plus and minus the value of half a pawn complexity, since the total space allocated to them is around that estimate) is used. Aspiration searching is simply a matter of cost. Each transposition-table entry popular and better understood alternative to the Principal requires about 10 bytes of memory, and most programs Variation Search method,although not as efficient. have tables in the range from 32,000 to 1 million entries, It is difficult to be precise about the advantages that though in 1993 one Supercomputer program boasted a moresearching provides. The size of the chess tree for any table with a 1,000 million entries! This wide range simply position is highly variable. In manyendgames there are reflects the memoryavailable to the programmer. only about 8 movesfor each side, while in complexmiddle

25 Program Performance and Rating The Future Despite the underlying similarity in methodsthere is wide These days the top chess machines are challenging the variation in performance amongthe programs, even in Grandmasters, especially in rapid play where the stand- machines using identical hardware. In some cases this alone PC-based machines have an advantage over merely reflects the effort put into the program’s multiprocessor-based systems. Stand-alone machines are development. For example, although every program has especially fast, because they don’t need the services of a an opening book, there is no basic book for them to use. computer network to transmit their moves. Multiprocessor Each team develops its own. At present these books vary machinesusing 10 to 100 processors are often better at the in size fl’om about 10,000 chess positions to about 500,000 standard competition rate of play of 40 movesin 2 hours. positions, although one experimental program has 1.7 Soon systems with 1000 processors, each as powerful as a million book entries. Conversely, only a few people use high-performance PC, will be with us. Even if their Ken Thompson’s CD-ROMdatabase of 5 and 6-piece efficiency is only at the 50%level, they will be able to endgames.This is partly for technical reasons related to search 2 or 3 ply deeper in a typical middle-gameposition relatively slow access to the database, but also because than any single-processor system. By then computers will most games finish before reaching these knownendings. be clearly out-searching humans. Whether this will be Perhaps programmersare just being realistic about howto enough to compensate for the human’s proven strength in spend their time! long-term planning remains to be seen. Humanchess Whenit comes to speed of execution, contemporary players are especially skilled at simplifying complex programs examine between 3,000 and 500,000 positions situations and identifying the fundamentalissues. They are per second on a single processor. Big differences in speed also adept at provoking iong-term weaknesses in their exist even for programs using identical machines. There opponent’sposition, until it becomesindefensible. Despite are manyexplanations. Those who program in assembler these advantages, each year we draw closer to realizing the tend to have faster programs, but even for the same perennial prediction that computers will beat the best programminglanguage, not all compilers (translators) humansat chess within 5 years. It could certainly take produce equally fast executable code. Muchdepends too another decadeto achievethat, but the inevitability is clear. 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 References examined. The extent of this slow, knowledge-based These are general sources about Chess Programs and process accounts for muchof the speed difference. One Programming Techniques. other factor that influences the speed and strength of a programis the size of its transposition table. Levy, D. ed. 1988. Compendium, New Althoughmany chess programsare similar to each other, York: Springer-Verlag. their relative playing strength can still differ greatly. Marsland, T.A. 1992. Computer Chess and Search. In Determining that strength is no easy matter, since Encyclopediaof Artificial Intelligence, S. Shapiro (editor), programscan be tuned to performwell on any standard test 2nd edition, 224-241. NewYork: J. Wiley & Sons. suite. For this reason the group whoproduce the Swedish Rating List use a more traditional approach. All Herik, van den H.J. ed., since 1983. International commercially available programs continually and Computer Chess Association Journal, Universitiet automatically play games against each other, leading to Maastricht, The Netherlands. hundredsof statistically valid results. Fromthese data an Marsland, T.A. and Schaeffer, J. eds. 1990 Computers, ELOrating is computed, muchlike the rating system used Chess, and Cognition, NewYork: Springer-Verlag. tor chess-players in Americaand elsewhere. In the USthe Various editors, 1997-1994. Advancesin ComputerChess, average player has a rating over 1500, while experts are in Volumes1 to 7, wu:ious publishers. 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 published in each issue of the International ComputerChess Association Journal.

26