{"id":663,"date":"2008-07-30T11:38:06","date_gmt":"2008-07-30T11:38:06","guid":{"rendered":"http:\/\/scientopia.org\/blogs\/goodmath\/2008\/07\/30\/solving-tic-tac-toe-game-tree-basics\/"},"modified":"2008-07-30T11:38:06","modified_gmt":"2008-07-30T11:38:06","slug":"solving-tic-tac-toe-game-tree-basics","status":"publish","type":"post","link":"http:\/\/www.goodmath.org\/blog\/2008\/07\/30\/solving-tic-tac-toe-game-tree-basics\/","title":{"rendered":"Solving Tic-Tac-Toe: Game Tree Basics"},"content":{"rendered":"<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" alt=\"tic-tac-toe.png\" src=\"https:\/\/i0.wp.com\/scientopia.org\/img-archive\/goodmath\/img_321.png?resize=292%2C198\" width=\"292\" height=\"198\" class=\"inset right\" \/><\/p>\n<p> Moving on from simple zero-sum games, there are a bunch of directions in which<br \/>\nwe can go. So far, the games we&#8217;ve looked at are very restrictive. Beyond the<br \/>\nzero-sum property, they&#8217;re built on a set of fundamental properties which ultimately<br \/>\nreduce to the idea that no player ever has an information advantage over any other<br \/>\nplayer: the complete payoff matrix is known by all players; no player gets<br \/>\nto see the other players strategy before selecting their own; and so on.<\/p>\n<p> Moving on to more interesting games, we can relax those assumptions, and allow information to be hidden. Perhaps each player can see a different part of the<br \/>\npayoff matrix. Perhaps they take turns, so that one player gets to see the others<br \/>\nstrategy before selecting his own. Perhaps the game isn&#8217;t zero-sum. <\/p>\n<p> Non-zero sum games turn out to be disappointing from a game theory point of<br \/>\nview. Given a suitable set of restrictions, you can convert a non-zero-sum game to a<br \/>\nzero-sum game with an additional player. In the cases where you can&#8217;t do that,<br \/>\nyou&#8217;re pretty much stuck &#8211; the mathematical tools that work well for analyzing<br \/>\nzero-sum games often simply don&#8217;t work once you relax the zero-sum requirement.<\/p>\n<p> The more interesting ways of exploring different realms of games comes when you<br \/>\nallow things to get more complex. This comes about when you allow a players strategy<br \/>\nselection to <em>alter the game<\/em>. This general takes place in a turn-taking<br \/>\ngame, where each players strategy selection alters the game for the other player. A<br \/>\nsimple example of this is the game of tic-tac-toe. The set of strategies of the game<br \/>\nfor a given player at any point in time is the set of open squares on the board.<br \/>\nEach time a player makes a move, the game is altered for the other player.<\/p>\n<p> This makes things much more interesting. The easiest way to think of it is<br \/>\nthat now, instead of a simple matrix for the game, we end up with a tree. Each move<br \/>\nthat a player can make creates a new game for the other player. By making each game position a tree node, and adding children nodes for each position that can follow it, you can build a tree describing the complete set of possible game positions, and thus the complete set of ways that the game could play out.<\/p>\n<p><!--more--><\/p>\n<p> As usual, it&#8217;s easiest to see this with an example. At the top of this post is the game tree for tic-tac-toe, assuming that &#8220;X&#8221; goes first.<\/p>\n<p> There are really three moves that X can make initially &#8211; she can play a corner,<br \/>\na center-edge, or the center. Which corner or edge she chooses is irrelevant &#8211; on an empty tic-tac-toe game-board, due to symmetries, the corners\/edges are equivalent. If X plays the center, then the other player can choose either an edge or a corner. If X plays an edge, the O player can play a corner adjacent to X&#8217;s move; a corner not adjacent; an adjacent edge; the opposite edge; or the center. And so on.<\/p>\n<p> How can you solve a game like this?<\/p>\n<p> Ultimately, it comes down to utility functions. You can build up a utility<br \/>\nfunction describing the values of each possible move. This requires some of what I<br \/>\ntalked about in my last post with lotteries: most moves produce not a specific<br \/>\nresult (win or lose), but a new game. So to compute the utility value of a<br \/>\nparticular strategy, you need to combine the utility values of the potential<br \/>\nsubsequent strategies resulting from that move.<\/p>\n<p> Computing the utilities in tic-tac-toe is easy: the utility of any move is the<br \/>\nprobability of your winning the game if you make that move. You determine that by<br \/>\nanalyzing the possible moves available to you. First, you can prune the tree: any<br \/>\nstrategy that doesn&#8217;t include a potential path for you to win, you can just<br \/>\neliminate from consideration: it has a utility of 0. For other moves, you look at<br \/>\nthe potential paths: if move A leads into a subtree where 72% of the paths lead to a<br \/>\nleaf in which you win, then the utility of A is 0.72. Each turn, the best<br \/>\nstrategy is the one with the highest utility; moves with equal utility are<br \/>\nequivalent.<\/p>\n<p> The problem with this approach is that game trees grow incredibly quickly. Even with all symmetries eliminated, the game tree for tic-tac-toe has approximately 25,000 nodes! That means that for a human, the complete game tree isn&#8217;t really understandable, even for a trivial game like tic-tac-toe. When<br \/>\nyou start looking at more interesting games, you get some really astonishingly large game trees. Checkers has a game tree with around 5&times;10<sup>20<\/sup> nodes, after eliminating all symmetries. For Go, the exact size of the tree is unknown &#8211; but it&#8217;s greater than 10<sup>100<\/sup>!<\/p>\n<p> Obviously, we can&#8217;t compute the whole game tree for games like that. And without the full tree, we can&#8217;t calculate precise utility for every possible move. So we<br \/>\nto compute <em>approximate<\/em> utilities. We can compute approximate utility<br \/>\nvalues using a variety of techniques, including heuristics, prunings, board valuations, and partial trees.<\/p>\n<p> Heuristics is the use of what you could call intelligent guesses. There<br \/>\nare moves or positions on most games that are usually sensible. In a game of checkers, if you have an opportunity to either jump and capture one opponents<br \/>\npiece, or double-jump and capture two, it&#8217;s generally smarter to capture two. Not<br \/>\nalways &#8211; there are cases where the single jump (and subsequent sacrifice of one of your pieces) is the best move. But <em>most of the time<\/em>, the double-capture is<br \/>\npreferable. In the absence of any other information, you&#8217;d assign a higher<br \/>\nestimated utility to the double-jump. Heuristics also covers some things<br \/>\nbased on your knowledge of the other player. People who&#8217;ve played chess with me know that I tend to over-use my queen and under-use my knights; if you use that<br \/>\nknowledge, you can make intelligent guesses that certain paths in the tree<br \/>\nare more likely than others, and use that to weight the likely paths higher<br \/>\nin your utility computation.<\/p>\n<p> Prunings can be thought of as a sort of heuristic. The idea is that<br \/>\nif you look at the game tree, there are some parts of the tree that lead<br \/>\ninto undesirable situations &#8211; that is, situations where your probability of<br \/>\nwinning is reduced. If it appears that a particular subtree of the game<br \/>\nisn&#8217;t likely to work out well for you, you just eliminate that entire<br \/>\nsubtree. It&#8217;s possible that if you searched that subtree, that you might find<br \/>\na path that would let you win. But the odds of finding a great winning strategy<br \/>\nare small enough that you just cut the subtree away, and don&#8217;t search it.<\/p>\n<p> Board valuations are ways of looking at a given game situation, and assigning<br \/>\nit a value. In chess, a board where your opponent has his king in an unguarded position, you&#8217;ve got your queen out on the board where it&#8217;s not vulnerable and it&#8217;s available to move, and your king is in a castled defensive position is better<br \/>\nthan the same position where you&#8217;re queen was captured, or where your king is undefended. You don&#8217;t need to look further into the game tree to make a strong guess which of those positions is preferable. This comes down to assigning a valuation<br \/>\nto a board position without looking further into the tree to compute that<br \/>\nvaluation. It&#8217;s based solely on immediate, observable properties of the state<br \/>\nof the game when you make the valuation.<\/p>\n<p> Board valuations are particularly important when combined with partial trees. The idea of a partial tree is that the full game tree is impossibly large. So you only consider a small part of it. This is very common in chess-playing programs. The<br \/>\nprogram computes a partial game tree: for example, it may compute 9 levels of the game tree from the current position, which covers the next 9 moves. The states at the leafs of that partial tree are computed by board valuations; the states at internal nodes are computed by combining the values of their children.<\/p>\n<p> So where do we go from here in our exploration of game theory? There&#8217;s more<br \/>\nto be said about game trees. For example, for most two-player alternative move games, there&#8217;s a very particular structure that can efficiently represent the game tree, and provide opportunities for analysis and pruning, called an and-or tree. There are also a set of optimizations based on the fact that in a typical game tree, there are multiple ways that a given board position can be reached. We can compact the game tree into a graph by taking advantage of that.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Moving on from simple zero-sum games, there are a bunch of directions in which we can go. So far, the games we&#8217;ve looked at are very restrictive. Beyond the zero-sum property, they&#8217;re built on a set of fundamental properties which ultimately reduce to the idea that no player ever has an information advantage over any [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[88],"tags":[],"class_list":["post-663","post","type-post","status-publish","format-standard","hentry","category-game-theory"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4lzZS-aH","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/663","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/comments?post=663"}],"version-history":[{"count":0,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/663\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/media?parent=663"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/categories?post=663"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/tags?post=663"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}