{"id":511,"date":"2007-09-16T11:58:23","date_gmt":"2007-09-16T11:58:23","guid":{"rendered":"http:\/\/scientopia.org\/blogs\/goodmath\/2007\/09\/16\/games-and-graphs-searching-for-victory\/"},"modified":"2007-09-16T11:58:23","modified_gmt":"2007-09-16T11:58:23","slug":"games-and-graphs-searching-for-victory","status":"publish","type":"post","link":"http:\/\/www.goodmath.org\/blog\/2007\/09\/16\/games-and-graphs-searching-for-victory\/","title":{"rendered":"Games and Graphs: Searching for Victory"},"content":{"rendered":"<p> Last time, I showed a way of using a graph to model a particular kind of puzzle via<br \/>\na search graph. Games and puzzles provide a lot of examples of how we can use graphs<br \/>\nto model problems. Another example of this is the most basic state-space search that we do in computer science problems.<\/p>\n<p><!--more--><\/p>\n<p> In terms of a game, a state space is a set of <em>equivalence classes<\/em> over all possible board positions. For example, in chess, the state of a game at any point is represented by a set of mappings that assign either a position on the board or &#8220;captured&#8221; to each piece. The state space of chess consists of all possible board positions that can be reached by any sequence of legal moves. The state space<br \/>\nof tic-tac-toe consists of all marked boards, partitioned into equivalence classes of marked boards equivalent modulo rotation or reflection.<\/p>\n<p> Given a state space, two states S<sub>1<\/sub> and S<sub>2<\/sub> are connected by a directed edge if and only if there is a legal move from one position to the other. When all possible moves are represented by edges, the resulting graph is a <em>complete model<\/em> of the game.<\/p>\n<p> For some games simple games, the state spaces are necessarily tree-like; in other games (for example, Chess, in which a given board position can be reproduced, which creates a cycle in the graph) they can be general directed graphs. But in general, most games are directed acyclic graphs. But for some reason, the graph model of a game is generally referred to as a <em>game tree<\/em>.<\/p>\n<p> For example, in the diagram below, I show a part of the game tree for tic-tac toe. From an empty board position, there are three possible unique moves. If the first move is putting an X in a corner, there are 5 possible unique moves. The diagram also includes an example of why the game tree is really a directed graph, not a tree: the game board after three moves, with X in a corner and center and O in a non-blocking<br \/>\ncorner, can be reached by two different paths: X in corner, O in corner, X in center; and X in center, O in corner, X in corner.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" alt=\"tic-tac.png\" src=\"https:\/\/i0.wp.com\/scientopia.org\/img-archive\/goodmath\/img_270.png?resize=478%2C444\" width=\"478\" height=\"444\" \/><\/p>\n<p> Once you have the game laid out as a graph in game-tree form, you can use graph-search algorithms to traverse the graph, looking for a path that leeds to winning the game. We say that a game is <em>solved<\/em> in graph theoretic terms when we have the complete graph of the game, and we know every possible path through it. <\/p>\n<p> Given a game in its graph form, for anything but the most trivial of games, it&#8217;s not<br \/>\nfeasible to use a real, complete graph search. For example, the game tree for checkers, which <a href=\"http:\/\/www.sciencemag.org\/cgi\/content\/abstract\/1144079v1\">was recently solved<\/a>, has 5&times;10<sup>20<\/sup> nodes. Solving checkers took 18 years of computation &#8211; and that was <em>not<\/em> actually a complete search of the state space!<\/p>\n<p> What you typically do in searching a game tree is use directed search algorithms and graph-reduction heuristics. The idea of both of these is to try to reduce the search space. A couple of common examples are:<\/p>\n<ul>\n<li><b>Pruning:<\/b> If you can show that a given edge in the search tree cannot possibly lead to an ideal solution, then you can cut that edge, often eliminating a large section of the graph. This is the main strategy used to reduce the search space for checkers: you can show, for many \tmoves, that making that move is non-optimal. Since the checkers player can decide not to make non-optimal moves, you prune the edge corresponding to the non-optimal move from the graph. This eliminates a significant number of states &#8211; for checkers, the final search graph \twas cut from 5&times;10<sup>20<\/sup> to something around 10<sup>18<\/sup> states, with a complete graph only for the end-game &#8211; which was a set of roughly 3&times;10<sup>14<\/sup>  \t\tstates.<\/li>\n<li> <b> Limiting:<\/b> Often, you can approximate the results of a full search by looking ahead through a limited-depth subset of the graph. This is commonly used in computer chess games: \tby looking ahead no more than 9 edges in the chess game-tree, you can determine a good enough approximation of outcomes to beat most human chess players.<\/li>\n<li><b>Edge Heuristics:<\/b> You can often exploit knowledge of the game to recognize that certain kinds of moves are more likely to lead to a good outcome (win or draw). By preferring to go to the edges corresponding to those moves, you can improve a pruning process to reduce the graph. This is, however, error-prone: sometimes, you&#8217;ll prune out the best path to winning the game.<\/li>\n<li><b>Vertex Heuristics:<\/b> Another form of exploiting game knowledge. For many games (including Chess), you can assign\ta &#8220;quality value&#8221; to a given board position. In combination with limiting, you can often use vertex heuristics to make good guesses at what moves to make. Again, as with most heuristic processes, this will work well most of the time, but there are cases where you&#8217;ll prune out the best solution.<\/li>\n<\/ul>\n<p> State spaces and searches like this don&#8217;t only come up in games &#8211; you can find state spaces in all sorts of models &#8211; economics, physics, knowledge representation, linguistic dialogue modeling, AI planning, resource allocation, and more. The basic ideas above &#8211; the ideas of the state-space graph and graph search &#8211; apply to all of these, and more.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last time, I showed a way of using a graph to model a particular kind of puzzle via a search graph. Games and puzzles provide a lot of examples of how we can use graphs to model problems. Another example of this is the most basic state-space search that we do in computer science problems.<\/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":[25],"tags":[],"class_list":["post-511","post","type-post","status-publish","format-standard","hentry","category-graph-theory"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4lzZS-8f","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/511","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=511"}],"version-history":[{"count":0,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/511\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/media?parent=511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/categories?post=511"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/tags?post=511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}