Presentation is loading. Please wait.

Presentation is loading. Please wait.

Intelligence for Games and Puzzles1 Solitaire Puzzle The solitaire puzzle is played with 32 pegs.

Similar presentations


Presentation on theme: "Intelligence for Games and Puzzles1 Solitaire Puzzle The solitaire puzzle is played with 32 pegs."— Presentation transcript:

1 http://csiweb.ucd.ie/Staff/acater/comp4031.htmlArtificial Intelligence for Games and Puzzles1 Solitaire Puzzle The solitaire puzzle is played with 32 pegs on a board with 33 holes. Initially all holes are occupied except the central hole. A move consists of removing a peg, hopping it over an adjacent peg, putting it into an empty hole one space further on, removing the peg hopped over The object is to end with just one peg, in the central hole.

2 http://csiweb.ucd.ie/Staff/acater/comp4031.htmlArtificial Intelligence for Games and Puzzles2 Encoding positions A program might represent a state of the puzzle as a 33-bit number. Each hole’s bit has meaning: 1 = occupied 0=empty. Of the many ways of assigning bits to holes, some will be completely arbitrary Some will be systematic but in a useless way Some will be systematic in a potentially useful way  because they capture (some of the) symmetry in the layout. For example, each of the four blocks can be transformed into another by a rotation. The central hole is out on its own.

3 http://csiweb.ucd.ie/Staff/acater/comp4031.htmlArtificial Intelligence for Games and Puzzles3 Exploiting a symmetrical encoding Using 4 8-bit bytes, each hole (except the central one) can be assigned a bit position within one byte that is the same as the position of related holes in other quarters of the board. This gives an easy way to find a canonical representation of a position Such as, pick the numerically least number of the four byte-rotated representations of the position So that, if rotationally-equivalent positions are reached by different sequences of moves, three out of four may be ignored. 5 13 46 7 2 8 Which is least? 5 13 46 7 2 8

4 http://csiweb.ucd.ie/Staff/acater/comp4031.htmlArtificial Intelligence for Games and Puzzles4 Encoding moves A move involves 3 holes two particular holes must be full, and one empty, before the move, full holes become empty, and the empty hole becomes full, after the move. A move can therefore be represented as a pair of 33-bits numbers, N1 and N2: N1 has 3 bits set to identify the three holes  whose content must be tested before the move  Whose content must be inverted after the move N2 has 2 bits set to identify the two holes that must be full before the move If (( oldposition AND move.N1) = move.N2) Then newposition := oldposition XOR move.N1

5 http://csiweb.ucd.ie/Staff/acater/comp4031.htmlArtificial Intelligence for Games and Puzzles5 Move example 11111111 0 Posn= N2= N1= Posn:= 00000000 000010011 00000000 11111111 00000000 11111111 00000000 11111111 00001001 11110110 0 1 canonical 11111111 11110110 1

6 http://csiweb.ucd.ie/Staff/acater/comp4031.htmlArtificial Intelligence for Games and Puzzles6 Searching 1 Each position can be faithfully represented (this way) using 33 bits. From a 33-bit position you can generate new 33-bit positions. But when/if you solve the puzzle, you - presumably - want to show how So with a position, store an record of which move was played to get there. There are 76 possible moves 2 from each “1” “3” “4” and “6”, 1 from each “2” and “5” 4 from each “7” and “8” 4 from the unique centre A number 1…76 can be stored in 7 bits; so a position with move-number can be stored in 40 bits. A sorted sequence of 5-byte numbers could be maintained to record positions that have already been generated, & how you got there or better how to get back

7 http://csiweb.ucd.ie/Staff/acater/comp4031.htmlArtificial Intelligence for Games and Puzzles7 Searching 2 A breadth-first search could take the positions generated by N moves, and build a sorted sequence of all possible positions generated by N+1 moves. And repeat this until 31 moves have been played. But 1.Breadth-first search consumes a lot of storage 2.It is possible to stop the search after only 16 moves After the 16th move, generated positions will have 32-16 filled holes, 1+16 empty. If we take such a position, and invert its positional bits (not its move number) and canonicalise, we get something comparable to a 15-move position. When searching forward from the start of the puzzle, we were in effect also searching backward from the end!

8 http://csiweb.ucd.ie/Staff/acater/comp4031.htmlArtificial Intelligence for Games and Puzzles8 Constructing the solution Suppose that there are two sequences A, B, of (CanonicalPositions)+(moves) P A N:M A N and P B N:M B N, so that (P A 16) = canonicalise(NOT (P B 15)). From any P A N:M A N you can reconstuct P A N-1 and look up P A N-1:M A N-1, likewise with P B N:M B N. As canonicalisation effectively rotates positions, so too it rotates moves. They should be numbered sensibly to facilitate this: symmetric moves systematically numbered in steps of 19 or more. The solution then consists of the concatenation of 1.Appropriately rotated M A N, N=1…16 2.Appropriately rotated M B N, N=15…1 P0 P A 1:M A 1 P B 1:M B 1P B 2:M B 2P B 3:M B 3P B 15:M B 15 P A 16:M A 16P A 3:M A 3P A 2:M A 2

9 http://csiweb.ucd.ie/Staff/acater/comp4031.htmlArtificial Intelligence for Games and Puzzles9 Storage requirements Breadth-first search of a game tree always suffers from the need to maintain a queue of unexpanded interior nodes A node has 5 bytes of information, and we may expect approx  N=1..16 ( 33 C N ) = 1B of them; to be kept in a sorted sequence of some sort. Could instead arrange a vector, containing all nodes with same lowest positional byte a table, indexed by a) lowest positional byte and b) its no-lower neighbour Godel numbering of all positions, recording one byte containing 0 or move# 1/4

10 http://csiweb.ucd.ie/Staff/acater/comp4031.htmlArtificial Intelligence for Games and Puzzles10 Where’s the AI? Where are the heuristics? If “solving Solitaire” were scientifically or financially significant, it could be solved by a brute-force method such as outlined earlier. 4+ Gb of storage and a few hours (?) of CPU should either do it, or prove it cannot be done. For “solving Solitaire” to be really interesting from an AI point of view, it should be that there are heuristics which can be used to effectively prune the search space. Aggressive Forward Pruning - rather than the provably safe pruning of search trees done by  - is useful in problem-solving domains (including game-playing and puzzle-solving) where there is heuristic knowledge that can be used to tame an unwieldy search space.


Download ppt "Intelligence for Games and Puzzles1 Solitaire Puzzle The solitaire puzzle is played with 32 pegs."

Similar presentations


Ads by Google