Scrabble on the Tetrascale
Total Page:16
File Type:pdf, Size:1020Kb
Scrabble on the TeraScale 2/27/08 11:01 AM This is the html version of the file http://cse.unl.edu/~bwickman/scrab-kwak.erased.pdf. G o o g l e automatically generates html versions of documents as we crawl the web. To link to or bookmark this page, use the following url: http://www.google.com/search? q=cache:0JBQstKCkscC:cse.unl.edu/~bwickman/scrab-kwak.erased.pdf Google is not affiliated with the authors of this page nor responsible for its content. Page 1 Scrabble on the TeraScale BRIAN J WICKMAN University of NebraskaLincoln 1. INTRODUCTION 1.3 Considerations To liken Scrabble to a science, one needs to define precise 1.1 Problems rules of gameplay. First and foremost, a standard lexicon Over the years, Scrabble r has become arguably the world's needs to be defined. In the United States, the Official Scrab- most popular word game. Unlike Chess or Go, Scrabble is ble Players Dictionary or OSPD is used, whereas much of a game of imperfect information as there are tiles left unseen the world uses the Official Scrabble Words or OSW. The throughout play. Therefore, adding search or strategy using combination of these lists, coined SOWPODS, is used for standard techniques is infeasible. World-Championship play. Secondly, tournament Scrab- ble is played one-on-one. Thirdly, each player has 25 min- Several authors in academia have produced programs [1, 2, utes to make all his or her moves. The remaining set of rules 4, 5]. There are several limitations to these programs, how- differs on style of play. These rules include constructs for ever, most notably in their age. Consequently, there is little challenging words off the board, exchanging tiles, passing, to no literature on harnessing the power of supercomputers and various other aspects important in computer play. It is for purposes of Scrabble play or research as the advent of assumed the reader knows the basic abovementioned rules. highly available computing resources came at a later date. 2. MOVE GENERATION There is also a lack of useful statistics for Scrabble players. James Cherry, author of an on-line Scrabble computer, simulated 5000 games and presented a body of statistics on 2.1 Overview it such as means, modes and standard deviations of winning The primary concern of a Scrabble programmer is to have game scores, aggregate game scores, highest scoring moves, a fast move generator, especially considering only a fraction number of bingoes per game, number of moves per game, of the total time consumed is not within this routine. Cer- and others. Statistics invaluable to wordgame programmers tain algorithms suffer in speed at the gain of compactness, involve probabilities such as how often words are played. while others do just the opposite. There are also complexity For example, the word QAT is played, on average, in 1 in 5 considerations. While a certain move generation algorithm games using the Official Scrabble Players Dictionary. While may look good on paper, actual performance on an archi- a sample set of 4000 games can provide some clues into typ- tecture depends heavily on the cache and branch-prediction ical gameplay, samples of millions or hundreds of millions mechanisms. are required to achieve asymptotic results and to pan out any irregularities in the data. 2.2 The Appel-Jacobsen Move Generation http://www.gtoal.com/wordgames/bwickman/ Page 1 of 8 Scrabble on the TeraScale 2/27/08 11:01 AM Algorithm 1.2 Goal Appel and Jacobsen published a paper in 1988 that provided The goals of the author are focused into one program, Mar- the first highly specific description of a Scrabble move gen- tin Landau, which is a fully-functional Scrabble program erator. Their first insight was to store the lexicon in a trie both aggressively optimized and written for use in super- and subsequently shrink it into a minimal graph via a finite computing environments. Its primary purpose thusfar is to state machine minimization algorithm. The resulting data generate sample games and consequently compute relevant structure is referred to as a Directed Acyclic Word Graph statistics from these data. Results of such computations will or DAWG. The minimization algorithm achieved nearly a be presented later in the text. four-fold reduction in size, allowing Appel and Jacobsen to fit the entire lexicon in core memory. Translating to today's machines, we can fit the same data structure almost entirely within cache. The first step in the algorithm involves two precomputation steps. First, it finds the squares directly contiguous to laid tiles on the board. These squares are called anchor squares and are those on which we start placing tiles. The second precomputation step computes cross sets for each possible Page 2 h 0 h 1 h 2 h 3 h 4 size of the lexicon data structure, this nondeterminism can v 0 B O I N G v 1 be eliminated completely. h 5 h 6 h 7 h 8 h 9 2.3 The Gordon Move Generation Algorithm h 0 = {A, O} Steve Gordon's move generation algorithm is very similar h 1 = {B, D, G, H, I, J, K, L, M, N, O, P, S, T, W, Y, Z} to the Appel and Jacobsen algorithm. It uses the same minimal data structure but with a slightly different lexi- h 2 = {A, B, D, G, H, L, M, O, P, Q, S, T, X} con. For each word, it stores all its possible linear trans- h = {A, E, I, O, U} 3 positions, separating wrapped letters with a delimiter. For h 4 = {A, U} example, APPEAR would be stored as six separate words: h 5 = {A, E, I, O, Y } APPEAR*, PPEAR*A, PEAR*PA, EAR*PPA, AR*EPPA, and R*AEPPA. While this will incur a tenfold increase in h 6 = {B, D, E, F, H, I, M, N, O, P, R, S, U, W, X, Y } the uncompressed size of the lexicon, the finite state min- h 7 = {D, F, N, O, S, T } imization routine is able to to reduce the trie to 15% of h 8 = {A, E, O, U, Y } its original size. A DAWG with the above transpositions is playfully called a DAGGAD. h 9 = {I, O, U} v = { } 0 To generate moves, it again starts at an anchor square but v 1 = {S} starts placing tiles to the right. If the tiles APPEAR are on the board, it will take the path APPEAR in the DAGGAD. The exit nodes from R are *AEIS. By taking *, it returns back to the anchor square and from then on places Figure 1: Cross Sets for BOING using SOWPODS tiles backwards from right-to-left. For example, APPE AR*ER, a valid path in the DAGGAD, would append the prefix RE onto APPEAR to form REAPPEAR. http://www.gtoal.com/wordgames/bwickman/ Page 2 of 8 Scrabble on the TeraScale 2/27/08 11:01 AM the prefix RE onto APPEAR to form REAPPEAR. anchor square. If one is placing tiles on the board from left- to-right, he or she wants to lay tiles that also form valid The pseudocode for this algorithm is given in Figure 2 as vertical words. The cross sets on the board with the word a corresponding pair of recursive functions, same as that BOING using SOWPODS are illustrated in Figure 1. described by Gordon. If the player had the rack AAEPPRS, he or she could bingo The author implements this algorithm nearly verbatim in by placing, left-to-right starting at h 0 , APPEARS. This is Martin Landau. valid because A h 0 , P h 1 , P h 2 , E h 3 , and A h 4 . Similarly, we could place, top-to-bottom starting at v 1 , Figure 3 and Figure 4 are reprinted from [3], with the au- SARAPE because S v 1 . v 0 is empty because BOING thor's permission, to illustrate the speed-size tradeoffs be- has no single-letter prefixes. Any tile may be placed on a tween basic implementations of both procedures. square without a cross set so long as it is attached to a word intersecting an anchor square. 2.4 Atomicity of Move Generation Algorithm Once the above precomputation steps have occurred, Appel On the average, it takes Martin Landau approximately and Jacobsen's algorithm now considers the board one row 0.0025 seconds to generate all possible moves given a random at a time. By having the cross sets, this consideration is ren- board and random rack on a single processing element of dered entirely one-dimensional. Similarly, it transposes the the Prairefire supercomputer. For racks with a single blank, board so that columns are considered in the same manner time is increased six-fold. For racks with two blanks, time as rows. is increased an additional four-fold. From the position of each anchor square, it generates all Because this number is so small, parallelization of the move possible left prefixes that can be formed from tiles on the generation algorithm on a system with relatively high-latency rack, taking cross sets and paths in the graph into consider- interconnect will actually decrease its speed considerably. ation. With the rack AAEPPRS, it may generate PRE, RE or PAE, but not PAER because, starting from the root of 3. MATING SUPERCOMPUTERS AND the DAWG, there is no path PAER. SCRABBLE TO IMPROVE STRATEGY For each of these prefixes, the algorithm tries placing the A common misconception of novice Scrabble players re- remaining tiles to the right, again considering cross sets and sults in them asking why one should implement a Scrab- paths in the graph into consideration.