### ### FILE : eight-puzzle.s ### ### ### AUTHOR(1) : John.E.Laird [ Soar 5.x ] ### ### ### CREATED(1) : Oct 11, 89 ### ### ### MODIFIED(8) : Aug 25, 96 [ Soar 7.0.3 ] Sayan Bhattacharyya ### MODIFIED(7) : Nov 18, 94 [ Soar 6.2.3 ] John.E.Laird ### MODIFIED(6) : May 10, 93 [ Soar 6.0.9 ] JT.Traub ### MODIFIED(5) : Apr 29, 93 [ Soar 6.0.7 ] John.E.Laird ### MODIFIED(4) : ? [ Soar 6.x.x ] ? ### MODIFIED(3) : Apr 17, 91 [ Soar 5.2.x ] Brian.G.Milnes ### MODIFIED(2) : May 17, 90 [ Soar 5.1.0 ] Thomas.F.McGinnis ### MODIFIED(1) : Oct 11, 89 [ Soar 5.1.0 ] John.E.Laird ### ### ### Aug 25, 96 : default rules now loaded automatically ### Nov 18, 94 : Clean up NNPSCM and improve generality of chunks by changing calculation of tile-cell on state ### May 10, 93 : Added in Multiattribute statements ### Apr 29, 93 : Removed testing cell names from state evaluation ### productions, and applied test from the production for ### operator termination. ### Apr 17, 91 : Changed for new notify. ### May 17, 90 : Added ^default-operator-copy no, in prep for Soar ### 5.1.2. ### Oct 11, 89 : Changed evaluation productions to Soar 5.1. ### ### ### Originally //hawk/users/soar/dsm/tasks/eight2.dsm (University of Michigan). ### Eight puzzle for DSM. Modifies the bindings, but does not create new ### bindings. ### State Structure: ## Each state contains nine bindings. ## The bindings connect together a cell, one of the nine positions on ## the board and a tile, one of the movable pieces. ## The cells have pointers, ^cell, to each of their adjacent cells. ## The state also has a pointer to the blank-cell and the cell ## that the last moved tile is in -- this improves efficiency and ## simplify computations that depend on the previous operator. ### Operator Staructure: ## Each operator contains a pointer to the cell with the blank ## and the cell with the tile to be moved. ### source $default multi-attributes binding 10 ## Name the first subgoal eight-puzzle and create the ## problem space and operators ### ### TOP GOAL: ### SOLVE-EIGHT-PUZZLE ### ### ### TOP GOAL PROBLEM SPACE: ### EIGHT-PUZZLE ### sp {eight*create*space*eight-puzzle (state ^superstate nil) --> ( ^name solve-eight-puzzle ^desired ^problem-space

+ ) (

^name eight-puzzle ^default-state-copy yes ^default-operator-copy no ^one-level-attributes blank-cell blank-cell & ^one-level-attributes tile-cell tile-cell & ^two-level-attributes binding binding & )} ### ### EIGHT-PUZZLE PROBLEM SPACE: ### INITIAL STATE AND DESIRED STATE ### ## Define the initial state and the impasse state: ## each state is a set of bindings# ## each binding points to a cell and a tile# ## each cell points to its neighboring cells. sp {eight*create*state*initial-and-desired-states (state ^name solve-eight-puzzle ^problem-space

^desired ) (

^name eight-puzzle) --> ( ^name 0) ( ^name 1) ( ^name 2) ( ^name 3) ( ^name 4) ( ^name 5) ( ^name 6) ( ^name 7) ( ^name 8) ( ^name c11 ^cell + &, ^cell + & ) ( ^name c12 ^cell + &, ^cell + &, ^cell + & ) ( ^name c13 ^cell + &, ^cell + &,) ( ^name c21 ^cell + &, ^cell + &, ^cell + & ) ( ^name c22 ^cell + &, ^cell + &, ^cell + &, ^cell + & ) ( ^name c23 ^cell + &, ^cell + &, ^cell + & ) ( ^name c31 ^cell + &, ^cell + & ) ( ^name c32 ^cell + &, ^cell + &, ^cell + & ) ( ^name c33 ^cell + &, ^cell + & ) ( ^blank-cell ^tile-cell nil ^binding + &, + &, + &, + &, + &, + &, + &, + &, + & ) ( ^cell ^tile ) ( ^cell ^tile ) ( ^cell ^tile ) ( ^cell ^tile ) ( ^cell ^tile ) ( ^cell ^tile ) ( ^cell ^tile ) ( ^cell ^tile ) ( ^cell ^tile ) ( ^better higher ^binding + &, + &, + &, + &, + &, + &, + &, + &, + & ) ( ^cell ^tile ) ( ^cell ^tile ) ( ^cell ^tile ) ( ^cell ^tile ) ( ^cell ^tile ) ( ^cell ^tile ) ( ^cell ^tile ) ( ^cell ^tile ) ( ^cell ^tile )} ### ### EIGHT-PUZZLE PROBLEM SPACE OPERATOR: ### MOVE-TILE ### sp {eight*create*operator*move-tile (state ^problem-space

^blank-cell ) (

^name eight-puzzle) ( ^cell ) --> ( ^name move-tile ^tile-cell ^blank-cell ) ( ^operator + )} ### ### EIGHT-PUZZLE PROBLEM SPACE: ### OPERATOR IMPLEMENTATION ### sp {eight*apply*operator*move-tile (state ^problem-space

