(FILECREATED "25-JUL-83 10:28:45" {INDIGO}<LOOPS>TRUCKIN>MULTI>TRAVELER.;3 16262  

      changes to:  (FNS BuyGasTravelerRules FindStoppingPlaceTravelerRules 
			GoToStoppingPlaceTravelerRules TakeTurnTravelerRules)

      previous date: "11-JUL-83 18:43:30" {INDIGO}<LOOPS>TRUCKIN>MULTI>TRAVELER.;2)


(PRETTYCOMPRINT TRAVELERCOMS)

(RPAQQ TRAVELERCOMS ((* Copyright (c)
			1983 by Xerox Corporation.)
		     (* * File for a Traveler. -- A very simple automatic player for TRUCKIN.)
		     (* TRUCKIN is a mini-expert system for teaching knowledge representation 
			techniques in the Loops programming system. Truckin provides a simple 
			simulation environment for novice Loops users in which small bodies of 
			knowledge can be created and tested interactively. Knowledge in Truckin is in 
			the form of rules for controlling a game piece to "maximize profit.")
		     (CLASSES * TRAVELERCLASSES)
		     (FNS * TRAVELERFNS)
		     (INSTANCES * TRAVELERINSTANCES)))



(* Copyright (c) 1983 by Xerox Corporation.)

(* * File for a Traveler. -- A very simple automatic player for TRUCKIN.)




(* TRUCKIN is a mini-expert system for teaching knowledge representation techniques in the 
Loops programming system. Truckin provides a simple simulation environment for novice Loops 
users in which small bodies of knowledge can be created and tested interactively. Knowledge in 
Truckin is in the form of rules for controlling a game piece to "maximize profit.")


(RPAQQ TRAVELERCLASSES (Traveler))
(DEFCLASSES Traveler)
[DEFCLASS Traveler
   (MetaClass PlayerMeta doc 

          (* * A Traveler is a player who tours back and forth between UnionHall and AlicesRestaurant, buying gasoline and 
	  getting weighed as needed. Example of a very simple automated playerthat does not compete very knowledgeably to 
	  win.)


	      Edited:                                        (* mjs: "18-FEB-83 10:53")
	      )
   (Supers Player)
   (ClassVariables)
   (InstanceVariables (destination NIL doc                   (* Current destination. Either AlicesRestaurant or the 
							     UnionHall.))
		      (direction NIL doc                     (* Forward or Backward direction of travel on the 
							     highway.))
		      (stoppingPlace NIL doc                 (* Place to stop enroute to destination.)
				     ))
   (Methods (BuyGas BuyGasTravelerRules doc                  (* RuleSet BuyGasTravelerRules is installed as the 
							     selector BuyGas of the class Traveler)
		    RuleSet BuyGasTravelerRules)
	    (FindStoppingPlace FindStoppingPlaceTravelerRules doc 
                                                             (* RuleSet FindStoppingPlaceTravelerRules is installed 
							     as the selector FindStoppingPlace of the class Traveler)
			       RuleSet FindStoppingPlaceTravelerRules)
	    (GoToStoppingPlace GoToStoppingPlaceTravelerRules doc 
                                                             (* RuleSet GoToStoppingPlaceTravelerRules is installed 
							     as the selector GoToStoppingPlace of the class Traveler)
			       RuleSet GoToStoppingPlaceTravelerRules)
	    (TakeTurn TakeTurnTravelerRules doc              (* RuleSet TakeTurnTravelerRules is installed as the 
							     selector TakeTurn of the class Traveler)
		      RuleSet TakeTurnTravelerRules))]


(RPAQQ TRAVELERFNS (BuyGasTravelerRules FindStoppingPlaceTravelerRules GoToStoppingPlaceTravelerRules 
					TakeTurnTravelerRules))
