Notes on solving and playing peg solitaire on a computer
We consider the one-person game of peg solitaire played on a computer. Two popular board shapes are the 33-hole cross-shaped board, and the 15-hole triangle board---we use them as examples throughout. The basic game begins from a full board with one …
Authors: George I. Bell
Notes on solving and pla ying p eg solitaire on a computer George I. Bell gibell@comc ast.net Abstract W e consider the one-p erson game of p eg solitaire pla yed on a computer. Tw o p opular b oard shap es are the 33-hole cross-shap ed b oard, and the 15-hole triangle b oard—we u se them as examples throughout. The basic game b egins fr om a full b oard with one p eg missing and the goal is to fi nish at a b oard p osition with one p eg. First, w e d iscuss wa ys to solv e the basic game on a computer. Then w e consider the problem of quic kly distinguishing b oard p ositions where the goal can still b e reac h ed (“winning” b oard p ositions) from those where it cannot. This enables a co mputer to alert the pla yer if a jump u nder consideration leads to a d ead end. On the 15-hole triangle b oard, it is p ossible to identify all win n ing b oard p ositions (from any single v acancy start) b y storing a k ey set of 437 b oard p ositions. F or the “central game” on the 33-hole cross-shap ed b oard, we can iden tify all winn ing b oard p ositio ns by storing 839,53 6 b oard p ositions. By viewing a su ccessful game as a tra versal of a directed graph of winn ing b oard p ositions, we apply a simple algorithm to count the num b er of wa ys to trav erse this graph, and calculate that the total n um b er of s olutions to the cen tral game is 40,861 ,647,0 40,079,968. Our analysis ca n also determine ho w quic kly w e can reac h a “dead b oard p osition”, where a one p eg fin ish is n o longer p ossible. 1 In tro duct i o n P eg solitaire is one of the oldest puzzles, with a 300 ye ar history . T he puzzle consists of a game b oard together with a num b er of p egs, or more commonly marbles. The b oard contains a grid of holes in whic h these p egs or marbles are placed. Figure 1 sho ws the most common shap es for a p eg solitaire b oard, the 3 3-hole cross-shap ed b oard, and the 15- hole tr iangle b oard. The game is pla yed b y jumping o ne p eg o v er another into an empt y hole, removin g the p eg that w as jump ed o v er. O n the cross-shap ed b oard of Figure 1 a, these jumps m ust b e made along columns or row s, whereas on the triangle boa r d of Figure 1 c, jumps are allow ed along an y of the six directions parallel to the sides of the b oard. The g oal is to finish with one p eg, a more adv anced v ariation is to finish with one p eg at a sp ecified hole. The basic game b egins from a full b oard with one p eg r emo v ed, a s in Figure 1 a or c. Starting from Figure 1 a and ending with one p eg in the cen ter of the b oard is kno wn as the “cen tral game” [ 1 ]. In Figure 1 b or d w e sho w starting configurations to b e referred to later. 1 Figure 1: P opular p eg solitaire b oards: (a ,b) the 33-hole cross-shap ed b oard, (c,d) the 15- hole tria ng le b oard. Only relativ ely recen tly in the history of the game hav e computers b een used as an in terface to pla y the ga me, as w ell as solv e the game. There are now dozens of v ersions of the game a v ailable for pla ying on y our computer or ev en y our cell phone. A computer v ersion of the game is in many w ays less satisfying than a ph ysical game. Ho w ev er, there a re some definite adv antages to play ing the game on a computer. The b oard can b e reset instantly , and y ou won’t b e c ha sing marbles tha t fall off the b oard! Y ou can tak e bac k a jump, all the w a y bac k to the b eginning if desired. This tends to mak e the game easier as y ou can more easily bac ktrac k from dead ends. The sequence of jumps leading to a solutio n can b e recorded a nd play ed bac k. The computer can also b e pro grammed to tell the user if t he jump they are considering leads to a dead end or not. Adding this abilit y to a computer v ersion of the g ame is tric ky , and most v ersions do not ha ve this abilit y . It is the goal of this paper to describ e efficien t tec hniques to enable a computer to p oin t out all go o d and bad jumps fr o m the curren t boa rd p osition. 2 Board t yp es and symmetry W e lab el the holes in the 33-hole b oard using Cartesian co ordinates (Figure 2 a), but with y incr e asin g dow n ward. F or the triangle b oards, we use “ske w-co ordinates” as sho wn in Figure 2 b. By adding 1 to eac h co ordinate, and conv erting the first to a letter, w e obtain the standard b oard lab elings used b y Beasley [ 1 ] and Bell [ 5 ] (for example the cen tral hole (3 , 3) in F ig ure 2 a becomes “d4”, see Figure 9 ). The 33-hole b oard has square symmetry . There are eight sym metry tra nsformations o f the b oard, giv en by the identit y , rotations o f 90 ◦ , 180 ◦ and 270 ◦ , and a reflection of t he b oard follo w ed by these 4 rotations [ 7 ] (the dihedral group D 4 ). The triangle b oards hav e 6-fold symmetry , with 3 p ossible rotations of 0 ◦ , 120 ◦ or 240 ◦ , plus a reflection follo w ed by a rotation (the dihedral group D 3 ). T o store a particular b oard p osition on a computer, we con v ert it to an integer b y taking one bit p er hole. The most o b vious w a y to do this is to tak e the boa rd, ro w b y row , top to b ottom, as in Figure 2 c. W e will use N to denote the total num b er of holes on the b oard 2 20 2 2,0 3,0 4,0 2,1 3,1 4,1 0,2 1,2 2,2 3,2 4,2 5,2 6,2 0,3 1,3 2,3 3,3 4,3 5,3 6,3 0,4 1,4 2,4 3,4 4,4 5,4 6,4 2,5 3,5 4,5 2,6 3,6 4,6 0,0 0,1 1,1 0,2 1,2 2,2 0,3 1,3 2,3 3,3 0,4 1,4 2,4 3,4 4,4 0,5 1,5 2,5 3,5 4,5 5,5 2 0 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 Figure 2: Hole co ordinates for (a) the 33-ho le cross-shap ed b oa r d, (b) the triangle b oards. (c) The w eigh ting of eac h hole to conv ert a b oard po sition to a binary co de. (the b oard size), so each b oard p osition is represen ted b y an N bit in teger. If b is a b oard p osition w e’ll denote this in teger represen tatio n by co de( b ). Man y computer langua ges use a 4- b yte in teger, the 33-hole b oard needs one more bit! Beasley [ 1 , p. 2 49] give s a tec hnique for storing a b o a rd p osition o n the 33-hole b oar d using 4 few er bits. This tec hnique is used in the ancillary progra m “p egs.cpp”. F or bo ards with more than 32 holes, w e usually split co de( b ) into sev eral 4-by te integers . The complemen t of a b oard p osition b is obta ined b y replacing ev ery p eg by a ho le (i.e. remo ving it), and replacing ev ery hole by a peg. The complemen t of b will b e denoted as b . W e note that co de( b ) = co de( f ) − co de( b ), where f is the b oard p osition where ev ery hole con ta ins a p eg, co de( f ) = 2 N − 1. The starting p osition for the “cen tra l ga me” in Figure 1 a therefore has co de 2 33 − 2 16 − 1. Tw o b oard p ositions are symmetry equiv alen t if one can b e con v erted to the other b y a symmetry tra nsfor ma t io n. This equiv alence relatio n in tro duces a set o f e quivalenc e classes of b oa rd p ositions, whic h w e call symmetry classes . The symmetry class of a b oa r d p osition do es not change after it is rotated or reflected. O ne w a y to c ho ose a repres en ta t iv e from eac h symmetry class is to tak e the o ne with the smallest co de. W e use the notatio n minco de( b ) to denote this opera t ion. F or example, the b oard p osition b in Figure 1 d has co de 2 0 + 2 1 + 2 2 + 2 8 + 2 13 = 8455, a nd the other 5 co des o btained b y sy mmetry t r ansformation are: 2183, 315 6 , 3904 , 25106 and 25280, so minco de( b ) = 2183. W e also ha v e minco de( b ) = (2 15 − 1) − maxco de( b ) = 7487. 3 Single v acancy to single surviv or pro blems A p eg solitaire problem whic h b egins with o ne p eg missing, with the goal to finish with one p eg, will b e called a single v acancy t o single survivor pro blem, abbreviated SVSS. When the star t ing v acancy ( x s , y s ) and finishing hole ( x f , y f ) are the same, the SVSS problem is called a complemen t problem , b ecause the starting and ending b oard p ositions are complemen ts of o ne another. A simple parit y argumen t giv es a necessary condition fo r solv ability of a SVSS problem [ 1 , 3 Chapter 4 ]. On a square lattice (like the standard 33-ho le b oard) , the requiremen t is that x s and x f m ust differ by a m ultiple o f 3, or that x s ≡ x f (mo d 3 ) , and y s ≡ y f (mo d 3 ) . Starting a nd ending b oard p ositions satisfying the ab ov e conditions are said to b e in the same p osition class (a second equiv alence class). On a triang ular lattice, the requiremen t is w eak er: x s + y s ≡ x f + y f (mo d 3 ) 1 . The main result is a p e g solitair e jump do es not change the p osi tion class , th us an entire p eg solita ir e game is play ed in the same p osition class. W e will not go into the theory of p osition classes, the reader should see Beasley [ 1 , Chapter 4] or Bell [ 5 ] for triangular p eg solitaire. It is intere sting to see what happ ens to the p osition class after the b oard is rotated or reflected. F or the cen tral game on the 33-ho le b oard (F ig ure 1 a), the p osition class is not c hanged b y rotatio ns or reflections of the b oar d. If w e b egin with (3 , 3) v acant w e can finish at (3 , 3), or the ro tationally equiv alen t holes (3 , 0), ( 0 , 3), (6 , 3) and (3 , 6). Any b oard p osition whic h b egins from any o f these fiv e ho les is in t he p osition class of one p eg in the cen ter. Moreo ver, if w e reflect and/or rotate the b oard at an y time during the game, it remains in the same p osition class. W e call an y SVSS problem b eginning and ending at an y of these holes “Ty p e A”; their solutions are a ll in terconnected (share the same boa rd p ositions). Type C 2 2 1 2 2 Type A 4 4 4 3 3 4 4 3 3 4 4 4 Type B 7 7 6 7 5 7 6 5 5 6 7 5 7 6 7 7 Figure 3 : The three t yp es of SVSS problem on t he standard 33-hole b oard. More commonly , the position class do es change after the b oard is rotated or r eflected. “T yp e B” problems are shown in Figure 3 b. In this case when w e rota t e the b oar d, the p osition class c hanges, but only among the 4 with single p eg represen tativ es in the holes sho wn in Figure 3 b. Another w ay to lo ok at Figure 3 b is tha t w e can b egin with ( x s , y s ) at any “ 3” or “4”, a nd finish a t any “3” or “4” , if we allow p eg solitaire jumps plus rotations and reflections of the b oar d. The third “T yp e C” problems a r e shown in Figure 3 c. The three problem t ypes a r e in a sense completely separate—it is nev er p ossible to mov e from a SVSS problem of one t yp e to another, ev en if y ou ar e allo w ed to rota te or reflect the b oard. Wiegleb’s b oard (F igure 4 ) is an extension of the standard 33-ho le b o ard and has 45 ho les [ 1 , p. 199–201 ]. Wiegleb’s b oard also has three problem t yp es, but there are more SVSS problems p ossible (36 in all, see [ 3 ]). Fig ure 5 sho ws the 6 × 6 square b oa rd, whic h also has three problem t yp es. In general, an y square-lattice b oard will ha v e three problem t yp es. 1 Both these conditions assume that the full and empt y b oar ds are in the same p osition class, a b oard satisfying this is c a lled a null-class b oard (see Beasley [ 1 ]). All the b oards w e will c o nsider are n ull-class, except for the tria ngle b oard of side 4. 4 Type C 2 2 1 2 2 Type A 5 5 4 4 5 4 3 3 4 5 5 4 3 3 4 5 4 4 5 5 Type B 9 8 8 7 8 6 8 9 7 6 6 7 9 8 6 8 7 8 8 9 Figure 4: The three types of SVSS problem on Wiegleb’s 45- hole b oard. Type C 1 1 1 1 Type A 4 3 3 4 3 2 2 3 3 2 2 3 4 3 3 4 Type B 6 6 6 5 5 6 5 5 5 5 6 5 5 6 6 6 Figure 5: The three types of SVSS problem on t he square 6x6 b oard. In triangular p eg solitaire the situation is somewhat differen t, for one thing there is only one t yp e of pro blem, Ty p e A. On the triangle b oa rd of side n , if n ≡ 1 (mo d 3), the b oard is not n ull- class and no complemen t problem can b e solv ed (see Bell [ 5 ]). The only SVSS problem on the 1 0 -hole triangle boa r d tha t is solv able is of t he form: v acate (0 , 1) finish at (1 , 1). This giv es only one ty p e of problem that is solv able (see Figure 6 a), and an y problem starting from an unmark ed hole in F igure 6 a cannot b e solved to o ne p eg. Type A 1 1 1 1 1 1 Type A 2 1 1 3 4 3 1 4 4 1 2 1 3 1 2 Type A 3 1 1 2 4 2 2 5 5 2 1 4 5 4 1 3 1 2 2 1 3 Type A 1 1 2 3 2 1 3 3 1 1 2 1 Figure 6: SVSS pro blems on 10, 15, 21 hole triangle b oards, and the 12-hole truncated triangle boa r d. The shaded holes sho w starting v acancies all in the same po sition class. The 15- hole triangle b oard is n ull-class (Fig ure 6 b). Here there are 4 differen t starting lo cations, the “standard starting v acancies” for eac h of the 4 are shaded. Aga in all problems 5 are of type A, in a sense all problems on this b oard are interrelated ( we shall see that they all m ust be considered together). The 21- hole t r ia ngle b o a rd is also n ull-class (Figure 6 c), and con ta ins 5 differen t starting lo cations. On this b oard it is p ossible to start with an y p eg missing, and finish at an y hole using p eg solitaire jumps, plus rotating and flipping the b o a rd. The fina l b oard in Figure 6 d is simply the 15- hole triangle b oard with the three cor ner holes remov ed. This “12 -hole truncated triangle” bo a rd is a go o d test case b ecause all SVSS problems are solv able on it. It is, in fact, the smallest r o tationally symmetric b oard with this prop erty . Here are sev eral p eg solitaire problems we are intere sted in solving: 1. The complemen t problem : F rom a starting v acancy ( x s , y s ), execute an arbitra r y n umber of jumps, then determine if the b oard p osition can b e reduced to one p eg at ( x s , y s ). 2. The general SVSS problem : F rom a starting v acancy ( x s , y s ), execute a n arbitrary n umber of jumps, then determine if the bo ard p osition can b e reduced to one p eg (an ywhere on the b oard). 3. The general problem : Giv en a config ura tion of p egs, determine if it can b e reduced to one p eg (an ywhere on the b oard). W e will consider primarily the first tw o problems in this pap er. W e also w an t to solv e these problems quic kly—ideally within a we b brow ser. In determining if a j ump leads to a dead end or not, a delay of one second is unacceptable. It is imp ortant to r ealize that problems #2 and #3 are differen t. F or example, on the 33-ho le b oard, a popula r problem to solv e is “cross” (F igure 1 b). This bo a rd p osition is solv able to one p eg, but can nev er app ear in the solution to any SVSS problem. How do w e kno w t his? Because the complemen t of this b oard p osition cannot b e reduced to o ne p eg. See Bell [ 4 ] to clarify wh y SVSS b oard p ositions mu st ha ve t his prop erty . A subtle p oin t is that problems #1 and #2 are intimately asso ciated with the shap e of the b o a rd, while problem #3 do es not hav e to b e asso ciated with any b oard—in the most general con t ext w e could consider problem #3 o n a n infinite b oar d. In this sense w e can see that pro blem #3 is differen t and more general. A fair question is, wh y no t go fo r the most general and difficult problem #3? The reason is that the complemen t pro blem #1 and general SVSS problem #2 are significan tly easier, b ecause w e can tak e adv an tage of sp ecial prop erties of their solutions. 3.1 Computer solving tec hniques The simplest tec hnique for solving a p eg solitaire problem on a computer is to store the sequence of completed jumps, t o gether with the current b oard position. One then p erfo rms a depth-first searc h b y jump (extending the jump sequence and back trac king when no further jump is p ossible). The 15-hole triangle b oard can be easily solve d using this tec hnique, but it is m uc h slo w er on the 33-hole b o ard. The reason is that there are a large n um b er of 6 jump seq uences that r esult in the same b oard p o sition, so there is a tremendous amoun t of duplicated w ork. This difficult y can b e remo v ed b y storing b oar d p ositions seen previously in a hash table or binary tree. An impro v ed tec hnique is to stop recording the jump sequence, and lo ok at the whole problem as a sequence of b oard p ositions (see [ 1 ]). Given a set of b oard p ositions F , w e denote by D ( F ) the set of b oard p ositions that can b e obtained b y p erforming ev ery p ossible jump to ev ery elemen t of F . W e call D ( F ) the descendan ts of F . As a programming task calculating D ( F ) is straightforw ard. F or example the set F can b e stored o n the disk as a sequence of integer co des, w e read eac h co de and con v ert it to a b oard p osition. F rom this b oard p osition w e execute ev ery p o ssible jump, resulting in a large num b er of b oard p ositions whic h are stored in a binary tree (or hash table) to remov e duplicates. This binary tree can b e dump ed to a file as a sequence of co des, the set D ( F ). The problem that ev en tually o ccurs is that the binary t r ee b ecomes to o large to fit into memory 2 . A t this p oin t the problem is easily split in to p smaller pieces that are calculated separately (or in para llel). Let p b e a prime num b er, c hosen so that 1 /p of the binary tree fits in to memory . W e now go through the b oard p ositions in F as b efore, but instead of storing eac h descendan t in a binary tree, we con vert it to a co de and write that co de to a temp orary file n um b ered co de( b )% p = co de( b ) (mo d p ). Here t he “%” op erat o r represen ts the remainder up on division b y p (as in C). After all b oard p ositions in F hav e b een consid- ered, w e no w go bac k through eac h of the p tempora ry files, filling a binary tree for each p to remov e duplicates and writing the unique b oard po sitions to the disk. In most cases we do not wan t to store tw o b oard p ositions that are in the same symmetry class. F or example, for the cen t ral game (Figure 1 a), there are four first j umps, but these result in iden tical b oard p ositions whic h are rotations of one another. A con v enien t w a y to select a single represen tativ e from the symmetry class is to use the one with the smallest co de. In the ab o v e algorithms, we use minco de( b ) in place of co de( b ). In what follows, we will denote sets o f b oard p ositions b y capital letters. F or a set of b oard positions F , w e denote b y | F | t he num b er of elemen ts in the set, and F is the set of complemen ted b oa r d p ositions. In other words b ∈ F if and only if b ∈ F . Often these sets will con tain only b oard p ositions with the same num b er of p egs, so w e ado pt the conv en tio n that a subscript (when presen t) m ust b e the n um b er of p egs. F n , b y this con v en tion, con tains only b oard p ositions with n p egs. W e can therefore deduce tha t all b oards in D ( F n ) ha v e n − 1 pegs and all boa rds in F n ha v e N − n p egs (recall tha t N is the size of the b oard). This con ven tion is useful in understanding these sets, for example w e can immediately conclude that F n ∩ F m = ∅ when n 6 = m . W e can also consider pla ying the game “bac kwards”, whic h in this notation lo oks lik e this: let b b e a b oard p osition with n pegs, a nd B n = { b } . Then D ( B n ) con tains all b oard p ositions where b can b e reac hed by executing one jump. W e note that all elemen ts of B n ha v e N − n p egs, D ( B n ) ha v e N − n − 1 p egs, and D ( B n ) ha v e N − ( N − n − 1) = n + 1 p egs, as expected. 2 On Wiegleb’s 45-hole b oar d, after 22 jumps the tree cont ains o ver 2 billion e le men ts. 7 Let b s b e the starting b oard p osition with one p eg missing, and let b f b e the target b oard p osition with one p eg. Let F N − 1 = { b s } and B 1 = { b f } . W e then define: F n = D ( F n +1 ) , n = N − 2 , N − 3 , . . . , 1 (1) Note that, as required of our notatio n, ev ery elemen t of F n has exactly n p egs. This pro duces a “ pla ying for ward” sequence of sets F N − 2 , F N − 3 , . . . , F 1 . W e a re calculating the no des in the “ga me tree”, but ha v e lost all information ab out the links connecting them (ho w ev er, this link infor ma t io n is easily reco v ered). The pro blem has a solution if and only if b f ∈ F 1 . A sequence of sets can also b e obtained from the finishing b o a rd p o sition b f b y “playin g bac kwards” f r om B 1 = { b f } , B n = D B n − 1 , n = 2 , 3 , . . . , N − 1 (2) Again, ev ery elemen t of B n has exactly n p egs, and the problem has a solution if and only if b s ∈ B N − 1 . It is w o rth noting that the sets B n con ta in every b oard p osition whic h can b e reduced to b f on this b oard. Th us, the sets B n can b e used to solv e an y problem #3 (p. 6) whic h finishes at b f . If w e calculate B n o v er all p ossible one p eg finishes, w e can solv e an y problem #3 (on this b oard). The set of “winning boa rd p ositions” with n p egs is then defined as W n = F n ∩ B n (3) If w e hav e any solution , and play this solution un t il reac hing b oard b with n p egs, then it m ust b e that b ∈ W n . The sets W n tend to b e m uc h smaller than F n and B n . These winning sets W n are t he n uggets of gold t ha t w e seek, b ecause they will enable us to quic kly recognize when a jump leads t o a dead end. As a practical matter, to find W n it is not necessary to calculate eve ry F n and B n for eac h n b et wee n 1 and N − 1 and p erform their inters ection (intersec ting tw o sets with p o t entially billions o f elemen ts is not a trivial computation). Supp ose we can calculate the forward sets to F k , and the bac kw ar d sets to B k for some k b etw een N − 1 and 1. If the problem has a solution, then W k = F k ∩ B k is not empt y . W e then compute W k − 1 , W k − 2 , . . . , W 1 = { b f } recursiv ely using W n = D ( W n +1 ) ∩ B n for n = k − 1 , k − 2 , . . . , 1 , (4) and W k +1 , W k +2 , . . . , W N − 1 = { b s } using W n = F n ∩ D ( W n − 1 ) for n = k + 1 , k + 2 , . . . , N − 1 . (5) T o calculate using equation ( 5 ), we take each elemen t of W n − 1 , complemen t it, calculate all descendan ts and complemen t each. This yields the set D ( W n − 1 ), and we now sa ve eac h elemen t whic h is in common with F n , giving us W n . The recursiv e calculations ( 4 ) and ( 5 ) are m uc h easier than calculating all F n and B n b ecause the sets W n tend to b e orders of magnitude smaller. The determination of W n using ( 4 ) and ( 5 ) is considerably faster than the initial task of calculating the sets F k and B k . 8 Equations ( 4 ) and ( 5 ) do no t follo w directly from ( 3 ), so here we justify that they are correct. F or ev ery b oard p osition w n ∈ W n , there m ust exist a sequence of jumps from the starting b oard p o sition b s to w n (this is a direct consequence of the fact that w n ∈ F n ), and a sequence of jumps from w n to the finishing b oard po sition b f (b ecause w n ∈ B n ). T ak en a ll together, these giv e t he sequenc e of jumps in a solution. Therefore, asso ciated with ev ery w n ∈ W n there exists (at least one) sequence of N − 1 b oard p ositions, b s = w N − 1 , w N − 2 , . . . , w n +1 , w n , w n − 1 , . . . , w 2 , w 1 = b f whic h show the state of the b oard as the solution is pla y ed. F or ev ery elemen t w k in this sequence , w k ∈ W k , w k ∈ D ( W k +1 ) and w k ∈ D ( W k − 1 ). These la st t w o statemen ts are exactly what is needed to pro v e ( 4 ) and ( 5 ) from ( 3 ). Finally , w e note that the sets F n , B n and W n can b e defined in tw o subtly differen t w a ys. First, they can simply b e sets of b oard p ositions. If b s is the starting p osition for the cen tral game (Fig ure 1 a), then F 32 = { b s } , and F 31 has 4 elemen ts whic h ar e rotations of o ne another. W e will sometimes refer to these sets as “ r a w F n ”. In most cases, ho w eve r, w e will conside r F n , B n and W n as sets of symmetry classes. Now the set F 31 only has a single elemen t, whic h can b e tak en a s an y represe n ta tiv e o f this symme try class, and generally w e c ho ose the one with the smallest co de(). These sets are called “ symme try reduced” F n . If w e refer to an unqualified F n or W n it can be assumed to be symmetry reduced. 4 The complemen t prob l em F or a complemen t problem, we ha ve b s = b f , so that B 1 = F N − 1 , and it fo llo ws from ( 1 ) and ( 2 ) that pla ying the game forward and bac kward amounts to t he same thing, B n = F N − n , (6) W n = F n ∩ F N − n , (7) and W n = W N − n (8) Equation ( 8 ) states that the sets of win n ing b o ar d p os i tions ar e c omplem ents of one an other . This is a remark able result, it is due to a fundamen tal symmetry b et w een p egs and holes 3 . F or a complemen t problem, we only need to store half the winning b oard p ositions. In order to calculate W n the work is halv ed as well, for w e need only calculate the forw ard sets F n do wn to k = ⌊ N / 2 ⌋ . After p erforming the in tersection ( 7 ), the remaining W n are then calculated using Equation ( 4 ), whic h can b e written using forward sets as W n = D ( W n +1 ) ∩ F N − n for n = k − 1 , k − 2 , . . . , 1 . (9) 3 While the for w ard ga me jumps one peg ov er another p eg into a hole, we can consider the backward game as jumping o ne hole over ano ther hole in to a p eg! See “Playing Backwards a nd F orwards” [ 2 , p. 8 17-8]. 9 Is storing winning boar d p ositions the most efficien t tec hnique? During the start of a game, it do es not seem so, b ecause all b oard p ositions that can b e reac hed are winning. P erhaps it is b etter to store “losing b oard p ositions”, or p ositions f rom which a one p eg finish a t the starting hole cannot b e reac hed? W e could define the set o f “losing b oard p ositions” with n p egs as those elemen ts of F n whic h are not in W n . It w ould b e more efficien t to store only losing b o a rd p ositions whic h are one jump aw a y from a winning b oard p osition. Th us, w e define L n = D ( W n +1 ) − W n (10) T a ble 1 sho ws the size s of F n , W n and L n for the 15 and 21-hole triangle b oards. All winning b oard p o sitions for any corner complemen t problem can b e iden tified b y storing just 95 b oard p ositions (15-hole b o ard) or 26 , 401 boa rd p ositions (21-hole b oard). If we store losing b oard p ositions as defined b y Equation ( 10 ), we need to store mo r e than four times as man y b oard p ositions. 15-hole tria ngle b oard 21-hole tria ngle b oard Ra w Symmetry reduce d Symmetry reduced n (p egs) | F n | | F n | | W n | | L n | | F n | | W n | | L n | 20 1 1 0 19 1 1 0 18 4 4 0 17 23 23 0 16 117 117 0 15 522 503 19 14 1 1 1 0 1,881 1,690 185 13 2 1 1 0 5,286 4,328 907 12 8 4 2 2 11,754 8,229 3,288 11 35 19 9 4 20,860 11,506 8,478 10 122 62 18 20 28,697 11,506 14,70 1 9 293 149 29 43 29,784 8 ,229 16,856 8 530 268 35 86 23,263 4 ,328 13,063 7 679 344 35 94 14,039 1 ,690 7,267 6 623 317 29 89 6,683 503 3,005 5 414 215 18 49 2,545 117 935 4 212 112 9 29 774 23 211 3 75 39 2 7 168 4 34 2 18 10 1 1 28 1 4 1 4 3 1 1 5 1 1 T o tal 3,016 1,544 † 95 425 146,434 † 26,401 68,954 T a ble 1: Size of F n , W n and L n for the corner complemen t problem on the 15 and 21 -hole triangle boa r ds. † Only half of the W n need to b e stored, due to Equ ation ( 8 ). 10 F or the corner complemen t pr o blem on the 15-hole triangle b oard, the winning boa rd p osi- tions are W 2 n . Note that the subscript refers to the num b er of p egs, while the sup erscript refers to the n umber assigned this starting v acancy in Figure 6 . The sets W 2 n giv e us a sim- ple tec hnique fo r determining if we a re “on trac k” to solv e the corner complemen t problem. Supp ose the curren t b oard state is b . 1. If b con tains more than ⌊ N / 2 ⌋ = 7 p egs, complemen t the b oard p osition. The b oard p osition now has n p egs where 1 ≤ n ≤ ⌊ N / 2 ⌋ . 2. Calculate mincode( b ). 3. If minco de( b ) ∈ W 2 n , then the complemen t problem can b e solv ed f rom the curren t b oard position, otherwise it cannot. Notice that minco de( b ) 6∈ W 2 n do es not necessarily imply t hat the b oard p osition cannot b e solv ed to one peg, just not to one p eg at the starting lo c ation . W e also giv e the ab ov e algorithm in pseudoco de: W[1] = {1} ! The set W_1^2 W[2] = {10} ! The set W_2^2 W[3] = {28, 112} ! W_3^2 W[4] = {23, 58, 85, 120, 1108, 1616, 2076, 2210, 2272} W[5] = {31, 93, 115, 601, 1054, 1138, 1140, 1562, 1648, 2183, 2218, 2245, 2280, 2348, 2472, 2616, 2728, 2819} W[6] = { 125, 633, 1086, 1111, 1594, 1621, 2191, 2253, 2275, 2289, 2343, 2467, 2589, 2723, 2785, 2841, 2889, 3126, 3250, 3298, 3428, 3634, 3845, 4220, 4270, 4282, 4691, 4728, 4817} W[7] = {1567, 1651, 2235, 2365, 2413, 2537, 2731, 2793, 3159, 3196, 3320, 3374, 3388, 3607, 3642, 3667, 3669, 3704, 3859, 3921, 4215, 4339, 4341, 4469, 4701, 4849, 5302, 5350, 5746, 5810, 6881, 6985, 10053, 10065, 12065} ! board is the curre nt board posi tion ! side is the triang le board side (mus t be 5) onePeg FinishP ossible(board, side) { n = Coun tPegs(b oard) tothol es = si de*(side +1)/2 ! sho uld evaluate to 15 if (n > totho les/2) the n { mincod e = 2^t otholes - 1 - GetMaxCode( board) n = tot - Count Pegs(bo ard) } else minco de = Get MinCode (board) for (j=0 ; j 0 (o r that the n umber of solv able complemen t problems p = 0), so that the only sets around are W 0 n = W n . These sets can b e calculated quite easily (ev en b y hand), and are sho wn in T a ble 4 . Here w e also see a b oard where the t o tal n umber of holes N = 10 is eve n, so that W 0 5 = W 0 5 is equal t o its o wn complemen t. W e can see that this is in fact the case, as the four b oard p ositions in W 0 5 are listed in pairs that are complemen ts of one other. W e must b e careful to in terpret the b oard p ositions in W 0 5 as symmetry classes , the complemen t of t he b oa rd position with co de 94 has co de 2 10 − 1 − 94 = 929, a boa rd position in the same symmetry class as the b oard with co de 103. W e conclude from T able 4 that only 10 essen tially differen t b oard p ositions (o r their complemen t) can app ear during a solution to any SVSS pr o blem on this b oard (we only nee d half of the set W 0 5 ). 15 6 The complemen t plus ge n eral S VSS pro blem W e no w sho w ho w to solv e either the complemen t problem (#1), o r the general SVSS problem (#2), with very little additiona l storag e ov er the general SVSS problem. Equation ( 11 ) sho ws that these tw o problems are closely related. The only difficulty in v olve s storing b oard p ositions efficien tly (without duplicates), and dealing with the degeneracies introduced in section 4.1 . In this section w e use as an example the 15-hole triangle b o ard. W e deal first with the storage problem. Ho w can we store all b oard p ositions in W i n without duplication? Here w e are considering all the problems of a certain ty p e on a b oa r d, and i = 1 , 2 , . . . , p ranges o v er the to tal n um b er of problems of this type. On the 15- hole triangle b oard, there is only one ty p e ( shown in Figure 6 b) with p = 4 differen t problems. The ob vious solution is to tak e all p ossible com binations of the 4 problems, 2 p = 16 p ossibilities, and for eac h combination w e store all b oards common to this com bination of problems. W e can think of these sets W n with a sup erscript given not b y the problem num b er i , but the index o f the combination of complemen t problems t hat this b oard p osition can o ccur in (ranging from 0 to 16). Index 0 remains the same as problem 0: W 0 n = W index =0 n is the set of n -p eg b oard p ositions that can o ccur during a SVSS pro blem, but not in an y complemen t problem. | W index n | for index = 0 t o 7 P egs ( n ) 0 1 2 3 4 6 7 T o tal 1 1 1 1 0 1 0 0 4 2 1 0 0 1 2 0 0 4 3 3 0 0 1 7 0 1 1 2 4 5 0 0 4 19 1 4 33 5 10 0 1 8 49 4 8 80 6 7 0 2 11 93 6 13 132 7 4 0 2 12 129 7 18 172 T o tal 31 1 6 3 7 300 18 44 437 T a ble 5: A coun t of winning b oard p ositions W index n on the 1 5 -hole triangle b oard. i n dex ranges fro m 0 to 15 but 5 and tho se b ey ond 7 ar e all empty . F or example, since index = 7 = 0111 in binary , then W index =7 n con ta ins all n -p eg p ositions that are common to problems 1, 2 and 3. W e note the since pro blem 4 is unsolv able as a complemen t problem [ 5 ], W 4 n = ∅ and all sets W index n with index b etw een 8 and 15 are also empt y . A tric kier question is ho w to resolv e the degene racy at the (0 , 3) starting lo cation. The sets W 1 n cannot b e symmetry reduced, y et W 2 n and W 3 n are symmetry reduced, and W 4 n = ∅ . W e see fr om Figure 7 that W 1 n con ta ins co de 50, while W 2 n con ta ins minco de 28, a b oard p osition in the same symmetry class. The solution is to use a n algorithm whic h kee ps all co des in W 1 n but remo v es all symmetry equiv a len ts in the in tersecting sets. This is the reason that the degenerate starting lo cations are indexed first. 16 T a ble 5 summarizes the num b er of b oard p ositions b y index and num b er of p egs n . The total n um b er of b oard p ositions o ver a ll sets is 437, whic h is only 10 more than are neede d to solv e the general SVSS problem b y itself. There are 10 boa rd p ositions in W 1 n whic h are reflections of other b oard p ositions in W 1 n (an example whic h is useful to c hec k b y hand are the b oard p ositions with co des 93 and 563, these 5-p eg b oard p ositions end up in index 7). The first row of T able 5 t ells us whic h complemen t problems are solv able, na mely those with index 1 (problem 1, the (0 , 3) complemen t), 2 (problem 2, the (0 , 0) complemen t ) and 4 (problem 3, the (2 , 4) complemen t). Aga in, the fact that W 8 1 = ∅ is equiv alen t to t he statemen t that pro blem 4, the (1 , 2) complemen t, is not solv able. 2183(min) (0,3) complement (0,0) complement (2,4) complement not in any complement index=0 index=1 index=2 index=3 index=4 index=5 index=6 index=7 (empty) (empty) 1480 ~ 181(min) 4291 ~ 1138(min) 3272 ~ 31(min) 7304 ~ 59(min) 115(min) Figure 8: A V enn diag ram show ing sample b oards with 5 p egs b y index. Figure 8 sho ws represen tativ e 5- p eg b oard p ositions in W index 5 for v alues of the index 0 to 7. Let us interpre t t wo of the b oard p ositions in this diagram. The b oard p osition with co de 1480 is in index 0, meaning that this b oard p osition cannot app ear in an y complemen t problem. This b oard p osition has a minco de of 181 . W e can finish with one p eg from t his b oard p osition at (0 , 0) or (0 , 3), but w e cannot start f r o m either of these holes and r each this b oa rd p osition. But it m ust b e p ossible to reac h t his b oard p osition from some start, and it turns out this start is (2 , 4). The b oard p osition with index 7 is 2183, whic h is the mincode. W e can play f r o m this b oard p osition to finish a t (0 , 0), (0 , 3), (3 , 3) or (2 , 4), and w e can also reach this b oar d p osition starting from (0 , 0), (0 , 3) or (2 , 4 ). Therefore, this b oard po sition can b e reac hed during an y of the three (solv able) complemen t problems. The b oard p osition with index 6 is 115, whic h is the mincode. W e can play fro m this b oard p osition to finish at (0 , 0), (0 , 3) or (2 , 4), a nd w e can reach this b oard p o sition from (0 , 0) 17 or (2 , 4). Therefore, this b oard p o sition can b e reac hed during the solution to the (0 , 0) or (2 , 4) complemen ts, so is in index 6. W e can see in Figure 8 (and T able 5 ) tha t the in d ex 1 and index 5 sets are empt y , wh y is that? The reason is that W 2 1 con ta ins a single b oard p o sition with minco de 10 and p egs at (0 , 1) and (0 , 2 ) . This means that all solutions to the (0 , 3 ) complemen t m ust b e gin and finis h with the jump from (0 , 1). Therefore, an y b oard p osition whic h can b e reac hed during the (0 , 3) complemen t (except for the starting b oard p osition) can b e reached during the (0 , 0) complemen t 5 . This is exactly what it means for the index 1 and index 5 sets to b e empt y , except for the one peg starting b oard po sition for the (0 , 3) complemen t. W e now presen t pseudo co de for iden t ificatio n of winning b oa rd p ositions for either the com- plemen t problem (#1) or the general SVSS problem (#2): W[5][1 ] = {16 ,64,1,8} ! W^ 1, index=0,1 , .. . 15, for the 15-hole triangl e board End[5] [1] = {1,2 ,3,3,4, 4,4,4,4,4,4,4,4,4,4,4} ! End s of each index 0- 15 ... see Trian gleWinn ing/Triangle5ByIndex.txt ... ! board is the curre nt board posi tion ! side is the triang le board side (4,5 , or 6) ! i is the number of this SVSS proble m ! ksym is the symmet ry code of the sta rting board pos ition ! comp is true for comple ment pro blems, oth erwise any finish is assumed proble mIsSolv able(board, side , i, ksy m, co mp) { int code [6] tothol es = si de*(side +1)/2 if (side ==4) { ! 10-h ole triangle bo ard topind ex = 1 degen = 0 } if (side ==5) { ! 15-h ole triangle bo ard topind ex = 2^ 4 ! po wer set of 4 problems degen = 1 ! number of degen erate pr oblems } if (side ==6) { ! 21-h ole triangle bo ard topind ex = 2^ 5 ! po wer set of 5 problems degen = 2 ! number of degen erate pr oblems } n = Coun tPegs(b oard) if (n > tot/2 ) the n { code[0 ] = 2^t ot - 1 - Co de(boar d) n = tot - Count Pegs(bo ard) } else code[ 0] = Cod e(board ) ! Get the 6 symmet ry code s, code[0] to co de[5] code[1 ] = rot atecode( code[0]) 5 The co n verse is not true, do y o u s e e why? The (0 , 0) complement can b egin with a jump from (0 , 2), but end with a jump from (2 , 2). 18 code[2 ] = rot atecode( code[1]) code[3 ] = ref lectcode (code[2]) code[4 ] = rot atecode( code[3]) code[5 ] = rot atecode( code[4]) if (comp ) { ! comp lement problem kStart = 0 kEnd = 6 if (i<=d egen) { kStart = kSym kEnd = kSym + 1 } for (ind ex=1; in dex
Original Paper
Loading high-quality paper...
Comments & Academic Discussion
Loading comments...
Leave a Comment