# Rules and operators to remember locations that have food in them # and forget locations when the food has been eaten. The food locations # are organized on a stack. The stack has two dummy nodes at the beginning # and end of the linked list. # firstfood points to the dummy node at the head of the linked list. sp {elaborate*firstfood (state ^superstate nil) --> ( ^food ^firstfood ) #the dummy node at the head ( ^food ) #the dummy node at the tail ( ^nextfood ) ( ^x 0 ^y 0)} # Notice locations that have food. sp {elaborate*noticed*food*north (state ^io.input-link ) ( ^my-location.north.content << normalfood bonusfood >> ) ( ^eater ) ( ^x ^y ) --> ( ^noticed-food ) ( ^x ^y (- 1))} sp {elaborate*noticed*food*south (state ^io.input-link ) ( ^my-location.south.content << normalfood bonusfood >> ) ( ^eater ) ( ^x ^y ) --> ( ^noticed-food ) ( ^x ^y (+ 1))} sp {elaborate*noticed*food*east (state ^io.input-link ) ( ^my-location.east.content << normalfood bonusfood >> ) ( ^eater ) ( ^x ^y ) --> ( ^noticed-food ) ( ^x (+ 1 ) ^y )} sp {elaborate*noticed*food*west (state ^io.input-link ) ( ^my-location.west.content << normalfood bonusfood >> ) ( ^eater ) ( ^x ^y ) --> ( ^noticed-food ) ( ^x (- 1 ) ^y )} # Operator to remember food sp {propose*remember*food (state ^noticed-food ) ( ^x ^y ) - {( ^food ) ( ^x ^y )} --> ( ^operator + =) ( ^name remember ^x ^y )} sp {apply*remember*food (state ^operator ) ( ^name remember ^x ^y ) ( ^firstfood ) #head of stack of food locations ( ^firstfood.nextfood ) #first actual food location --> ( ^food ) ( ^x ^y ^nextfood ) ( ^nextfood - ) ( ^nextfood )} # Operator to forget food sp {propose*forget*food (state ^io.input-link.eater ) ( ^x ^y ) ( ^food ) ( ^x ^y ) --> ( ^operator + =) ( ^name forget ^x ^y ) } sp {apply*forget*food (state ^operator ) ( ^name forget ^x ^y ) ( ^food ^food ) ( ^x ^y ^nextfood ) ( ^nextfood ) --> ( ^food - ) ( ^nextfood - ) ( ^nextfood ) }