^operator ^binding { <> } ^blank-cell ) (

^name eight-puzzle) ( ^tile-cell ^blank-cell ^name move-tile) ( ^tile ^cell ) ( ^tile ^cell ) --> ( ^blank-cell - ) ( ^tile - ) ( ^tile - )} sp {eight*apply*operator*remove-tile-cell (state ^problem-space

^operator ^tile-cell ) (

^name eight-puzzle) ( ^blank-cell <> ^name move-tile) --> ( ^tile-cell -)} sp {eight*apply*operator*add-tile-cell (state ^problem-space

^operator ^blank-cell ) (

^name eight-puzzle) ( ^blank-cell ^name move-tile) --> ( ^tile-cell )} sp {eight*save*operator*applied*a (state ^problem-space

^operator ^tile-cell ^blank-cell -^applied) (

^name eight-puzzle) ( ^tile-cell ^blank-cell ) --> ( ^applied + )} sp {eight*save*operator*applied*b (state ^problem-space

^operator ^tile-cell ^blank-cell ^applied { <> }) (

^name eight-puzzle) ( ^tile-cell ^blank-cell ) --> ( ^applied - + )} ### ### EIGHT-PUZZLE PROBLEM SPACE: ### OPERATOR TERMINATION ### sp {eight*reconsider*operator*move-tile (state ^problem-space

^operator ^tile-cell ^blank-cell ) (

^name eight-puzzle) ( ^tile-cell ^blank-cell ) --> ( ^operator @ )} ### ### EIGHT-PUZZLE PROBLEM SPACE: ### STATE EVALUATION ### ## A numeric evaluation function, ## based on changes by operators, is used ## to evaluate state. ### ### EVALUATION: STATE POSITIVE ### ## 1 point for moving tile into its impasse cell # sp {eight*elaborate*state*evaluation*positive*one (state ^problem-space

^superstate ^tile-cell ^binding ^applied ) (

^name eight-puzzle) ( ^binding ) ( ^cell ^tile ) ( ^cell ^tile ) ( ^operator ^evaluation ) ( ^name evaluate-object ^evaluation ^object ^desired ) --> ( ^numeric-value 1)} ### ### EVALUATION: STATE NEUTRAL ### ## 0 points for not moving tile in or out of its impasse cell # sp {eight*elaborate*state*evaluation*neutral*zero (state ^problem-space

^superstate ^tile-cell ^blank-cell ^binding { <> } { <> <> } ^applied ) (

^name eight-puzzle) ( ^binding { <> }) ( ^cell ^tile ) ( ^tile ) ( ^tile ) ( ^cell ^tile { <> }) ( ^cell ^tile { <> }) ( ^operator ^evaluation ) ( ^name evaluate-object ^evaluation ^object ^desired ) --> ( ^numeric-value 0)} ### ### EVALUATION: STATE NEGATIVE ### ## -1 points for moving tile out of its impasse cell # sp {eight*elaborate*state*evaluation*negative*one (state ^problem-space

^superstate ^tile-cell ^binding ^blank-cell ^applied ) (

^name eight-puzzle) ( ^binding ) ( ^cell ^tile ) ( ^cell ^tile ) ( ^operator ^evaluation ) ( ^name evaluate-object ^evaluation ^object ^desired ) --> ( ^numeric-value -1)} ### ### EVALUATION: STATE SUCCESS/GOAL TEST ### sp {eight*detect*state*success (state ^problem-space

^desired ^binding ) (

^name eight-puzzle) ( ^cell.name c11 ^tile ) ( ^cell.name c12 ^tile ) ( ^cell.name c13 ^tile ) ( ^cell.name c21 ^tile ) ( ^cell.name c22 ^tile ) ( ^cell.name c23 ^tile ) ( ^cell.name c31 ^tile ) ( ^cell.name c32 ^tile ) ( ^cell.name c33 ^tile ) ( ^binding ) ( ^cell.name c11 ^tile ) ( ^cell.name c12 ^tile ) ( ^cell.name c13 ^tile ) ( ^cell.name c21 ^tile ) ( ^cell.name c22 ^tile ) ( ^cell.name c23 ^tile ) ( ^cell.name c31 ^tile ) ( ^cell.name c32 ^tile ) ( ^cell.name c33 ^tile ) --> ( ^success )} ### ### EIGHT-PUZZLE PROBLEM SPACE: ### SEARCH CONTROL ### sp {eight*operator*move-tile*inverse*reject "Reject the operator that was applied to create this state." (state ^problem-space

^operator + ^tile-cell ) (

^name eight-puzzle) ( ^tile-cell ) --> ( ^operator - )} ### ### EIGHT-PUZZLE PROBLEM SPACE: ### MONITOR STATE ### ## Want this to fire whenever an op is installed or ## whenever op is applied (bindings change) but NOT both. ## Try requiring that operator be finished. # sp {eight*monitor*state (state ^problem-space

^binding ) (

^name eight-puzzle) ( ^cell.name c11 ^tile ) ( ^name ) ( ^cell.name c12 ^tile ) ( ^name ) ( ^cell.name c13 ^tile ) ( ^name ) ( ^cell.name c21 ^tile ) ( ^name ) ( ^cell.name c22 ^tile ) ( ^name ) ( ^cell.name c23 ^tile ) ( ^name ) ( ^cell.name c31 ^tile ) ( ^name ) ( ^cell.name c32 ^tile ) ( ^name ) ( ^cell.name c33 ^tile ) ( ^name ) --> (write (crlf) | -------------| | | (crlf) | | ) (write | \|| | | | | |\|| | | | | |\|| | | | | |\|| | | (crlf) | | ) (write | \|---\|---\|---\|| | | (crlf) | | ) (write | \|| | | | | |\|| | | | | |\|| | | | | |\|| | | (crlf) | | ) (write | \|---\|---\|---\|| | | (crlf) | | ) (write | \|| | | | | |\|| | | | | |\|| | | | | |\|| | | (crlf) | | ) (write | -------------| | | (crlf) | | )} ### eof of eight-puzzle.s