### Table of contents, ht.s7 ### ### i. Some simple things to help beginners ### I. Propose the top space ### II. Propose the main operators ### II. Propose the main operators ### III. Implement the main operators ### IV. Noticing when full ### V. Operator Set-up ### VI. Better object traces ### ### Copyright 1994. F. E. Ritter & R. M. Young. ### ### Last substantially modified: 10Feb96 -FER ### With useful bug fixes from Kate Cook. ### ### 5/7/95 Gary Jones - NNPSCM conversion. ### ### 27/7/95 Gary Jones - Altered references to to be . ### For example, state is now state . ### Just to make it easier to understand. ### Also put in learn -off (because it should be). ### ### ### Saved as Text Only so that it can be loaded into Soar. ### ### A simple hungry-thirsty problem space and operators ### ### The code supplied has these characteristics: ### - The operators Eat & Drink are proposed iff they're ### applicable. that is, Eat if (^hungry yes), Drink if (^thirsty yes) ### - There is an explicit ^desired on the goal ### - which is tested by the goal attainment rule ### - There are hand-written control chunks giving Eat best ### ### Example command within Soar to get to this code and load it: ### ### Macintosh: cd "joe:EuroSoar7:tutorial" ### Unix: cd "/aigr/staff/ritter/res/soar/euro-soar93/tutorial/" ### ### Then: source "ht.s7" ### ### ### i. Some simple things to help beginners ### ## Resets the watch level to the base level in case you changed it: watch 0 learn -off echo "learn -off; " ## Upon reload, resetting the goal stack to be empty is usually ## required and is a good idea: init-soar echo "watch set to 0; init-soar done " ## What to do with sets of indifferent context elements: take the ## first one. user-select -first ### ### I. Propose the top space ### ### The code in this section proposes a simple space to work in, and a ### simple state to start working in. sp {ht*propose-space*ht (state -^impasse ^superstate nil) --> ( ^name ht-state) ( ^problem-space

^desired ) (

^name hungry-thirsty) ( ^hungry no) ( ^thirsty yes ^hungry yes) } ## Propose the top state ## simple way to set up the top-state with a separate production ##sp {ht*propose-state*ht ## (state ^problem-space.name hungry-thirsty) ## --> ## ( ^name ht-state) ## ( ^thirsty yes ^hungry yes)} ## You can put the closing parenthesis on its own line (e.g., in the ## first production) to show that it is closed, but I generally don't ## to save space. ### ### II. Propose the main operators ### ### The code in this section proposes the two operators eat and drink. ### The third production creates a preference for choosing between ### them. ## Propose eat. sp {ht*propose-op*eat (state ^problem-space.name hungry-thirsty ) ( ^hungry yes) --> ( ^operator ) ( ^name eat)} ## Propose drink. sp {ht*propose-op*drink (state ^problem-space.name hungry-thirsty ) ( ^thirsty yes) --> ( ^operator ) ( ^name drink)} ## Eat is better if you are hungry. sp {ht*compare*eat*better*drink (state ^desired ^problem-space.name hungry-thirsty) ( ^hungry no) ( ^operator +) ( ^name eat) ( ^operator +) ( ^name drink) --> ( ^operator > )} ### ### III. Implement the main operators ### ## Implement the operators with productions that modify the state once ## the operators have been selected, and then terminate them after ## they have done ## what they need to do ## ## Note: We make the new value acceptable and reject the previous ## value. ## ## The reconsider preference effectively terminates the operator on ## the next decision cycle after it has done what its supposed to do. sp {ht*apply-op*eat (state ^operator ) ( ^name eat) ( ^hungry yes) --> (write (crlf) | chomp chomp... |) ( ^hungry yes - no +)} sp {ht*terminate*eat (state ^operator ) ( ^name eat) ( ^hungry no) --> ( ^operator @)} ## Implement drink ## Note: just making the new value acceptable and best, to ## overwrite any value (or no value) on the state, is not a wise ## idea (if the another operator applies and makes another attribute ## best you will get ties and lose. sp {ht*apply-op*drink (state ^operator ) ( ^name drink) ( ^thirsty yes) --> (write (crlf) | glug glug... |) ( ^thirsty no + yes -)} sp {ht*terminate*drink (state ^operator ) ( ^name drink) ( ^thirsty no) --> ( ^operator @)} ### ### IV. Noticing when full ### ### This code terminates the problem solving when the goal is reached. ## How to tell if you can stop sp {ht*evaluate*state*success (state ^desired ) ( ^hungry ) ( ^hungry ) --> ( ^success )} ## One of the default rules is brought in to notice that we are ## finished. (Slightly modified to be more compact and less general.) sp {default*top-goal*halt*state*success :default (state ^desired ) ( ^success ) --> (write (crlf) | goal for | | achieved | ) (halt)} ### ### V. Better object traces ### ## Soar6 supports the idea of setting up context element traces. We ## include here some better object traces to make the stack trace ## clearer. format-watch -stack -add * {%id (name: %v[name])} ## This traces the values of hungry and thirsty on states. ## Be careful not to get a CR in the middle of the string. format-watch -stack -add s ht-state \ {%id (name: %v[name] hungry: %v[hungry] thirsty: %v[thirsty])} ;# need to do this to get a new line in soar7.0.0 beta echo "" ###--------------------------------------------------------------- ### END OF FILE ###---------------------------------------------------------------