# Encoding solitaire_decision.gringo

Name solitaire_decision.gringo Martin Gebser Martin Gebser and Roland Kaminski Description =========== Solitaire is a single player game played on a 7x7 board with 2x2 corners omitted. Each position is either full (containing a peg / marble) or empty. With 'O' representing full positions and '.' representing an empty position, a possible board configuration is: ```   .OO   .OO O.OOOOO OOO.OOO OOOOOOO   O.O  OOO ``` Each turn the player must jump a peg over an existing peg and removed the 'jumped' peg. For example, numbering the board from the top left, moving peg (4,2) down would give the following board configuration: ```   .OO   ..O O.O.OOO OOOOOOO OOOOOOO   O.O   OOO ``` The task is, given an initial board configuration, find a sequence of the given number of moves. Input ----- Thirty two facts giving the initial board configuration, each of which is either: full(X,Y). or empty(X,Y). indicating that position (X,Y) is either full or empty. A number of time facts, giving the number of moves that must be found. These are given as a range of consecutive, ascending integers, starting at 1. Output ------ The input facts plus a number of move facts equal to the number of time facts. Each move fact is of the form: move(T,D,X,Y). indicating that to get to time step T from time step T-1 (the initial conditions are regarded to be time step 0), the peg in position (X,Y) is moved in direction D (up, down, left or right). Calibration ----------- Generally the fewer pegs remaining on the board, the harder it is to make a move. Thus instances starting with a full or a nearly full board and conduct 27-31 moves are the most difficult. Author: Martin Brain 2009-03-27 12:58 2009-05-11 22:04 Instance Group 1 empty/2full/2time/1 empty/2full/2move/4time/1 No ASP Contest 09 (Martin Gebser) #hide dir/3. #hide field/2. #hide field/3. #hide stone/3. #hide moved/3. #hide removed/3. field(X,Y) :- empty(X,Y). field(X,Y) :- full(X,Y). dir(left ,-1, 0). dir(right, 1, 0). dir(up , 0,-1). dir(down , 0, 1). stone(X,Y,0) :- full(X,Y). field(X,Y,D) :- field(X,Y), field(X+DX,Y+DY), field(X+2*DX,Y+2*DY), dir(D,DX,DY). 1 { move(T,D,X,Y) : field(X,Y,D) } 1 :- time(T). :- move(T,D,X,Y), not stone(X,Y,T-1). :- move(T,D,X,Y), stone(X+2*DX,Y+2*DY,T-1), dir(D,DX,DY). :- move(T,D,X,Y), not stone(X+DX,Y+DY,T-1), dir(D,DX,DY). moved(T,X,Y) :- move(T,D,X,Y), time(T). removed(T,X+DX,Y+DY) :- move(T,D,X,Y), dir(D,DX,DY). stone(X+2*DX,Y+2*DY,T) :- move(T,D,X,Y), dir(D,DX,DY). stone(X,Y,T) :- field(X,Y), stone(X,Y,T-1), not moved(T,X,Y), not removed(T,X,Y), time(T).