Pavel Dvorák Advanced Methods of Searching the Game Tree of 3
Total Page:16
File Type:pdf, Size:1020Kb
Charles University in Prague Faculty of Mathematics and Physics BACHELOR THESIS Pavel Dvoˇr´ak Advanced methods of searching the game tree of 3-dimensional Tic-Tac-Toe Department of Applied Mathematics Supervisor of the bachelor thesis: RNDr. Tom´aˇsValla, Ph.D. Study programme: Computer Science Specialization: General Computer Science Prague 2013 I would like to thank my supervisor Tom´aˇsValla for introducing me to combinato- rial game theory (together with Robert S´amal)andˇ for organizing our mini game seminary, where we discussed our game-theoretical thesis with Jitka Novotn´aand Pavel Vesel´y.I also would like to thank Michaela Zaloudkov´aforˇ the correction of my English. I declare that I carried out this bachelor thesis independently, and only with the cited sources, literature and other professional sources. I understand that my work relates to the rights and obligations under the Act No. 121/2000 Coll., the Copyright Act, as amended, in particular the fact that the Charles University in Prague has the right to conclude a license agreement on the use of this work as a school work pursuant to Section 60 paragraph 1 of the Copyright Act. In Prague date ............ Pavel Dvoˇr´ak N´azevpr´ace: Pokroˇcil´emetody prohled´av´an´ı hern´ıho stromu trojrozmˇern´ych piˇskvorek Autor: Pavel Dvoˇr´ak Katedra: Katedra aplikovan´ematematiky Vedouc´ıbakal´aˇrsk´epr´ace:RNDr. Tom´aˇsValla, PhD., Informatick´y´ustav Uni- verzity Karlovy Abstrakt: V t´etopr´acizkoum´amepoziˇcn´ıhry, zejm´enapak v´ıcerozmˇern´epiˇskvorky. Porovn´av´ameexistuj´ıc´ıpokroˇcil´ealgoritmy (Pn-search, Db-Search, λ-search) pro ˇreˇsen´ıpozic v poziˇcn´ıch hr´ach. Algoritmy nasazujeme na dom´eny her 43 a 53, coˇzjsou prvn´ınetrivi´aln´ıpˇripadytrojrozmˇern´ych piˇskvorek. Paralelizujeme Pn- search pro pˇr´ıpad, kdy existuje v´ıce poˇc´ateˇcn´ıch pozic. Pn-search aplikujeme jako jednovl´aknovou ´ulohu a ˇreˇs´ıme,jak sd´ılettranspoziˇcn´ıtabulku s vyˇreˇsen´ymi pozicemi. Hlavn´ıma ˇcistˇeteoretick´ymv´ysledkem je charakterizace grupy auto- morfism˚ukombinatorick´ekrychle nd se stejnou mnoˇzinoulini´ıjako v´ıcerozmˇern´e piˇskvorky. Toto je zobecnˇen´ıSilvera [The American Mathematical Monthly, Vol. 74, No. 3, 1967], kter´ypopsal automorfismy hry 43. Kl´ıˇcov´aslova: v´ıcerozmˇern´epiˇskvory, paralelizace, automorfismy Title: Advanced methods of searching the game tree of 3-dimensional Tic-Tac- Toe Author: Pavel Dvoˇr´ak Department: Department of Applied Mathematics Supervisor: RNDr. Tom´aˇsValla, PhD., Computer Science Institute of Charles University Abstract: In this thesis we study positional games, especially multidimensional tic-tac-toe. We compare present advanced algorithms (Pn-search, Db-search and λ-search) for position solving in positional games. We apply the algorithms on the domain of 43 and 53 games, which are the first nontrivial cases of 3-dimensional tic-tac-toe. We parallelize Pn-search for cases when there are more starting po- sitions. We apply Pn-search as a single-thread task and we solve how to share the transposition table with solved positions. Our main and clearly theoretical result is the characterization of the group of all automorphisms of combinatorial cube nd with the same set of lines as multidimensional tic-tac-toe has. This is a generalization of Silver [The American Mathematical Monthly, Vol. 74, No. 3, 1967], who characterized the automorphisms of the game 43. Keywords: multidimensional tic-tac-toe, parallelization, automorphisms Contents Introduction 3 1 Positional games 5 1.1 Tic-tac-toe ............................... 7 1.1.1 Qubic solving ......................... 7 2 Game tree searching algorithms 9 2.1 Proof-Number search ......................... 9 2.1.1 AND/OR Tree ........................ 9 2.1.2 Algorithm description .................... 10 2.1.3 Transposition table ...................... 12 2.1.4 Weak Proof-number search . 15 2.2 Dependency-based search ....................... 15 2.2.1 Structure states ........................ 15 2.2.2 Paths ............................. 16 2.2.3 Traversing the key classes . 17 2.2.4 Db-search and Qubic ..................... 17 2.3 λ-search ................................ 19 3 Solving Qubic 23 3.1 Properties of Qubic and its game tree . 23 3.2 Choice of algorithm .......................... 23 3.3 Program architecture ......................... 24 3.3.1 Parallelization ......................... 24 3.4 Our Result ............................... 25 3.4.1 Starting depth ......................... 25 3.4.2 Single-thread algorithms ................... 25 3.4.3 Parallel algorithm ....................... 25 3.5 Discussion ............................... 27 3.5.1 Automorphisms ........................ 27 3.5.2 Distributed calculation .................... 27 3.5.3 Other games .......................... 28 4 Automorphisms of the game nd 29 4.1 Introduction .............................. 29 4.2 More formally ............................. 29 Td 4.2.1 Order of 2 .......................... 30 4.3 Automorphisms of (2k)3 ....................... 31 4.3.1 Line and point classes .................... 31 T3 4.3.2 Generator of 2k ....................... 34 4.4 Automorphisms of nd ......................... 38 4.4.1 Corners, main diagonals and edges . 38 Td 4.5 Generator of the group n ...................... 42 Td 4.6 Order of the group n ........................ 45 Conclusion 49 1 Bibliography 51 List of Figures 53 List of Tables 55 List of Abbreviations 57 A Solving program documentation 59 A.1 Introduction .............................. 59 A.2 Algorithms ............................... 59 A.2.1 Pn-search ........................... 59 A.2.2 Db-search ........................... 61 A.2.3 λ-search ............................ 63 A.2.4 Transposition table ...................... 64 A.2.5 Automorphisms ........................ 66 A.2.6 Code generating ........................ 67 A.3 Data Structure ............................ 68 A.3.1 Game representation ..................... 68 A.3.2 Vertex ............................. 69 A.3.3 DbVertex ........................... 70 A.4 Settings ................................ 70 A.5 Inputs and Outputs .......................... 71 A.5.1 Outputs of parallel program . 72 A.6 Parallelization ............................. 72 A.6.1 Transposition table ...................... 72 2 Introduction Playing games has always been a pastime of the human race. Along with every game comes a question: How to play the game? There are two approaches how to answer this question. The first one is by experience. Usually when we play a game repeatedly, we learn with some time how to play this game good. The second approach is more formal. We can use mathematics to describe the rules and try to find the properties of the game. Mathematicians usually study games, where no randomness occurs, because the state of the game is determined only by players' moves. Classical game theory studies games with imperfect information. However in this thesis we are interested in tic-tac-toe, which is a game for 2 players with perfect information. These games are studied by combinatorial game theory. For some simple games with small state space only paper and pen suffice to find out if the first player can force the win. However, when the games are more complex the paper and pen do not suffice and we need computers. Computers are mainly used for 2 problems according to games: finding the winning strategy or creating the artificial intelligence for the game. Actually these problems are very similar, both are solved by searching algorithms. However, a lot of games have huge state space and searching the whole state space for finding the winning strategy would last very long. So AI searches only part of the state space and selects the best ply with respect to the searched part of the state space. Tic-tac-toe is one of the most famous games for two players. Even little children play it, because it has very simple rules. The size of a basic board of tic-tac-toe is 3 × 3 and it is easy to find by case analysis that the game ends with a draw, if both players play optimally. However when the size and dimension of the game board are bigger, the manual case analysis is impossible. We are interested if the first player can force the win in 3-dimensional tic-tac- toe. In tic-tac-toe with the board 2 × 2 × 2 and 3 × 3 × 3 the first player can force the win and it can be shown by simple case analysis. Hence the first non-trivial size of the board is 4 and tic-tac-toe with board 4 × 4 × 4 is called Qubic. Upon our knowledge, Qubic was solved twice in history by Oren Patashnik [5] in 1980 and by Louis V. Allis [1] in 1994. However, we are the first ones, as far as we know, who used the parallel algorithm. We apply Pn-search as a single-thread task and each starting position is solved in one thread. We found that parallel algorithm is easy to implement and it gives quite good results. Usually people are not interested how many winning strategies exist for the first or second player, but only if a winning strategy exists. Therefore automor- phisms are used very often, when a game is analyzed. All automorphisms for Qubic were characterized by Rolland Silver [7] in 1967. When we analyzed the 5 × 5 × 5, we found that the group of automorphism of 5 × 5 × 5 is isomorphic to the group of Qubic automorphisms. Hence we started to study automorphisms a little bit more. Some people ask about the automorphisms of general tic-tac-toe. We answer these questions and we characterized all automorphisms for tic-tac-toe played in general cube with arbitrary length of edge and dimension. This thesis was motivated by solving the game 5 × 5 × 5, which is an open problem. Unfortunately we did not manage to solve this game. The game 5×5×5 has a much bigger state space than Qubic and also the algorithms which we used 3 are not as efficient as for Qubic. Nonetheless, we still have two results: • We propose an easy-implemented parallelization of Pn-search, when there are more starting positions. • We characterize all automorphisms of the combinatorial cube nd with the multidimensional tic-tac-toe set of lines.