(FILECREATED "15-JUL-83 15:49:24" {IVY}<LOOPSCOURSE>OUSTERHOUT>BADAPPLES.;15 45291  

      changes to:  (FNS BuyGasBadApplesRules FindStoppingPlaceBadApplesRules GetHintBadApples 
			GoToStoppingPlaceBadApplesRules SellGoodsBadApplesRules 
			TakeTurnBadApplesRules)

      previous date: "15-JUL-83 13:15:45" {IVY}<LOOPSCOURSE>OUSTERHOUT>BADAPPLES.;13)


(PRETTYCOMPRINT BADAPPLESCOMS)

(RPAQQ BADAPPLESCOMS ((CLASSES BadApples)
		      (INSTANCES BuyGasBadApplesRules FindStoppingPlaceBadApplesRules 
				 GetConsumerBadApples GetHintBadApples 
				 GoToStoppingPlaceBadApplesRules SellGoodsBadApplesRules 
				 TakeTurnBadApplesRules)
		      (FNS BESort BadApples.EvalBoard BadApples.FindBandits BadApples.Get 
			   BadApples.Sort BuyGasBadApplesRules FindStoppingPlaceBadApplesRules 
			   GetConsumerBadApples GetHintBadApples GoToStoppingPlaceBadApplesRules 
			   SellGoodsBadApplesRules TakeTurnBadApplesRules)))
(DEFCLASSES BadApples)
[DEFCLASS BadApples
   (MetaClass PlayerMeta Edited:                             (* edited: "15-JUL-83 10:54"))
   (Supers Peddler)
   (ClassVariables (CopyCV (Icon InitializeIVs))
		   (InitializeIVs ?)
		   (Icon ?))
   (InstanceVariables (hints NIL doc                         (* List of producer consumer rating triples, in 
							     decreasing order of rating))
		      (consumer NIL doc                      (* Current consumer))
		      (producer NIL doc                      (* Current producer)))
   (Methods (BuyGas BuyGasBadApplesRules RuleSet BuyGasBadApplesRules doc 
                                                             (* RuleSet BuyGasTravelerRules is installed as the 
							     selector BuyGas of the class Traveler))
	    (FindBandits BadApples.FindBandits args NIL doc 
                                                             (* Finds all roadstops wibandits, returns list)
			 )
	    (EvalBoard BadApples.EvalBoard args (ourTruck)
		       doc                                   (* Evaluates all producer-consumer pairs on the board, 
							     and returns a list of the top few, according to Dave's 
							     handy-dandy evaluation function)
		       )
	    (TakeTurn TakeTurnBadApplesRules RuleSet TakeTurnBadApplesRules args NIL doc 
                                                             (* RuleSet TakeTurnPeddlerRules is installed as the 
							     selector TakeTurn of the class Peddler))
	    (GetHint GetHintBadApples RuleSet GetHintBadApples)
	    (GetConsumer GetConsumerBadApples RuleSet GetConsumerBadApples)
	    (GoToStoppingPlace GoToStoppingPlaceBadApplesRules RuleSet 
			       GoToStoppingPlaceBadApplesRules doc 
                                                             (* RuleSet GoToStoppingPlacePeddlerRules is installed as
							     the selector GoToStoppingPlace of the class Peddler)
			       )
	    (SellGoods SellGoodsBadApplesRules RuleSet SellGoodsBadApplesRules doc 
                                                             (* RuleSet SellGoodsPeddlerRules is installed as the 
							     selector SellGoods of the class Peddler))
	    (FindStoppingPlace FindStoppingPlaceBadApplesRules RuleSet 
			       FindStoppingPlaceBadApplesRules doc 
                                                             (* RuleSet FindStoppingPlacePeddlerRules is installed as
							     the selector FindStoppingPlace of the class Peddler)
			       ))]

