(FILECREATED " 9-JUN-83 23:36:19" {INDIGO}<LOOPS>TRUCKIN>PLAYERS>TRAVELER.;5 18855 previous date: " 8-JUN-83 18:35:02" {IVY}<STEFIK>LISP>TRAVELER.;1) (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 (← gameMaster Buy qty] QUIT(RETURN ↑value]) (FindStoppingPlaceTravelerRules [LAMBDA (self) (PROG (↑auditRecord ↑value wStation gasStation) [COND [(EQ (GetValue (GetValue self (QUOTE truck)) (QUOTE fuel)) 0) (SETQ ↑value (PROGN (PROGN (* Make an audit record for this rule and set its audit values.) (SETQ ↑auditRecord (← ($ StandardAuditRecord) NewTemp)) (PutValue ↑auditRecord (QUOTE rule) (GetObjFromUID "UISC@@Ot"))) (PROGN (* Rule Tracing Code) (TraceRHS (QUOTE FindStoppingPlaceTravelerRules) NIL 1) (← (GetObjFromUID "UISC@@Ot") Print)) (PutAuditRec self (QUOTE stoppingPlace) (AnyRoadStop ($ UnionHall)) ↑auditRecord] [[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 (* Make an audit record for this rule and set its audit values.) (SETQ ↑auditRecord (← ($ StandardAuditRecord) NewTemp)) (PutValue ↑auditRecord (QUOTE rule) (GetObjFromUID "UISC@@Ou"))) (PROGN (* Rule Tracing Code) (TraceRHS (QUOTE FindStoppingPlaceTravelerRules) NIL 2) (← (GetObjFromUID "UISC@@Ou") Print)) (PutAuditRec self (QUOTE stoppingPlace) wStation ↑auditRecord] [[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 (* Make an audit record for this rule and set its audit values.) (SETQ ↑auditRecord (← ($ StandardAuditRecord) NewTemp)) (PutValue ↑auditRecord (QUOTE rule) (GetObjFromUID "UISC@@Ov"))) (PROGN (* Rule Tracing Code) (TraceRHS (QUOTE FindStoppingPlaceTravelerRules) NIL 3) (← (GetObjFromUID "UISC@@Ov") Print)) (PutAuditRec self (QUOTE stoppingPlace) gasStation ↑auditRecord] [[AND (LEQ (Distance (GetValue self (QUOTE destination))) (← self Range1)) (RoomToParkP (GetValue self (QUOTE destination] (SETQ ↑value (PROGN (PROGN (* Make an audit record for this rule and set its audit values.) (SETQ ↑auditRecord (← ($ StandardAuditRecord) NewTemp)) (PutValue ↑auditRecord (QUOTE rule) (GetObjFromUID "UISC@@Ow"))) (PROGN (* Rule Tracing Code) (TraceRHS (QUOTE FindStoppingPlaceTravelerRules) NIL 4) (← (GetObjFromUID "UISC@@Ow") Print)) (PutAuditRec self (QUOTE stoppingPlace) (GetValue self (QUOTE destination)) ↑auditRecord] ((AND) (SETQ ↑value (PROGN (PROGN (* Make an audit record for this rule and set its audit values.) (SETQ ↑auditRecord (← ($ StandardAuditRecord) NewTemp)) (PutValue ↑auditRecord (QUOTE rule) (GetObjFromUID "UISC@@Ox"))) (PROGN (* Rule Tracing Code) (TraceRHS (QUOTE FindStoppingPlaceTravelerRules) NIL 5) (← (GetObjFromUID "UISC@@Ox") Print)) (PutAuditRec self (QUOTE stoppingPlace) (NthRoadStop maxMove (GetValue self (QUOTE direction)) NIL (QUOTE Room)) ↑auditRecord] QUIT(RETURN ↑value]) (GoToStoppingPlaceTravelerRules [LAMBDA (self) (PROG (↑value) [SETQ ↑value (PROGN (← self FindStoppingPlace) (← gameMaster Move (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 (↑auditRecord ↑value) [COND ((NOT (GetValue self (QUOTE destination))) (SETQ ↑value (PROGN (PROGN (* Make an audit record for this rule and set its audit values.) (SETQ ↑auditRecord (← ($ StandardAuditRecord) NewTemp)) (PutValue ↑auditRecord (QUOTE rule) (GetObjFromUID "UISC@@O|"))) (PutAuditRec self (QUOTE destination) (AnyRoadStop ($ AlicesRestaurant)) ↑auditRecord) (PutAuditRec self (QUOTE direction) (QUOTE Forward) ↑auditRecord] [COND ((← (GetValue (GetValue self (QUOTE truck)) (QUOTE location)) InstOf ($ UnionHall)) (SETQ ↑value (PROGN (PROGN (* Make an audit record for this rule and set its audit values.) (SETQ ↑auditRecord (← ($ StandardAuditRecord) NewTemp)) (PutValue ↑auditRecord (QUOTE rule) (GetObjFromUID "UISC@@P="))) (PutAuditRec self (QUOTE destination) (AnyRoadStop ($ AlicesRestaurant)) ↑auditRecord) (PutAuditRec self (QUOTE direction) (QUOTE Forward) ↑auditRecord] [COND ((← (GetValue (GetValue self (QUOTE truck)) (QUOTE location)) InstOf ($ AlicesRestaurant)) (SETQ ↑value (PROGN (PROGN (* Make an audit record for this rule and set its audit values.) (SETQ ↑auditRecord (← ($ StandardAuditRecord) NewTemp)) (PutValue ↑auditRecord (QUOTE rule) (GetObjFromUID "UISC@@P>"))) (PutAuditRec self (QUOTE destination) (AnyRoadStop ($ UnionHall)) ↑auditRecord) (PutAuditRec self (QUOTE direction) (QUOTE Backward) ↑auditRecord] (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 (A 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 (A)) (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 "UISC@@P?")) (#&(Rule "UISC@@P@")))) (perspectiveNode #&(RuleSetNode "JZS@@A>N@")) (created "27-JAN-83 00:31:21") (creator STEFIK) (edited " 9-JUN-83 09:55:09") (editor STEFIK)) (DEFINST RuleSetSource ("JZS@@A>NE") (indexedVars ((#&(Rule "UISC@@Ot")) (#&(Rule "UISC@@Ou")) (#&(Rule "UISC@@Ov")) (#&(Rule "UISC@@Ow")) (#&(Rule "UISC@@Ox")) (#&(Rule "J[S@@AOG")))) (perspectiveNode #&(RuleSetNode "JZS@@A>NA")) (created "27-JAN-83 00:34:46") (creator STEFIK) (edited " 9-JUN-83 10:38:25") (editor STEFIK)) (DEFINST RuleSetSource ("JZS@@A>NF") (indexedVars ((#&(Rule "UISC@@PA")) (#&(Rule "UISC@@PB")) (#&(Rule "J[S@@AO>")))) (perspectiveNode #&(RuleSetNode "JZS@@A>NB")) (created "27-JAN-83 00:02:00") (creator STEFIK) (edited " 9-JUN-83 10:41:00") (editor STEFIK)) (DEFINST RuleSetSource ("JZS@@A>NG") (indexedVars ((#&(Rule "UISC@@O|")) (#&(Rule "UISC@@P=")) (#&(Rule "UISC@@P>")) (#&(Rule "UISC@@PC")) (#&(Rule "J←S@@=lF")))) (perspectiveNode #&(RuleSetNode "JZS@@A>NC")) (created "26-JAN-83 23:15:35") (creator STEFIK) (edited " 9-JUN-83 10:41:11") (editor STEFIK)) (DEFINST Rule ("UISC@@P?") (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 " 9-JUN-83 09:55:09") (editor STEFIK) (ruleNumber 1) (ruleSet #&(RuleSet "JZS@@A>N>"))) (DEFINST Rule ("UISC@@P@") (source "(* Now appropriate quantity has been computed) IF qty>0 THEN (← \gameMaster Buy qty );") (edited " 9-JUN-83 09:55:09") (editor STEFIK) (ruleNumber 2) (ruleSet #&(RuleSet "JZS@@A>N>"))) (DEFINST Rule ("UISC@@Ot") (source "(* Return as a value the next place to stop enroute to destination.) IF truck:fuel=0 THEN stoppingPlace←(AnyRoadStop $UnionHall);") (edited " 9-JUN-83 10:38:25") (editor STEFIK) (ruleNumber 1) (ruleSet #&(RuleSet "JZS@@A>N?"))) (DEFINST Rule ("UISC@@Ou") (source "IF wStation←(NearestRoadStop (RoadStops $WeighStation .Range1 direction 'Room)) (Distance wStation)<(Distance destination) THEN stoppingPlace←wStation;") (edited " 9-JUN-83 10:38:25") (editor STEFIK) (ruleNumber 2) (ruleSet #&(RuleSet "JZS@@A>N?"))) (DEFINST Rule ("UISC@@Ov") (source " IF gasStation←(FurthestRoadStop (RoadStops $GasStation .Range1 direction 'Room)) (Distance gasStation)<(Distance destination) THEN stoppingPlace←gasStation;") (edited " 9-JUN-83 10:38:25") (editor STEFIK) (ruleNumber 3) (ruleSet #&(RuleSet "JZS@@A>N?"))) (DEFINST Rule ("UISC@@Ow") (source "IF (Distance destination)<=.Range1 (RoomToParkP destination) THEN stoppingPlace←destination;") (edited " 9-JUN-83 10:38:25") (editor STEFIK) (ruleNumber 4) (ruleSet #&(RuleSet "JZS@@A>N?"))) (DEFINST Rule ("UISC@@Ox") (source "-> stoppingPlace←(NthRoadStop \maxMove direction NIL 'Room);") (edited " 9-JUN-83 10:38:25") (editor STEFIK) (ruleNumber 5) (ruleSet #&(RuleSet "JZS@@A>N?"))) [DEFINST Rule ("J[S@@AOG") (source NIL) (edited "27-JAN-83 13:27:03") (editor "STEFIK") (ruleNumber 6) (ruleSet #&(RuleSet "JZS@@A>N?")) (lhs) (rhs (SETQ ↑value (NthRoadStop maxMove (GetValue self (QUOTE direction] (DEFINST Rule ("UISC@@PA") (source "(* Ask to go to a stopping place returned by FindStoppingPlace) -> .FindStoppingPlace (← \gameMaster Move stoppingPlace);") (edited " 9-JUN-83 10:41:00") (editor STEFIK) (ruleNumber 1) (ruleSet #&(RuleSet "JZS@@A>M|"))) (DEFINST Rule ("UISC@@PB") (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 " 9-JUN-83 10:41:00") (editor STEFIK) (ruleNumber 2) (ruleSet #&(RuleSet "JZS@@A>M|"))) [DEFINST Rule ("J[S@@AO>") (source NIL) (edited "27-JAN-83 11:31:20") (editor "STEFIK") (ruleNumber 3) (ruleSet #&(RuleSet "JZS@@A>M|")) (lhs (ISA stoppingPlace (QUOTE GasStation))) (rhs (SETQ ↑value (← self BuyGas] (DEFINST Rule ("UISC@@O|") (source "(* Top Level RuleSet for Traveler. Travel between UnionHall a randomly chosen AlicesRestaurant) IF ~destination THEN destination←(AnyRoadStop $AlicesRestaurant) direction←'Forward;") (edited " 9-JUN-83 10:41:11") (editor STEFIK) (ruleNumber 1) (ruleSet #&(RuleSet "JZS@@A>M{"))) (DEFINST Rule ("UISC@@P=") (source " (* No destination if at start) IF (← truck:location InstOf $UnionHall) THEN destination←(AnyRoadStop $AlicesRestaurant) direction←'Forward;") (edited " 9-JUN-83 10:41:11") (editor STEFIK) (ruleNumber 2) (ruleSet #&(RuleSet "JZS@@A>M{"))) (DEFINST Rule ("UISC@@P>") (source " (* Choose an Alices to go to.) IF (← truck:location InstOf $AlicesRestaurant) THEN destination←(AnyRoadStop $UnionHall) direction←'Backward;") (edited " 9-JUN-83 10:41:11") (editor STEFIK) (ruleNumber 3) (ruleSet #&(RuleSet "JZS@@A>M{"))) (DEFINST Rule ("UISC@@PC") (source " (* Set destination to UnionHall) THEN .GoToStoppingPlace;") (edited " 9-JUN-83 10:41:11") (editor STEFIK) (ruleNumber 4) (ruleSet #&(RuleSet "JZS@@A>M{"))) [DEFINST Rule ("J←S@@=lF") (source NIL) (edited "31-JAN-83 20:45:43") (editor "BOBROW") (ruleNumber 5) (ruleSet #&(RuleSet "JZS@@A>M{")) (lhs) (rhs (SETQ ↑value (PROGN] (DECLARE: DONTCOPY (FILEMAP (NIL (3403 10461 (BuyGasTravelerRules 3413 . 4275) (FindStoppingPlaceTravelerRules 4277 . 8114) (GoToStoppingPlaceTravelerRules 8116 . 8484) (TakeTurnTravelerRules 8486 . 10459))))) STOP