(DEFINEQ

(BuyGasTravelerRules
  [LAMBDA (self)
    (PROG (↑value spaceInTank fuelAffordable fuelAvailable qty)
          [SETQ ↑value (PROGN [SETQ spaceInTank (DIFFERENCE (GetClassValue (GetValue self
										     (QUOTE truck))
									   (QUOTE MaxFuel))
							    (GetValue (GetValue self (QUOTE truck))
								      (QUOTE fuel]
			      (SETQ fuelAvailable (GetValue (GetValue (GetValue self (QUOTE truck))
								      (QUOTE location))
							    (QUOTE qty)))
			      [SETQ fuelAffordable (QUOTIENT (GetValue (GetValue self (QUOTE truck))
								       (QUOTE cashBox))
							     (PricePerUnit
							       (GetValue (GetValue self (QUOTE truck))
									 (QUOTE location]
			      (SETQ qty (MIN spaceInTank fuelAffordable fuelAvailable]
          [COND
	    ((GREATERP qty 0)
	      (SETQ ↑value (← PlayerInterface Buy self qty]
      QUIT(RETURN ↑value])

(FindStoppingPlaceTravelerRules
  [LAMBDA (self)
    (PROG (↑value wStation gasStation)
          [COND
	    [(EQ (GetValue (GetValue self (QUOTE truck))
			   (QUOTE fuel))
		 0)
	      (SETQ ↑value (PROGN (PROGN                     (* Rule Tracing Code)
					 (TraceRHS (QUOTE FindStoppingPlaceTravelerRules)
						   NIL 1)
					 (← (GetObjFromUID "LYS.0.5349.124.36446.235")
					    Print))
				  (PutValue self (QUOTE stoppingPlace)
					    (AnyRoadStop ($ UnionHall]
	    [[AND [SETQ wStation (NearestRoadStop (RoadStops ($ WeighStation)
							     (← self Range1)
							     (GetValue self (QUOTE direction))
							     (QUOTE Room]
		  (LESSP (Distance wStation)
			 (Distance (GetValue self (QUOTE destination]
	      (SETQ ↑value (PROGN (PROGN                     (* Rule Tracing Code)
					 (TraceRHS (QUOTE FindStoppingPlaceTravelerRules)
						   NIL 2)
					 (← (GetObjFromUID "LYS.0.5349.124.36446.236")
					    Print))
				  (PutValue self (QUOTE stoppingPlace)
					    wStation]
	    [[AND [SETQ gasStation (FurthestRoadStop (RoadStops ($ GasStation)
								(← self Range1)
								(GetValue self (QUOTE direction))
								(QUOTE Room]
		  (LESSP (Distance gasStation)
			 (Distance (GetValue self (QUOTE destination]
	      (SETQ ↑value (PROGN (PROGN                     (* Rule Tracing Code)
					 (TraceRHS (QUOTE FindStoppingPlaceTravelerRules)
						   NIL 3)
					 (← (GetObjFromUID "LYS.0.5349.124.36446.237")
					    Print))
				  (PutValue self (QUOTE stoppingPlace)
					    gasStation]
	    [[AND (LEQ (Distance (GetValue self (QUOTE destination)))
		       (← self Range1))
		  (RoomToParkP (GetValue self (QUOTE destination]
	      (SETQ ↑value (PROGN (PROGN                     (* Rule Tracing Code)
					 (TraceRHS (QUOTE FindStoppingPlaceTravelerRules)
						   NIL 4)
					 (← (GetObjFromUID "LYS.0.5349.124.36446.238")
					    Print))
				  (PutValue self (QUOTE stoppingPlace)
					    (GetValue self (QUOTE destination]
	    ((AND)
	      (SETQ ↑value (PROGN (PROGN                     (* Rule Tracing Code)
					 (TraceRHS (QUOTE FindStoppingPlaceTravelerRules)
						   NIL 5)
					 (← (GetObjFromUID "LYS.0.5349.124.36446.239")
					    Print))
				  (PutValue self (QUOTE stoppingPlace)
					    (NthRoadStop (GetValue self (QUOTE maxMove))
							 (GetValue self (QUOTE direction))
							 NIL
							 (QUOTE Room]
      QUIT(RETURN ↑value])

(GoToStoppingPlaceTravelerRules
  [LAMBDA (self)
    (PROG (↑value)
          [SETQ ↑value (PROGN (← self FindStoppingPlace)
			      (← PlayerInterface Move self (GetValue self (QUOTE stoppingPlace]
          [COND
	    ((ISA (GetValue (GetValue self (QUOTE truck))
			    (QUOTE location))
		  ($ GasStation))
	      (SETQ ↑value (← self BuyGas]
      QUIT(RETURN ↑value])

(TakeTurnTravelerRules
  [LAMBDA (self)
    (PROG (↑value)
          [COND
	    ((NOT (GetValue self (QUOTE destination)))
	      (SETQ ↑value (PROGN (PutValue self (QUOTE destination)
					    (AnyRoadStop ($ AlicesRestaurant)))
				  (PutValue self (QUOTE direction)
					    (QUOTE Forward]
          [COND
	    ((← (GetValue (GetValue self (QUOTE truck))
			  (QUOTE location))
		InstOf
		($ UnionHall))
	      (SETQ ↑value (PROGN (PutValue self (QUOTE destination)
					    (AnyRoadStop ($ AlicesRestaurant)))
				  (PutValue self (QUOTE direction)
					    (QUOTE Forward]
          [COND
	    ((← (GetValue (GetValue self (QUOTE truck))
			  (QUOTE location))
		InstOf
		($ AlicesRestaurant))
	      (SETQ ↑value (PROGN (PutValue self (QUOTE destination)
					    (AnyRoadStop ($ UnionHall)))
				  (PutValue self (QUOTE direction)
					    (QUOTE Backward]
          (SETQ ↑value (← self GoToStoppingPlace))
      QUIT(RETURN ↑value])
)

(RPAQQ TRAVELERINSTANCES (BuyGasTravelerRules FindStoppingPlaceTravelerRules 
					      GoToStoppingPlaceTravelerRules TakeTurnTravelerRules))
(DEFINST RuleSet (BuyGasTravelerRules "JZS@@A>N>")
	 (perspectiveNode #&(RuleSetNode "JZS@@A>N@"))
	 (name #(BuyGasTravelerRules NIL RememberName))
	 (compiledRules BuyGasTravelerRules)
	 (workSpace Traveler)
	 (args NIL)
	 (tempVars (spaceInTank fuelAffordable fuelAvailable qty))
	 (taskVars NIL)
	 (debugVars NIL)
	 (numRules 2)
	 (controlStructure DOALL)
	 (whileCondition NIL)
	 (compilerOptions NIL)
	 (auditClass NIL)
	 (metaAssignments NIL)
	 (ruleClass NIL)
	 (taskClass)
	 (arguments))



(DEFINST RuleSet (FindStoppingPlaceTravelerRules "JZS@@A>N?")
	 (perspectiveNode #&(RuleSetNode "JZS@@A>NA"))
	 (name #(FindStoppingPlaceTravelerRules NIL RememberName))
	 (compiledRules FindStoppingPlaceTravelerRules)
	 (workSpace Traveler)
	 (args NIL)
	 (tempVars (wStation gasStation))
	 (taskVars NIL)
	 (debugVars NIL)
	 (numRules 5)
	 (controlStructure DO1)
	 (whileCondition NIL)
	 (compilerOptions (T))
	 (auditClass NIL)
	 (metaAssignments NIL)
	 (ruleClass NIL)
	 (taskClass)
	 (arguments))



(DEFINST RuleSet (GoToStoppingPlaceTravelerRules "JZS@@A>M|")
	 (perspectiveNode #&(RuleSetNode "JZS@@A>NB"))
	 (name #(GoToStoppingPlaceTravelerRules NIL RememberName))
	 (compiledRules GoToStoppingPlaceTravelerRules)
	 (workSpace Traveler)
	 (args NIL)
	 (tempVars NIL)
	 (taskVars NIL)
	 (debugVars NIL)
	 (numRules 2)
	 (controlStructure DOALL)
	 (whileCondition NIL)
	 (compilerOptions NIL)
	 (auditClass NIL)
	 (metaAssignments NIL)
	 (ruleClass NIL)
	 (taskClass)
	 (arguments))



(DEFINST RuleSet (TakeTurnTravelerRules "JZS@@A>M{")
	 (perspectiveNode #&(RuleSetNode "JZS@@A>NC"))
	 (name #(TakeTurnTravelerRules NIL RememberName))
	 (compiledRules TakeTurnTravelerRules)
	 (workSpace Traveler)
	 (args NIL)
	 (tempVars NIL)
	 (taskVars NIL)
	 (debugVars NIL)
	 (numRules 4)
	 (controlStructure DOALL)
	 (whileCondition NIL)
	 (compilerOptions NIL)
	 (auditClass NIL)
	 (metaAssignments NIL)
	 (ruleClass NIL)
	 (taskClass)
	 (arguments))



(DEFINST RuleSetNode ("JZS@@A>N@")
	 (perspectives ? RuleSet #&(RuleSet "JZS@@A>N>") Source #&(RuleSetSource "JZS@@A>ND")))



(DEFINST RuleSetNode ("JZS@@A>NA")
	 (perspectives ? RuleSet #&(RuleSet "JZS@@A>N?") Source #&(RuleSetSource "JZS@@A>NE")))



(DEFINST RuleSetNode ("JZS@@A>NB")
	 (perspectives ? RuleSet #&(RuleSet "JZS@@A>M|") Source #&(RuleSetSource "JZS@@A>NF")))



(DEFINST RuleSetNode ("JZS@@A>NC")
	 (perspectives ? RuleSet #&(RuleSet "JZS@@A>M{") Source #&(RuleSetSource "JZS@@A>NG")))



(DEFINST RuleSetSource ("JZS@@A>ND")
	 (indexedVars ((#&(Rule "LYS.0.5349.124.36446.240"))
		       (#&(Rule "LYS.0.5349.124.36446.241"))))
	 (perspectiveNode #&(RuleSetNode "JZS@@A>N@"))
	 (created "27-JAN-83 00:31:21")
	 (creator STEFIK)
	 (edited "25-JUL-83 10:27:35")
	 (editor STEFIK))



(DEFINST RuleSetSource ("JZS@@A>NE")
	 (indexedVars ((#&(Rule "LYS.0.5349.124.36446.235"))
		       (#&(Rule "LYS.0.5349.124.36446.236"))
		       (#&(Rule "LYS.0.5349.124.36446.237"))
		       (#&(Rule "LYS.0.5349.124.36446.238"))
		       (#&(Rule "LYS.0.5349.124.36446.239"))))
	 (perspectiveNode #&(RuleSetNode "JZS@@A>NA"))
	 (created "27-JAN-83 00:34:46")
	 (creator STEFIK)
	 (edited "25-JUL-83 10:27:46")
	 (editor STEFIK))



(DEFINST RuleSetSource ("JZS@@A>NF")
	 (indexedVars ((#&(Rule "LYS.0.5349.124.36446.242"))
		       (#&(Rule "LYS.0.5349.124.36446.243"))))
	 (perspectiveNode #&(RuleSetNode "JZS@@A>NB"))
	 (created "27-JAN-83 00:02:00")
	 (creator STEFIK)
	 (edited "25-JUL-83 10:27:55")
	 (editor STEFIK))



(DEFINST RuleSetSource ("JZS@@A>NG")
	 (indexedVars ((#&(Rule "LYS.0.5349.124.36446.244"))
		       (#&(Rule "LYS.0.5349.124.36446.245"))
		       (#&(Rule "LYS.0.5349.124.36446.246"))
		       (#&(Rule "LYS.0.5349.124.36446.247"))))
	 (perspectiveNode #&(RuleSetNode "JZS@@A>NC"))
	 (created "26-JAN-83 23:15:35")
	 (creator STEFIK)
	 (edited "25-JUL-83 10:28:04")
	 (editor STEFIK))



(DEFINST Rule ("LYS.0.5349.124.36446.240")
	 (source 

"(* Buy gasoline as limited by various constraints.)

     THEN spaceInTank←truck::MaxFuel-truck:fuel
	
          fuelAvailable←truck:location:qty

          fuelAffordable←truck:cashBox/(PricePerUnit truck:location)

          qty←(MIN spaceInTank fuelAffordable fuelAvailable);")
	 (edited "25-JUL-83 10:27:35")
	 (editor STEFIK)
	 (ruleNumber 1)
	 (ruleSet #&(RuleSet "JZS@@A>N>")))



(DEFINST Rule ("LYS.0.5349.124.36446.241")
	 (source 

"(* Now appropriate quantity has been computed)

    IF qty>0
     THEN  (← \PlayerInterface Buy self qty );")
	 (edited "25-JUL-83 10:27:35")
	 (editor STEFIK)
	 (ruleNumber 2)
	 (ruleSet #&(RuleSet "JZS@@A>N>")))



(DEFINST Rule ("LYS.0.5349.124.36446.235")
	 (source 

"(* Return as a value the next place to stop enroute to destination.)

IF truck:fuel=0
 THEN stoppingPlace←(AnyRoadStop $UnionHall);")
	 (edited "25-JUL-83 10:27:46")
	 (editor STEFIK)
	 (ruleNumber 1)
	 (ruleSet #&(RuleSet "JZS@@A>N?")))



(DEFINST Rule ("LYS.0.5349.124.36446.236")
	 (source 

"IF wStation←(NearestRoadStop (RoadStops $WeighStation .Range1 direction 'Room))
   (Distance wStation)<(Distance destination)
 THEN stoppingPlace←wStation;")
	 (edited "25-JUL-83 10:27:46")
	 (editor STEFIK)
	 (ruleNumber 2)
	 (ruleSet #&(RuleSet "JZS@@A>N?")))



(DEFINST Rule ("LYS.0.5349.124.36446.237")
	 (source 

" 
IF gasStation←(FurthestRoadStop (RoadStops $GasStation .Range1 direction 'Room))
  (Distance gasStation)<(Distance destination)
THEN stoppingPlace←gasStation;")
	 (edited "25-JUL-83 10:27:46")
	 (editor STEFIK)
	 (ruleNumber 3)
	 (ruleSet #&(RuleSet "JZS@@A>N?")))



(DEFINST Rule ("LYS.0.5349.124.36446.238")
	 (source 
  "IF (Distance destination)<=.Range1 (RoomToParkP destination)
 THEN stoppingPlace←destination;")
	 (edited "25-JUL-83 10:27:46")
	 (editor STEFIK)
	 (ruleNumber 4)
	 (ruleSet #&(RuleSet "JZS@@A>N?")))



(DEFINST Rule ("LYS.0.5349.124.36446.239")
	 (source "-> stoppingPlace←(NthRoadStop maxMove direction NIL 'Room);")
	 (edited "25-JUL-83 10:27:46")
	 (editor STEFIK)
	 (ruleNumber 5)
	 (ruleSet #&(RuleSet "JZS@@A>N?")))



(DEFINST Rule ("LYS.0.5349.124.36446.242")
	 (source 

"(* Ask to go to a stopping place returned by FindStoppingPlace)

	-> .FindStoppingPlace (← \PlayerInterface Move self stoppingPlace);")
	 (edited "25-JUL-83 10:27:55")
	 (editor STEFIK)
	 (ruleNumber 1)
	 (ruleSet #&(RuleSet "JZS@@A>M|")))



(DEFINST Rule ("LYS.0.5349.124.36446.243")
	 (source 

" 
(* Check if real truck location is a gas station.  Don't  
   use stoppingPlace, since chosen it may not have been reached  
   because of cops or robbers)

	IF (ISA truck:location $GasStation)
	 THEN .BuyGas;")
	 (edited "25-JUL-83 10:27:55")
	 (editor STEFIK)
	 (ruleNumber 2)
	 (ruleSet #&(RuleSet "JZS@@A>M|")))



(DEFINST Rule ("LYS.0.5349.124.36446.244")
	 (source 

"(* Top Level RuleSet for Traveler.
   Travel between UnionHall a randomly chosen AlicesRestaurant)

	IF ~destination
	 THEN destination←(AnyRoadStop $AlicesRestaurant)
	     direction←'Forward;")
	 (edited "25-JUL-83 10:28:04")
	 (editor STEFIK)
	 (ruleNumber 1)
	 (ruleSet #&(RuleSet "JZS@@A>M{")))



(DEFINST Rule ("LYS.0.5349.124.36446.245")
	 (source 

"  	(* No destination if at start)

	IF (← truck:location InstOf $UnionHall)
	 THEN destination←(AnyRoadStop $AlicesRestaurant)
	     direction←'Forward;")
	 (edited "25-JUL-83 10:28:04")
	 (editor STEFIK)
	 (ruleNumber 2)
	 (ruleSet #&(RuleSet "JZS@@A>M{")))



(DEFINST Rule ("LYS.0.5349.124.36446.246")
	 (source 

"	(* Choose an Alices to go to.)

	IF (← truck:location InstOf $AlicesRestaurant)
	 THEN destination←(AnyRoadStop $UnionHall)
	     direction←'Backward;")
	 (edited "25-JUL-83 10:28:04")
	 (editor STEFIK)
	 (ruleNumber 3)
	 (ruleSet #&(RuleSet "JZS@@A>M{")))



(DEFINST Rule ("LYS.0.5349.124.36446.247")
	 (source "	(* Set destination to UnionHall)

	 THEN .GoToStoppingPlace;")
	 (edited "25-JUL-83 10:28:04")
	 (editor STEFIK)
	 (ruleNumber 4)
	 (ruleSet #&(RuleSet "JZS@@A>M{")))



(DECLARE: DONTCOPY
  (FILEMAP (NIL (3546 8178 (BuyGasTravelerRules 3556 . 4428) (FindStoppingPlaceTravelerRules 4430 . 6848
) (GoToStoppingPlaceTravelerRules 6850 . 7228) (TakeTurnTravelerRules 7230 . 8176)))))
STOP