(DEFINST RuleSet (BuyGasBadApplesRules "LNS.0.5349.128.61126.2")
	 (perspectiveNode #&(RuleSetNode "LNS.0.5349.128.61126.3") myViewName RuleSet)
	 (name #(BuyGasBadApplesRules NIL RememberName))
	 (compiledRules BuyGasBadApplesRules)
	 (workSpace BadApples)
	 (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))



(DEFINST RuleSet (FindStoppingPlaceBadApplesRules "LOS.0.5349.128.29386.107")
	 (perspectiveNode #&(RuleSetNode "LOS.0.5349.128.29386.146") myViewName RuleSet)
	 (name #(FindStoppingPlaceBadApplesRules NIL RememberName))
	 (compiledRules FindStoppingPlaceBadApplesRules)
	 (workSpace BadApples)
	 (args NIL)
	 (tempVars (roughRoad gasStation))
	 (taskVars NIL)
	 (debugVars NIL)
	 (numRules 7)
	 (controlStructure DO1)
	 (whileCondition NIL)
	 (compilerOptions NIL)
	 (auditClass NIL)
	 (metaAssignments NIL)
	 (ruleClass NIL)
	 (taskClass))



(DEFINST RuleSet (GetConsumerBadApples "LOS.0.5349.128.29386.67")
	 (perspectiveNode #&(RuleSetNode "LOS.0.5349.128.29386.147"))
	 (name #(GetConsumerBadApples NIL RememberName))
	 (compiledRules GetConsumerBadApples)
	 (workSpace BadApples)
	 (args NIL)
	 (tempVars (cargo))
	 (taskVars NIL)
	 (debugVars NIL)
	 (numRules 4)
	 (controlStructure DOALL)
	 (whileCondition NIL)
	 (compilerOptions NIL)
	 (auditClass NIL)
	 (metaAssignments NIL)
	 (ruleClass NIL)
	 (taskClass))



(DEFINST RuleSet (GetHintBadApples "LNS.0.5349.128.61126.127")
	 (perspectiveNode #&(RuleSetNode "LNS.0.5349.128.61126.168"))
	 (name #(GetHintBadApples NIL RememberName))
	 (compiledRules GetHintBadApples)
	 (workSpace BadApples)
	 (args NIL)
	 (tempVars NIL)
	 (taskVars NIL)
	 (debugVars NIL)
	 (numRules 3)
	 (controlStructure WHILEALL)
	 (whileCondition (ruleApplied))
	 (compilerOptions NIL)
	 (auditClass NIL)
	 (metaAssignments NIL)
	 (ruleClass NIL)
	 (taskClass))



(DEFINST RuleSet (GoToStoppingPlaceBadApplesRules "LOS.0.5349.128.29386.103")
	 (perspectiveNode #&(RuleSetNode "LOS.0.5349.128.29386.148") myViewName RuleSet)
	 (name #(GoToStoppingPlaceBadApplesRules NIL RememberName))
	 (compiledRules GoToStoppingPlaceBadApplesRules)
	 (workSpace BadApples)
	 (args NIL)
	 (tempVars (realLocation numBuy))
	 (taskVars NIL)
	 (debugVars NIL)
	 (numRules 7)
	 (controlStructure DOALL)
	 (whileCondition NIL)
	 (compilerOptions NIL)
	 (auditClass NIL)
	 (metaAssignments NIL)
	 (ruleClass NIL)
	 (taskClass))



(DEFINST RuleSet (SellGoodsBadApplesRules "LOS.0.5349.128.29386.106")
	 (perspectiveNode #&(RuleSetNode "LOS.0.5349.128.29386.149") myViewName RuleSet)
	 (name #(SellGoodsBadApplesRules NIL RememberName))
	 (compiledRules SellGoodsBadApplesRules)
	 (workSpace BadApples)
	 (args NIL)
	 (tempVars (cargo sellQty))
	 (taskVars NIL)
	 (debugVars NIL)
	 (numRules 3)
	 (controlStructure DOALL)
	 (whileCondition NIL)
	 (compilerOptions NIL)
	 (auditClass NIL)
	 (metaAssignments NIL)
	 (ruleClass NIL)
	 (taskClass))



(DEFINST RuleSet (TakeTurnBadApplesRules "LNS.0.5349.128.61126.119")
	 (perspectiveNode #&(RuleSetNode "LNS.0.5349.128.61126.169") myViewName RuleSet)
	 (name #(TakeTurnBadApplesRules NIL RememberName))
	 (compiledRules TakeTurnBadApplesRules)
	 (workSpace BadApples)
	 (args NIL)
	 (tempVars (possibleStops))
	 (taskVars NIL)
	 (debugVars NIL)
	 (numRules 11)
	 (controlStructure DOALL)
	 (whileCondition NIL)
	 (compilerOptions NIL)
	 (auditClass NIL)
	 (metaAssignments NIL)
	 (ruleClass NIL)
	 (taskClass))



(DEFINST RuleSetNode ("LNS.0.5349.128.61126.3")
	 (perspectives ? RuleSet #&(RuleSet "LNS.0.5349.128.61126.2") Source 
		       #&(RuleSetSource "LNS.0.5349.128.61126.4")))



(DEFINST RuleSetNode ("LOS.0.5349.128.29386.146")
	 (perspectives ? RuleSet #&(RuleSet "LOS.0.5349.128.29386.107") Source 
		       #&(RuleSetSource "LOS.0.5349.128.29386.150")))



(DEFINST RuleSetNode ("LOS.0.5349.128.29386.147")
	 (perspectives ? RuleSet #&(RuleSet "LOS.0.5349.128.29386.67") Source 
		       #&(RuleSetSource "LOS.0.5349.128.29386.151")))



(DEFINST RuleSetNode ("LNS.0.5349.128.61126.168")
	 (perspectives ? RuleSet #&(RuleSet "LNS.0.5349.128.61126.127") Source 
		       #&(RuleSetSource "LNS.0.5349.128.61126.170")))



(DEFINST RuleSetNode ("LOS.0.5349.128.29386.148")
	 (perspectives ? RuleSet #&(RuleSet "LOS.0.5349.128.29386.103") Source 
		       #&(RuleSetSource "LOS.0.5349.128.29386.152")))



(DEFINST RuleSetNode ("LOS.0.5349.128.29386.149")
	 (perspectives ? RuleSet #&(RuleSet "LOS.0.5349.128.29386.106") Source 
		       #&(RuleSetSource "LOS.0.5349.128.29386.153")))



(DEFINST RuleSetNode ("LNS.0.5349.128.61126.169")
	 (perspectives ? RuleSet #&(RuleSet "LNS.0.5349.128.61126.119") Source 
		       #&(RuleSetSource "LNS.0.5349.128.61126.171")))



(DEFINST RuleSetSource ("LNS.0.5349.128.61126.4")
	 (indexedVars ((#&(Rule "LNS.0.5349.128.61126.5"))
		       (#&(Rule "LNS.0.5349.128.61126.6"))))
	 (perspectiveNode #&(RuleSetNode "LNS.0.5349.128.61126.3") myViewName Source)
	 (created "27-JAN-83 00:31:21")
	 (creator STEFIK)
	 (edited "14-JUL-83 17:02:59")
	 (editor OUSTERHOUT))



(DEFINST RuleSetSource ("LOS.0.5349.128.29386.150")
	 (indexedVars ((#&(Rule "LOS.0.0.170.55978.2"))
		       (#&(Rule "LOS.0.0.170.55978.3"))
		       (#&(Rule "LOS.0.0.170.55978.4"))
		       (#&(Rule "LOS.0.0.170.55978.5"))
		       (#&(Rule "LOS.0.0.170.55978.6"))
		       (#&(Rule "LOS.0.0.170.55978.7"))
		       (#&(Rule "LOS.0.0.170.55978.8"))))
	 (perspectiveNode #&(RuleSetNode "LOS.0.5349.128.29386.146") myViewName Source)
	 (created " 1-FEB-83 14:25:23")
	 (creator LOOPSCOURSE)
	 (edited "15-JUL-83 15:48:28")
	 (editor OUSTERHOUT))



(DEFINST RuleSetSource ("LOS.0.5349.128.29386.151")
	 (indexedVars ((#&(Rule "LOS.0.5349.128.29386.154"))
		       (#&(Rule "LOS.0.5349.128.29386.155"))
		       (#&(Rule "LOS.0.5349.128.29386.156"))
		       (#&(Rule "LOS.0.5349.128.29386.157"))))
	 (perspectiveNode #&(RuleSetNode "LOS.0.5349.128.29386.147"))
	 (created "15-JUL-83 09:06:24")
	 (creator LOOPSCOURSE)
	 (edited "15-JUL-83 10:50:28")
	 (editor OUSTERHOUT))



(DEFINST RuleSetSource ("LNS.0.5349.128.61126.170")
	 (indexedVars ((#&(Rule "LOS.0.5349.128.29386.86"))
		       (#&(Rule "LOS.0.5349.128.29386.158"))
		       (#&(Rule "LOS.0.5349.128.29386.87"))))
	 (perspectiveNode #&(RuleSetNode "LNS.0.5349.128.61126.168"))
	 (created "15-JUL-83 00:57:21")
	 (creator LOOPSCOURSE)
	 (edited "15-JUL-83 09:50:28")
	 (editor OUSTERHOUT))



(DEFINST RuleSetSource ("LOS.0.5349.128.29386.152")
	 (indexedVars ((#&(Rule "LOS.0.5349.128.29386.125"))
		       (#&(Rule "LOS.0.5349.128.29386.159"))
		       (#&(Rule "LOS.0.5349.128.29386.160"))
		       (#&(Rule "LOS.0.5349.128.29386.161"))
		       (#&(Rule "LOS.0.5349.128.29386.162"))
		       (#&(Rule "LOS.0.5349.128.29386.163"))
		       (#&(Rule "LOS.0.5349.128.29386.164"))))
	 (perspectiveNode #&(RuleSetNode "LOS.0.5349.128.29386.148") myViewName Source)
	 (created " 1-FEB-83 14:25:34")
	 (creator LOOPSCOURSE)
	 (edited "15-JUL-83 10:35:22")
	 (editor OUSTERHOUT))



(DEFINST RuleSetSource ("LOS.0.5349.128.29386.153")
	 (indexedVars ((#&(Rule "LOS.0.5349.128.29386.165"))
		       (#&(Rule "LOS.0.5349.128.29386.166"))
		       (#&(Rule "LOS.0.5349.128.29386.167"))
		       (#&(Rule "LESC@8BT"))
		       (#&(Rule "LESC@8BU"))
		       (#&(Rule "LESC@8BV"))
		       (#&(Rule "FBS@@A?b"))
		       (#&(Rule "FBS@@A?c"))))
	 (perspectiveNode #&(RuleSetNode "LOS.0.5349.128.29386.149") myViewName Source)
	 (created " 1-FEB-83 14:25:40")
	 (creator LOOPSCOURSE)
	 (edited "15-JUL-83 10:20:13")
	 (editor OUSTERHOUT))



(DEFINST RuleSetSource ("LNS.0.5349.128.61126.171")
	 (indexedVars ((#&(Rule "LOS.0.0.170.43386.19"))
		       (#&(Rule "LOS.0.0.170.43386.26"))
		       (#&(Rule "LOS.0.0.170.43386.27"))
		       (#&(Rule "LOS.0.0.170.43386.28"))
		       (#&(Rule "LOS.0.0.170.43386.20"))
		       (#&(Rule "LOS.0.0.170.43386.21"))
		       (#&(Rule "LOS.0.0.170.43386.22"))
		       (#&(Rule "LOS.0.0.170.43386.23"))
		       (#&(Rule "LOS.0.0.170.43386.24"))
		       (#&(Rule "LOS.0.0.170.43386.25"))
		       (#&(Rule "LOS.0.0.170.43386.29"))))
	 (perspectiveNode #&(RuleSetNode "LNS.0.5349.128.61126.169") myViewName Source)
	 (created " 1-FEB-83 14:25:51")
	 (creator LOOPSCOURSE)
	 (edited "15-JUL-83 13:14:39")
	 (editor OUSTERHOUT))



(DEFINST Rule ("LNS.0.5349.128.61126.5")
	 (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 "14-JUL-83 17:02:59")
	 (editor OUSTERHOUT)
	 (ruleNumber 1)
	 (ruleSet #&(RuleSet "LNS.0.5349.128.61126.2")))



(DEFINST Rule ("LNS.0.5349.128.61126.6")
	 (source 

"(* Now appropriate quantity has been computed)

    IF qty>=1
     THEN  (← \PlayerInterface Buy self qty );")
	 (edited "14-JUL-83 17:02:59")
	 (editor OUSTERHOUT)
	 (ruleNumber 2)
	 (ruleSet #&(RuleSet "LNS.0.5349.128.61126.2")))



(DEFINST Rule ("LOS.0.0.170.55978.2")
	 (source 

"(* Returns a stopping place en route to a destination.)

IF truck:fuel=0 goal goal='Peddle
THEN stoppingPlace←(AnyRoadStop $UnionHall);")
	 (edited "15-JUL-83 15:48:28")
	 (editor OUSTERHOUT)
	 (ruleNumber 1)
	 (ruleSet #&(RuleSet "LOS.0.5349.128.29386.107")))



(DEFINST Rule ("LOS.0.0.170.55978.3")
	 (source "IF truck:cashBox < 3000 ~truck:cargo
THEN stoppingPlace←(AnyRoadStop $UnionHall);")
	 (edited "15-JUL-83 15:48:28")
	 (editor OUSTERHOUT)
	 (ruleNumber 2)
	 (ruleSet #&(RuleSet "LOS.0.5349.128.29386.107")))



(DEFINST Rule ("LOS.0.0.170.55978.4")
	 (source 

"(* Dont run out of gas.)
IF goal~='SitTight 
   truck:fuel < .4 * truck::MaxFuel
   truck:cashBox>0
   gasStation←(NearestRoadStop (RoadStops $GasStation .Range1 NIL 'Room))
THEN stoppingPlace←gasStation;")
	 (edited "15-JUL-83 15:48:28")
	 (editor OUSTERHOUT)
	 (ruleNumber 3)
	 (ruleSet #&(RuleSet "LOS.0.5349.128.29386.107")))



(DEFINST Rule ("LOS.0.0.170.55978.5")
	 (source 

"(* Obey the law - stop at rough road for fragile goods.)
IF truck:cargo (ISA (CAR truck:cargo) $FragileCommodity)
   roughRoad←(NearestRoadStop (RoadStops $RoughRoad .Range1 direction 'Room))
   (Distance roughRoad)<(Distance destination) 
THEN stoppingPlace←roughRoad;")
	 (edited "15-JUL-83 15:48:28")
	 (editor OUSTERHOUT)
	 (ruleNumber 4)
	 (ruleSet #&(RuleSet "LOS.0.5349.128.29386.107")))



(DEFINST Rule ("LOS.0.0.170.55978.6")
	 (source 
   "IF (Distance destination)<=.Range1 (RoomToParkP destination)
THEN stoppingPlace←destination;")
	 (edited "15-JUL-83 15:48:28")
	 (editor OUSTERHOUT)
	 (ruleNumber 5)
	 (ruleSet #&(RuleSet "LOS.0.5349.128.29386.107")))



(DEFINST Rule ("LOS.0.0.170.55978.7")
	 (source 

"IF gasStation←(FurthestRoadStop (RoadStops $GasStation .Range1 direction 'Room))
   gasStation:qty>0
THEN stoppingPlace←gasStation;")
	 (edited "15-JUL-83 15:48:28")
	 (editor OUSTERHOUT)
	 (ruleNumber 6)
	 (ruleSet #&(RuleSet "LOS.0.5349.128.29386.107")))



(DEFINST Rule ("LOS.0.0.170.55978.8")
	 (source "THEN stoppingPlace←(NthRoadStop  maxMove direction NIL 'Room);")
	 (edited "15-JUL-83 15:48:28")
	 (editor OUSTERHOUT)
	 (ruleNumber 7)
	 (ruleSet #&(RuleSet "LOS.0.5349.128.29386.107")))



(DEFINST Rule ("LOS.0.5349.128.29386.154")
	 (source "THEN cargo ← (CAR truck:cargo);")
	 (edited "15-JUL-83 10:50:28")
	 (editor OUSTERHOUT)
	 (ruleNumber 1)
	 (ruleSet #&(RuleSet "LOS.0.5349.128.29386.67")))



(DEFINST Rule ("LOS.0.5349.128.29386.155")
	 (source "THEN destination ← consumer;")
	 (edited "15-JUL-83 10:50:28")
	 (editor OUSTERHOUT)
	 (ruleNumber 2)
	 (ruleSet #&(RuleSet "LOS.0.5349.128.29386.67")))



(DEFINST Rule ("LOS.0.5349.128.29386.156")
	 (source 

"(* If our initial consumer couldn't buy, then choose any other)

IF consumer:qty=0
    THEN destination ← (NearestRoadStop (Buyers cargo));")
	 (edited "15-JUL-83 10:50:28")
	 (editor OUSTERHOUT)
	 (ruleNumber 3)
	 (ruleSet #&(RuleSet "LOS.0.5349.128.29386.67")))



(DEFINST Rule ("LOS.0.5349.128.29386.157")
	 (source 

"(* If we've got garbage or no consumer, then go to the City Dump)

IF (OR ~consumer ~cargo:status)
    THEN destination ← (NearestRoadStop (RoadStops $CityDump));")
	 (edited "15-JUL-83 10:50:28")
	 (editor OUSTERHOUT)
	 (ruleNumber 4)
	 (ruleSet #&(RuleSet "LOS.0.5349.128.29386.67")))



(DEFINST Rule ("LOS.0.5349.128.29386.86")
	 (source 

"IF ~hints
    THEN hints ← (← self EvalBoard truck)
    producer ← (CAAR hints)
    consumer ← (CADAR hints);")
	 (edited "15-JUL-83 09:50:28")
	 (editor OUSTERHOUT)
	 (ruleNumber 1)
	 (ruleSet #&(RuleSet "LNS.0.5349.128.61126.127")))



(DEFINST Rule ("LOS.0.5349.128.29386.158")
	 (source "IF ~hints THEN (STOP NIL 'NoGoodMove 'GaveUp);")
	 (edited "15-JUL-83 09:50:28")
	 (editor OUSTERHOUT)
	 (ruleNumber 2)
	 (ruleSet #&(RuleSet "LNS.0.5349.128.61126.127")))



(DEFINST Rule ("LOS.0.5349.128.29386.87")
	 (source 

"IF (OR producer:qty<1  consumer:qty<1 (AnyBanditsP producer consumer))
    THEN hints ← (CDR hints)
    producer ← (CAAR hints)
    consumer ← (CADAR hints);")
	 (edited "15-JUL-83 09:50:28")
	 (editor OUSTERHOUT)
	 (ruleNumber 3)
	 (ruleSet #&(RuleSet "LNS.0.5349.128.61126.127")))



(DEFINST Rule ("LOS.0.5349.128.29386.125")
	 (source "	-> direction←(DirectionOf destination);")
	 (edited "15-JUL-83 10:35:22")
	 (editor OUSTERHOUT)
	 (ruleNumber 1)
	 (ruleSet #&(RuleSet "LOS.0.5349.128.29386.103")))



(DEFINST Rule ("LOS.0.5349.128.29386.159")
	 (source "        -> realLocation←truck:location;")
	 (edited "15-JUL-83 10:35:22")
	 (editor OUSTERHOUT)
	 (ruleNumber 2)
	 (ruleSet #&(RuleSet "LOS.0.5349.128.29386.103")))



(DEFINST Rule ("LOS.0.5349.128.29386.160")
	 (source 

"	IF .FindStoppingPlace stoppingPlace~=truck:location
          ~stoppingPlace.BanditP
	THEN (← \PlayerInterface Move self stoppingPlace)
               realLocation←truck:location;")
	 (edited "15-JUL-83 10:35:22")
	 (editor OUSTERHOUT)
	 (ruleNumber 3)
	 (ruleSet #&(RuleSet "LOS.0.5349.128.29386.103")))



(DEFINST Rule ("LOS.0.5349.128.29386.161")
	 (source 

"        IF realLocation~=stoppingPlace 
	THEN (WriteGameStatus %"Oh!! %" driver %" Didnt reach stoppingPlace%");")
	 (edited "15-JUL-83 10:35:22")
	 (editor OUSTERHOUT)
	 (ruleNumber 4)
	 (ruleSet #&(RuleSet "LOS.0.5349.128.29386.103")))



(DEFINST Rule ("LOS.0.5349.128.29386.162")
	 (source "	IF (ISA realLocation $GasStation)
	THEN .BuyGas;")
	 (edited "15-JUL-83 10:35:22")
	 (editor OUSTERHOUT)
	 (ruleNumber 5)
	 (ruleSet #&(RuleSet "LOS.0.5349.128.29386.103")))



(DEFINST Rule ("LOS.0.5349.128.29386.163")
	 (source 

"	IF goal='Peddle
	   realLocation=producer 
           numBuy←(← self MaxPurchase realLocation)
           numBuy>=1  
	THEN (← \PlayerInterface Buy self numBuy);")
	 (edited "15-JUL-83 10:35:22")
	 (editor OUSTERHOUT)
	 (ruleNumber 6)
	 (ruleSet #&(RuleSet "LOS.0.5349.128.29386.103")))



(DEFINST Rule ("LOS.0.5349.128.29386.164")
	 (source 
	"	IF (ISA realLocation $Consumer) realLocation=destination truck:cargo
	THEN .SellGoods;")
	 (edited "15-JUL-83 10:35:22")
	 (editor OUSTERHOUT)
	 (ruleNumber 7)
	 (ruleSet #&(RuleSet "LOS.0.5349.128.29386.103")))



(DEFINST Rule ("LOS.0.5349.128.29386.165")
	 (source "	-> cargo←(CAR truck:cargo);")
	 (edited "15-JUL-83 10:20:13")
	 (editor OUSTERHOUT)
	 (ruleNumber 1)
	 (ruleSet #&(RuleSet "LOS.0.5349.128.29386.106")))



(DEFINST Rule ("LOS.0.5349.128.29386.166")
	 (source 
	 "	IF ~(ISA cargo truck:location::Commodity)
	THEN (STOP NIL 'NoSale 'WrongKindOfBuyer);")
	 (edited "15-JUL-83 10:20:13")
	 (editor OUSTERHOUT)
	 (ruleNumber 2)
	 (ruleSet #&(RuleSet "LOS.0.5349.128.29386.106")))



(DEFINST Rule ("LOS.0.5349.128.29386.167")
	 (source 

"	IF cargo:status sellQty←(MIN truck:location:qty cargo:qty) sellQty>=1 
	THEN (← \PlayerInterface Sell self cargo sellQty);")
	 (edited "15-JUL-83 10:20:13")
	 (editor OUSTERHOUT)
	 (ruleNumber 3)
	 (ruleSet #&(RuleSet "LOS.0.5349.128.29386.106")))



(DEFINST Rule ("LESC@8BT")
	 (source "	IF truck:location:pr < 0 
	THEN (STOP NIL 'NoSale 'NeverSellAtLoss);")
	 (edited " 5-JUL-83 11:57:52")
	 (editor MITTAL)
	 (ruleNumber 4)
	 (ruleSet #&(RuleSet "FRSC@$PC")))



(DEFINST Rule ("LESC@8BU")
	 (source 

"(* Make sale as limited by cargo and consumer.)

IF ~cargo:status (ISA truck:location $CityDump)
THEN sellQty←(MIN truck:location:qty cargo:qty) 
     (← \PlayerInterface Sell self cargo sellQty)
     (STOP T 'Sold 'AtCityDump);")
	 (edited " 5-JUL-83 11:57:52")
	 (editor MITTAL)
	 (ruleNumber 5)
	 (ruleSet #&(RuleSet "FRSC@$PC")))



(DEFINST Rule ("LESC@8BV")
	 (source 

"	IF cargo:status sellQty←(MIN truck:location:qty cargo:qty) sellQty>=1 
	THEN (← \PlayerInterface Sell self cargo sellQty);")
	 (edited " 5-JUL-83 11:57:52")
	 (editor MITTAL)
	 (ruleNumber 6)
	 (ruleSet #&(RuleSet "FRSC@$PC")))



[DEFINST Rule ("FBS@@A?b")
	 (source NIL)
	 (edited " 2-FEB-83 14:52:20")
	 (editor "LOOPSCOURSE")
	 (ruleNumber 7)
	 (ruleSet #&(RuleSet "FAS@@&Lr"))
	 (lhs (AND (PROGN                                    (* Rule Tracing Code)
			  (TraceLHS NIL 7)
			  (← (GetObjFromUID "FBS@@A?b")
			     Print))
		   (EQ cQty sellQty)))
	 (rhs (SETQ ↑value (PROGN (PROGN                     (* Make an audit record for this rule and set its audit 
							     values.)
					 (SETQ ↑auditRecord (← (GetObjFromUID "FAS@@<\")
							       NewTemp))
					 (PutValue ↑auditRecord (QUOTE rule)
						   (GetObjFromUID "FBS@@A?b")))
				  (PROGN                     (* Rule Tracing Code)
					 (TraceRHS NIL 7)
					 (← (GetObjFromUID "FBS@@A?b")
					    Print))
				  (PutAuditRec self (QUOTE goal)
					       (QUOTE Buy)
					       ↑auditRecord)
				  (PutAuditRec self (QUOTE destination)
					       NIL ↑auditRecord]



[DEFINST Rule ("FBS@@A?c")
	 (source NIL)
	 (edited " 2-FEB-83 14:52:20")
	 (editor "LOOPSCOURSE")
	 (ruleNumber 8)
	 (ruleSet #&(RuleSet "FAS@@&Lr"))
	 (lhs (AND (PROGN                                    (* Rule Tracing Code)
			  (TraceLHS NIL 8)
			  (← (GetObjFromUID "FBS@@A?c")
			     Print))
		   (LESSP sellQty cQty)))
	 (rhs (SETQ ↑value (PROGN (PROGN                     (* Make an audit record for this rule and set its audit 
							     values.)
					 (SETQ ↑auditRecord (← (GetObjFromUID "FAS@@<\")
							       NewTemp))
					 (PutValue ↑auditRecord (QUOTE rule)
						   (GetObjFromUID "FBS@@A?c")))
				  (PROGN                     (* Rule Tracing Code)
					 (TraceRHS NIL 8)
					 (← (GetObjFromUID "FBS@@A?c")
					    Print))
				  (PutAuditRec self (QUOTE destination)
					       (NearestRoadStop (Buyers cargo1))
					       ↑auditRecord)
				  (PutAuditRec self (QUOTE direction)
					       (DirectionOf (GetValue self (QUOTE destination)))
					       ↑auditRecord]



(DEFINST Rule ("LOS.0.0.170.43386.19")
	 (source 

"   (* Top-Level RuleSet for taking turns.  Sets goal and destination.)

 IF ~goal
  THEN goal←'Peddle;")
	 (edited "15-JUL-83 13:14:39")
	 (editor OUSTERHOUT)
	 (ruleNumber 1)
	 (ruleSet #&(RuleSet "LNS.0.5349.128.61126.119")))



(DEFINST Rule ("LOS.0.0.170.43386.26")
	 (source " IF goal='Peddle ~truck:cargo THEN .GetHint;")
	 (edited "15-JUL-83 13:14:39")
	 (editor OUSTERHOUT)
	 (ruleNumber 2)
	 (ruleSet #&(RuleSet "LNS.0.5349.128.61126.119")))



(DEFINST Rule ("LOS.0.0.170.43386.27")
	 (source " IF goal='Peddle ~hints
    THEN (STOP NIL 'NoMove 'WeWillWait);")
	 (edited "15-JUL-83 13:14:39")
	 (editor OUSTERHOUT)
	 (ruleNumber 3)
	 (ruleSet #&(RuleSet "LNS.0.5349.128.61126.119")))



(DEFINST Rule ("LOS.0.0.170.43386.28")
	 (source " IF goal='Peddle truck:cargo
    THEN .GetConsumer;")
	 (edited "15-JUL-83 13:14:39")
	 (editor OUSTERHOUT)
	 (ruleNumber 4)
	 (ruleSet #&(RuleSet "LNS.0.5349.128.61126.119")))



(DEFINST Rule ("LOS.0.0.170.43386.20")
	 (source " IF goal='Peddle ~truck:cargo
    THEN destination←producer;")
	 (edited "15-JUL-83 13:14:39")
	 (editor OUSTERHOUT)
	 (ruleNumber 5)
	 (ruleSet #&(RuleSet "LNS.0.5349.128.61126.119")))



(DEFINST Rule ("LOS.0.0.170.43386.21")
	 (source 

" 
 IF goal='Peddle truck:fuel< .7*truck::MaxFuel
    THEN destination←(NearestRoadStop (RoadStops $GasStation));")
	 (edited "15-JUL-83 13:14:39")
	 (editor OUSTERHOUT)
	 (ruleNumber 6)
	 (ruleSet #&(RuleSet "LNS.0.5349.128.61126.119")))



(DEFINST Rule ("LOS.0.0.170.43386.22")
	 (source 

"(* Don't move away from Alices during endgame.)
 IF goal='GoToAlices truck:location=alices
  THEN goal←'SitTight;")
	 (edited "15-JUL-83 13:14:39")
	 (editor OUSTERHOUT)
	 (ruleNumber 7)
	 (ruleSet #&(RuleSet "LNS.0.5349.128.61126.119")))



(DEFINST Rule ("LOS.0.0.170.43386.23")
	 (source 

"(* Except dont overstay at Alices.)
IF truck:location=alices  .TimeAtStop > 25 goal='SitTight
 THEN alices←(NearestRoadStop (RoadStops $AlicesRestaurant))
       destination← (PickHiObj self 'RateSpotsNearAlices (RoadStops))
       goal←'GetClose;")
	 (edited "15-JUL-83 13:14:39")
	 (editor OUSTERHOUT)
	 (ruleNumber 8)
	 (ruleSet #&(RuleSet "LNS.0.5349.128.61126.119")))



(DEFINST Rule ("LOS.0.0.170.43386.24")
	 (source 

"(* Get near to Alices when time gets close)		
 IF \Simulator:timeLeft < 100 ~[goal<<'(SitTight GetClose GoToAlices)]  
  THEN alices←(NearestRoadStop (RoadStops $AlicesRestaurant))
       destination← (PickHiObj self 'RateSpotsNearAlices (RoadStops))
       goal←'GetClose;")
	 (edited "15-JUL-83 13:14:39")
	 (editor OUSTERHOUT)
	 (ruleNumber 9)
	 (ruleSet #&(RuleSet "LNS.0.5349.128.61126.119")))



(DEFINST Rule ("LOS.0.0.170.43386.25")
	 (source 

"(* Go to Alices now that it is time)
 IF \Simulator:timeLeft < 30 
    ~(ISA truck:location $AlicesRestaurant)   
  THEN destination← (NearestRoadStop (RoadStops $AlicesRestaurant))
       goal←'GoToAlices ;")
	 (edited "15-JUL-83 13:14:39")
	 (editor OUSTERHOUT)
	 (ruleNumber 10)
	 (ruleSet #&(RuleSet "LNS.0.5349.128.61126.119")))



(DEFINST Rule ("LOS.0.0.170.43386.29")
	 (source 

"IF ~(OR goal='SitTight 
       (AND goal='GetClose (Distance truck:location alices)<=3))
 THEN .GoToStoppingPlace;")
	 (edited "15-JUL-83 13:14:39")
	 (editor OUSTERHOUT)
	 (ruleNumber 11)
	 (ruleSet #&(RuleSet "LNS.0.5349.128.61126.119")))



(DEFINST RuleSet (SellGoodsPeddlerRules "FRSC@$PC")
	 (perspectiveNode #&(RuleSetNode "FRSC@$PH") myViewName RuleSet)
	 (name #(SellGoodsPeddlerRules NIL RememberName))
	 (compiledRules SellGoodsPeddlerRules)
	 (workSpace Peddler)
	 (args NIL)
	 (tempVars (cargo sellQty))
	 (taskVars NIL)
	 (debugVars NIL)
	 (numRules 6)
	 (controlStructure DOALL)
	 (whileCondition NIL)
	 (compilerOptions NIL)
	 (auditClass NIL)
	 (metaAssignments NIL)
	 (ruleClass NIL)
	 (taskClass)
	 (arguments))



(DEFINST RuleSet (SellGoodsToyotaRules "FAS@@&Lr")
	 (perspectiveNode #&(RuleSetNode "FAS@@&Mj") myViewName RuleSet)
	 (name #(SellGoodsToyotaRules NIL RememberName))
	 (compiledRules SellGoodsToyotaRules)
	 (workSpace Toyota)
	 (args)
	 (tempVars (cargo sellQty))
	 (taskVars NIL)
	 (debugVars NIL)
	 (numRules 4)
	 (controlStructure DOALL)
	 (whileCondition NIL)
	 (compilerOptions NIL)
	 (auditClass NIL)
	 (metaAssignments NIL)
	 (ruleClass NIL)
	 (taskClass)
	 (arguments))



(DEFINST RuleSetNode ("FRSC@$PH")
	 (perspectives ? RuleSet #&(RuleSet "FRSC@$PC") Source #&(RuleSetSource "FRSC@$PM")))



(DEFINST RuleSetNode ("FAS@@&Mj")
	 (perspectives ? RuleSet #&(RuleSet "FAS@@&Lr") Source #&(RuleSetSource "FAS@@&Mp")))



(DEFINST RuleSetSource ("FRSC@$PM")
	 (indexedVars ((#&(Rule "LESC@8BQ"))
		       (#&(Rule "LESC@8BR"))
		       (#&(Rule "LESC@8BS"))
		       (#&(Rule "LESC@8BT"))
		       (#&(Rule "LESC@8BU"))
		       (#&(Rule "LESC@8BV"))
		       (#&(Rule "FBS@@A?b"))
		       (#&(Rule "FBS@@A?c"))))
	 (perspectiveNode #&(RuleSetNode "FRSC@$PH") myViewName Source)
	 (created " 1-FEB-83 14:25:40")
	 (creator LOOPSCOURSE)
	 (edited " 5-JUL-83 11:57:52")
	 (editor MITTAL))



(DEFINST RuleSetSource ("FAS@@&Mp")
	 (indexedVars ((#&(Rule "FPSC@$MD"))
		       (#&(Rule "FPSC@$ME"))
		       (#&(Rule "FPSC@$MF"))
		       (#&(Rule "FPSC@$MG"))
		       (#&(Rule "FBS@@A?`"))
		       (#&(Rule "FBS@@A?a"))
		       (#&(Rule "FBS@@A?b"))
		       (#&(Rule "FBS@@A?c"))))
	 (perspectiveNode #&(RuleSetNode "FAS@@&Mj") myViewName Source)
	 (created " 1-FEB-83 14:25:40")
	 (creator LOOPSCOURSE)
	 (edited "16-FEB-83 14:26:24")
	 (editor STEFIK))



(DEFINST Rule ("LESC@8BQ")
	 (source "	-> cargo←(CAR truck:cargo);")
	 (edited " 5-JUL-83 11:57:52")
	 (editor MITTAL)
	 (ruleNumber 1)
	 (ruleSet #&(RuleSet "FRSC@$PC")))



(DEFINST Rule ("LESC@8BR")
	 (source 
	 "	IF ~(ISA cargo truck:location::Commodity)
	THEN (STOP NIL 'NoSale 'WrongKindOfBuyer);")
	 (edited " 5-JUL-83 11:57:52")
	 (editor MITTAL)
	 (ruleNumber 2)
	 (ruleSet #&(RuleSet "FRSC@$PC")))



(DEFINST Rule ("LESC@8BS")
	 (source 
	  "	IF truck:location:pr < 1.1 goal='Peddle 
	THEN (STOP NIL 'NoSale 'AvoidCheapSkates);")
	 (edited " 5-JUL-83 11:57:52")
	 (editor MITTAL)
	 (ruleNumber 3)
	 (ruleSet #&(RuleSet "FRSC@$PC")))



(DEFINST Rule ("FPSC@$MD")
	 (source "	-> cargo←(CAR truck:cargo);")
	 (edited "16-FEB-83 14:26:24")
	 (editor STEFIK)
	 (ruleNumber)
	 (ruleSet #&(RuleSet "FAS@@&Lr")))



(DEFINST Rule ("FPSC@$ME")
	 (source 

"(* Abort sale if cargo has disappeared.)
	IF ~cargo
	THEN destination←NIL
	(WriteGameStatus %"Yipes! My cargo is gone!%")
	(STOP NIL 'NoSale 'NoCargo);")
	 (edited "16-FEB-83 14:26:24")
	 (editor STEFIK)
	 (ruleNumber)
	 (ruleSet #&(RuleSet "FAS@@&Lr")))



(DEFINST Rule ("FPSC@$MF")
	 (source 

"(* Make sale as limited by cargo and consumer.)

	IF sellQty←(MIN truck:location:qty cargo:qty) sellQty>0 
	THEN (← gameMaster Sell cargo sellQty);")
	 (edited "16-FEB-83 14:26:24")
	 (editor STEFIK)
	 (ruleNumber)
	 (ruleSet #&(RuleSet "FAS@@&Lr")))



(DEFINST Rule ("FPSC@$MG")
	 (source 

"(* Find another buyer if all not sold.)

	IF cargo←(CAR truck:cargo) cargo:qty>0
	THEN destination←(NearestRoadStop (Buyers truck:cargo))
	     direction←(DirectionOf destination)
	     (STOP NIL 'NoSale 'CantSell);")
	 (edited "16-FEB-83 14:26:24")
	 (editor STEFIK)
	 (ruleNumber)
	 (ruleSet #&(RuleSet "FAS@@&Lr")))



[DEFINST Rule ("FBS@@A?`")
	 (source NIL)
	 (edited " 2-FEB-83 14:52:20")
	 (editor "LOOPSCOURSE")
	 (ruleNumber 5)
	 (ruleSet #&(RuleSet "FAS@@&Lr"))
	 [lhs (AND (PROGN                                    (* Rule Tracing Code)
			  (TraceLHS NIL 5)
			  (← (GetObjFromUID "FBS@@A?`")
			     Print))
		   (OR (EQ sellQty 0)
		       (NOT (ISA cargo1 commodity]
	 (rhs (SETQ ↑value (PROGN (PROGN                     (* Make an audit record for this rule and set its audit 
							     values.)
					 (SETQ ↑auditRecord (← (GetObjFromUID "FAS@@<\")
							       NewTemp))
					 (PutValue ↑auditRecord (QUOTE rule)
						   (GetObjFromUID "FBS@@A?`")))
				  (PROGN                     (* Rule Tracing Code)
					 (TraceRHS NIL 5)
					 (← (GetObjFromUID "FBS@@A?`")
					    Print))
				  (PutAuditRec self (QUOTE destination)
					       (NearestRoadStop (Buyers cargo1))
					       ↑auditRecord)
				  (PutAuditRec self (QUOTE direction)
					       (DirectionOf (GetValue self (QUOTE destination)))
					       ↑auditRecord)
				  (PROGN                     (* ↑value set by RuleSetStop)
					 (RuleSetStop self)
					 (GO QUIT]



[DEFINST Rule ("FBS@@A?a")
	 (source NIL)
	 (edited " 2-FEB-83 14:52:20")
	 (editor "LOOPSCOURSE")
	 (ruleNumber 6)
	 (ruleSet #&(RuleSet "FAS@@&Lr"))
	 (lhs (PROGN                                         (* Rule Tracing Code)
		     (TraceLHS NIL 6)
		     (← (GetObjFromUID "FBS@@A?a")
			Print)))
	 (rhs (SETQ ↑value (PROGN (PROGN                     (* Rule Tracing Code)
					 (TraceRHS NIL 6)
					 (← (GetObjFromUID "FBS@@A?a")
					    Print))
				  (← gameMaster Sell cargo1 sellQty]



(DEFINEQ

(BESort
  [LAMBDA (a b)                                              (* edited: "14-JUL-83 23:55")
    (GREATERP (CADDR a)
	      (CADDR b])

(BadApples.EvalBoard
  [LAMBDA (self ourTruck)                                    (* edited: "15-JUL-83 12:30")
                                                             (* Evaluates all producer-consumer pairs on the board, 
							     and returns a list of the top few, according to Dave's 
							     handy-dandy evaluation function)
    (PROG (pairs distance profit maxWt maxVol cap maxDist)
          (SETQ maxWt (@@ ourTruck MaxWeight))
          (SETQ maxVol (@@ ourTruck MaxVolume))
          (SETQ maxDist (@@ ourTruck MaxDist))
          [SETQ pairs (for p in (RoadStops ($ Producer))
			 join (for c in (Buyers (@@ p Commodity)
						maxDist)
				 when (PROGN (SETQ cap (MIN (QUOTIENT maxVol (@@(@@ p Commodity)
									VolPerQty))
							    (QUOTIENT maxWt (@@(@@ p Commodity)
									WtPerQty))
							    (@ p qty)))
					     (SETQ distance (Distance c p))
					     [SETQ profit (TIMES (@@(@@ p Commodity)
								   AvgPrice)
								 cap
								 (DIFFERENCE (@ c pr)
									     (@ p pr]
					     (SETQ turns (PLUS 2 (TIMES 4 (QUOTIENT distance maxDist))
							       (QUOTIENT distance 5)))
					     (SETQ profit (QUOTIENT profit turns))
					     (GREATERP profit 10000))
				 collect (LIST p c profit]
          (SETQ pairs (SORT pairs (FUNCTION BESort)))
          (SETQ pairs (LDIFF pairs (NTH pairs 10)))
          (RETURN pairs])

(BadApples.FindBandits
  [LAMBDA (self)                                             (* edited: "14-JUL-83 20:40")
                                                             (* Finds all roadstops wibandits, returns list)
    (for X in (RoadStops) when (← X BanditP) collect X])

(BadApples.Get
  [LAMBDA (self)                                             (* edited: "15-JUL-83 09:02")
                                                             (* New method template)
    self])

(BadApples.Sort
  [LAMBDA (self)                                             (* edited: "14-JUL-83 23:53")
                                                             (* New method template)
    self])

(BuyGasBadApplesRules
  [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
	    ((GEQ qty 1)
	      (SETQ ↑value (← PlayerInterface Buy self qty]
      QUIT(RETURN ↑value])

(FindStoppingPlaceBadApplesRules
  [LAMBDA (self)
    (PROG (↑value roughRoad gasStation)
          [COND
	    [(AND (EQ (GetValue (GetValue self (QUOTE truck))
				(QUOTE fuel))
		      0)
		  (GetValue self (QUOTE goal))
		  (EQ (GetValue self (QUOTE goal))
		      (QUOTE Peddle)))
	      (SETQ ↑value (PutValue self (QUOTE stoppingPlace)
				     (AnyRoadStop ($ UnionHall]
	    [[AND (LESSP (GetValue (GetValue self (QUOTE truck))
				   (QUOTE cashBox))
			 3000)
		  (NOT (GetValue (GetValue self (QUOTE truck))
				 (QUOTE cargo]
	      (SETQ ↑value (PutValue self (QUOTE stoppingPlace)
				     (AnyRoadStop ($ UnionHall]
	    ([AND (NEQ (GetValue self (QUOTE goal))
		       (QUOTE SitTight))
		  [LESSP (GetValue (GetValue self (QUOTE truck))
				   (QUOTE fuel))
			 (TIMES .4 (GetClassValue (GetValue self (QUOTE truck))
						  (QUOTE MaxFuel]
		  (GREATERP (GetValue (GetValue self (QUOTE truck))
				      (QUOTE cashBox))
			    0)
		  (SETQ gasStation (NearestRoadStop (RoadStops ($ GasStation)
							       (← self Range1)
							       NIL
							       (QUOTE Room]
	      (SETQ ↑value (PutValue self (QUOTE stoppingPlace)
				     gasStation)))
	    ([AND (GetValue (GetValue self (QUOTE truck))
			    (QUOTE cargo))
		  (ISA (CAR (GetValue (GetValue self (QUOTE truck))
				      (QUOTE cargo)))
		       ($ FragileCommodity))
		  [SETQ roughRoad (NearestRoadStop (RoadStops ($ RoughRoad)
							      (← self Range1)
							      (GetValue self (QUOTE direction))
							      (QUOTE Room]
		  (LESSP (Distance roughRoad)
			 (Distance (GetValue self (QUOTE destination]
	      (SETQ ↑value (PutValue self (QUOTE stoppingPlace)
				     roughRoad)))
	    [[AND (LEQ (Distance (GetValue self (QUOTE destination)))
		       (← self Range1))
		  (RoomToParkP (GetValue self (QUOTE destination]
	      (SETQ ↑value (PutValue self (QUOTE stoppingPlace)
				     (GetValue self (QUOTE destination]
	    ((AND [SETQ gasStation (FurthestRoadStop (RoadStops ($ GasStation)
								(← self Range1)
								(GetValue self (QUOTE direction))
								(QUOTE Room]
		  (GREATERP (GetValue gasStation (QUOTE qty))
			    0))
	      (SETQ ↑value (PutValue self (QUOTE stoppingPlace)
				     gasStation)))
	    (T (SETQ ↑value (PutValue self (QUOTE stoppingPlace)
				      (NthRoadStop (GetValue self (QUOTE maxMove))
						   (GetValue self (QUOTE direction))
						   NIL
						   (QUOTE Room]
      QUIT(RETURN ↑value])

(GetConsumerBadApples
  [LAMBDA (self)
    (PROG (↑value cargo)
          [SETQ ↑value (SETQ cargo (CAR (GetValue (GetValue self (QUOTE truck))
						  (QUOTE cargo]
          [SETQ ↑value (PutValue self (QUOTE destination)
				 (GetValue self (QUOTE consumer]
          [COND
	    ((EQ (GetValue (GetValue self (QUOTE consumer))
			   (QUOTE qty))
		 0)
	      (SETQ ↑value (PutValue self (QUOTE destination)
				     (NearestRoadStop (Buyers cargo]
          [COND
	    ([OR (NOT (GetValue self (QUOTE consumer)))
		 (NOT (GetValue cargo (QUOTE status]
	      (SETQ ↑value (PutValue self (QUOTE destination)
				     (NearestRoadStop (RoadStops ($ CityDump]
      QUIT(RETURN ↑value])

(GetHintBadApples
  [LAMBDA (self)
    (PROG (↑value ↑prevValue ruleApplied)
          (SETQ ruleApplied T)
      cycleLoop
          (COND
	    ((NOT ruleApplied)
	      (GO QUIT)))
          (SETQ ↑value ↑noRuleApplied)
          [COND
	    ((NOT (GetValue self (QUOTE hints)))
	      (SETQ ↑value (PROGN [PutValue self (QUOTE hints)
					    (← self EvalBoard (GetValue self (QUOTE truck]
				  [PutValue self (QUOTE producer)
					    (CAAR (GetValue self (QUOTE hints]
				  (PutValue self (QUOTE consumer)
					    (CADAR (GetValue self (QUOTE hints]
          [COND
	    ((NOT (GetValue self (QUOTE hints)))
	      (SETQ ↑value (PROGN                            (* ↑value set by RuleSetStop)
				  (RuleSetStop NIL (QUOTE NoGoodMove)
					       (QUOTE GaveUp))
				  (GO QUIT]
          [COND
	    ([OR (LESSP (GetValue (GetValue self (QUOTE producer))
				  (QUOTE qty))
			1)
		 (LESSP (GetValue (GetValue self (QUOTE consumer))
				  (QUOTE qty))
			1)
		 (AnyBanditsP (GetValue self (QUOTE producer))
			      (GetValue self (QUOTE consumer]
	      (SETQ ↑value (PROGN [PutValue self (QUOTE hints)
					    (CDR (GetValue self (QUOTE hints]
				  [PutValue self (QUOTE producer)
					    (CAAR (GetValue self (QUOTE hints]
				  (PutValue self (QUOTE consumer)
					    (CADAR (GetValue self (QUOTE hints]
          (COND
	    ((EQ ↑value ↑noRuleApplied)                      (* Here if no rule applied.)
	      (SETQ ruleApplied NIL)
	      (SETQ ↑value ↑prevValue))
	    (T                                               (* Here if some rule applied.)
	       (SETQ ruleApplied T)
	       (SETQ ↑prevValue ↑value)))
          (GO cycleLoop)
      QUIT(RETURN ↑value])

(GoToStoppingPlaceBadApplesRules
  [LAMBDA (self)
    (PROG (↑value realLocation numBuy)
          [SETQ ↑value (PutValue self (QUOTE direction)
				 (DirectionOf (GetValue self (QUOTE destination]
          [SETQ ↑value (SETQ realLocation (GetValue (GetValue self (QUOTE truck))
						    (QUOTE location]
          [COND
	    ((AND (← self FindStoppingPlace)
		  (NEQ (GetValue self (QUOTE stoppingPlace))
		       (GetValue (GetValue self (QUOTE truck))
				 (QUOTE location)))
		  (NOT (← (GetValue self (QUOTE stoppingPlace))
			  BanditP)))
	      (SETQ ↑value (PROGN (← PlayerInterface Move self (GetValue self (QUOTE stoppingPlace)))
				  (SETQ realLocation (GetValue (GetValue self (QUOTE truck))
							       (QUOTE location]
          [COND
	    ((NEQ realLocation (GetValue self (QUOTE stoppingPlace)))
	      (SETQ ↑value (WriteGameStatus "Oh!! " (GetValue self (QUOTE driver))
					    " Didnt reach stoppingPlace"]
          [COND
	    ((ISA realLocation ($ GasStation))
	      (SETQ ↑value (← self BuyGas]
          [COND
	    ((AND (EQ (GetValue self (QUOTE goal))
		      (QUOTE Peddle))
		  (EQ realLocation (GetValue self (QUOTE producer)))
		  (SETQ numBuy (← self MaxPurchase realLocation))
		  (GEQ numBuy 1))
	      (SETQ ↑value (← PlayerInterface Buy self numBuy]
          [COND
	    ((AND (ISA realLocation ($ Consumer))
		  (EQ realLocation (GetValue self (QUOTE destination)))
		  (GetValue (GetValue self (QUOTE truck))
			    (QUOTE cargo)))
	      (SETQ ↑value (← self SellGoods]
      QUIT(RETURN ↑value])

(SellGoodsBadApplesRules
  [LAMBDA (self)
    (PROG (↑value cargo sellQty)
          [SETQ ↑value (SETQ cargo (CAR (GetValue (GetValue self (QUOTE truck))
						  (QUOTE cargo]
          [COND
	    ([NOT (ISA cargo (GetClassValue (GetValue (GetValue self (QUOTE truck))
						      (QUOTE location))
					    (QUOTE Commodity]
	      (SETQ ↑value (PROGN                            (* ↑value set by RuleSetStop)
				  (RuleSetStop NIL (QUOTE NoSale)
					       (QUOTE WrongKindOfBuyer))
				  (GO QUIT]
          [COND
	    ((AND (GetValue cargo (QUOTE status))
		  [SETQ sellQty (MIN (GetValue (GetValue (GetValue self (QUOTE truck))
							 (QUOTE location))
					       (QUOTE qty))
				     (GetValue cargo (QUOTE qty]
		  (GEQ sellQty 1))
	      (SETQ ↑value (← PlayerInterface Sell self cargo sellQty]
      QUIT(RETURN ↑value])

(TakeTurnBadApplesRules
  [LAMBDA (self)
    (PROG (↑value possibleStops)
          [COND
	    ((NOT (GetValue self (QUOTE goal)))
	      (SETQ ↑value (PutValue self (QUOTE goal)
				     (QUOTE Peddle]
          [COND
	    ([AND (EQ (GetValue self (QUOTE goal))
		      (QUOTE Peddle))
		  (NOT (GetValue (GetValue self (QUOTE truck))
				 (QUOTE cargo]
	      (SETQ ↑value (← self GetHint]
          [COND
	    ([AND (EQ (GetValue self (QUOTE goal))
		      (QUOTE Peddle))
		  (NOT (GetValue self (QUOTE hints]
	      (SETQ ↑value (PROGN                            (* ↑value set by RuleSetStop)
				  (RuleSetStop NIL (QUOTE NoMove)
					       (QUOTE WeWillWait))
				  (GO QUIT]
          [COND
	    ((AND (EQ (GetValue self (QUOTE goal))
		      (QUOTE Peddle))
		  (GetValue (GetValue self (QUOTE truck))
			    (QUOTE cargo)))
	      (SETQ ↑value (← self GetConsumer]
          [COND
	    ([AND (EQ (GetValue self (QUOTE goal))
		      (QUOTE Peddle))
		  (NOT (GetValue (GetValue self (QUOTE truck))
				 (QUOTE cargo]
	      (SETQ ↑value (PutValue self (QUOTE destination)
				     (GetValue self (QUOTE producer]
          [COND
	    ([AND (EQ (GetValue self (QUOTE goal))
		      (QUOTE Peddle))
		  (LESSP (GetValue (GetValue self (QUOTE truck))
				   (QUOTE fuel))
			 (TIMES .7 (GetClassValue (GetValue self (QUOTE truck))
						  (QUOTE MaxFuel]
	      (SETQ ↑value (PutValue self (QUOTE destination)
				     (NearestRoadStop (RoadStops ($ GasStation]
          [COND
	    ([AND (EQ (GetValue self (QUOTE goal))
		      (QUOTE GoToAlices))
		  (EQ (GetValue (GetValue self (QUOTE truck))
				(QUOTE location))
		      (GetValue self (QUOTE alices]
	      (SETQ ↑value (PutValue self (QUOTE goal)
				     (QUOTE SitTight]
          [COND
	    ((AND (EQ (GetValue (GetValue self (QUOTE truck))
				(QUOTE location))
		      (GetValue self (QUOTE alices)))
		  (GREATERP (← self TimeAtStop)
			    25)
		  (EQ (GetValue self (QUOTE goal))
		      (QUOTE SitTight)))
	      (SETQ ↑value (PROGN [PutValue self (QUOTE alices)
					    (NearestRoadStop (RoadStops ($ AlicesRestaurant]
				  (PutValue self (QUOTE destination)
					    (PickHiObj self (QUOTE RateSpotsNearAlices)
						       (RoadStops)))
				  (PutValue self (QUOTE goal)
					    (QUOTE GetClose]
          [COND
	    ([AND (LESSP (GetValue Simulator (QUOTE timeLeft))
			 100)
		  (NOT (FMEMB (GetValue self (QUOTE goal))
			      (QUOTE (SitTight GetClose GoToAlices]
	      (SETQ ↑value (PROGN [PutValue self (QUOTE alices)
					    (NearestRoadStop (RoadStops ($ AlicesRestaurant]
				  (PutValue self (QUOTE destination)
					    (PickHiObj self (QUOTE RateSpotsNearAlices)
						       (RoadStops)))
				  (PutValue self (QUOTE goal)
					    (QUOTE GetClose]
          [COND
	    ([AND (LESSP (GetValue Simulator (QUOTE timeLeft))
			 30)
		  (NOT (ISA (GetValue (GetValue self (QUOTE truck))
				      (QUOTE location))
			    ($ AlicesRestaurant]
	      (SETQ ↑value (PROGN [PutValue self (QUOTE destination)
					    (NearestRoadStop (RoadStops ($ AlicesRestaurant]
				  (PutValue self (QUOTE goal)
					    (QUOTE GoToAlices]
          [COND
	    ([NOT (OR (EQ (GetValue self (QUOTE goal))
			  (QUOTE SitTight))
		      (AND (EQ (GetValue self (QUOTE goal))
			       (QUOTE GetClose))
			   (LEQ (Distance (GetValue (GetValue self (QUOTE truck))
						    (QUOTE location))
					  (GetValue self (QUOTE alices)))
				3]
	      (SETQ ↑value (← self GoToStoppingPlace]
      QUIT(RETURN ↑value])
)
(DECLARE: DONTCOPY
  (FILEMAP (NIL (31364 45269 (BESort 31374 . 31522) (BadApples.EvalBoard 31524 . 32940) (
BadApples.FindBandits 32942 . 33249) (BadApples.Get 33251 . 33464) (BadApples.Sort 33466 . 33680) (
BuyGasBadApplesRules 33682 . 34550) (FindStoppingPlaceBadApplesRules 34552 . 36989) (
GetConsumerBadApples 36991 . 37681) (GetHintBadApples 37683 . 39379) (GoToStoppingPlaceBadApplesRules 
39381 . 40925) (SellGoodsBadApplesRules 40927 . 41769) (TakeTurnBadApplesRules 41771 . 45267)))))
STOP