PROGRAM "Wumpus World" CAPABILITIES { pitCounter(I) } PaintPits(X,Y) { NOT pitCounter(I), pitCounter(I+1), PaintTo(pits, X, Y, I) } { } PaintedPit(X,Y) { paintedPit(X,Y) } { } PaintGold(X,Y) { PaintTo(gold, X, Y, Counter) } { } PaintWumpus(X,Y) { PaintTo(wumpus, X, Y, Counter) } { direction(north) } TurnLeft() { NOT direction(north), direction(west), AgentAction(TurnToWest) } { direction(west) } TurnLeft() { NOT direction(west), direction(south), AgentAction(TurnToSouth) } { direction(south) } TurnLeft() { NOT direction(south), direction(east), AgentAction(TurnToEast) } { direction(east) } TurnLeft() { NOT direction(east), direction(north), AgentAction(TurnToNorth) } { direction(north) } TurnRight() { NOT direction(north), direction(east), AgentAction(TurnToEast) } { direction(east) } TurnRight() { NOT direction(east), direction(south), AgentAction(TurnToSouth) } { direction(south) } TurnRight() { NOT direction(south), direction(west), AgentAction(TurnToWest) } { direction(west) } TurnRight() { NOT direction(west), direction(north), AgentAction(TurnToNorth) } {points(Score) AND position(X,Y) AND NOT wall(X + 1,Y)} StepToEast() { NOT position(X,Y), position(X+1,Y), NOT points(Score), points(Score - 1) , AgentAction(east) } {points(Score) AND position(X,Y) AND NOT wall(X,Y + 1)} StepToNorth() { NOT position(X,Y), position(X,Y+1), NOT points(Score), points(Score - 1) , AgentAction(north) } {points(Score) AND position(X,Y) AND NOT wall(X - 1,Y)} StepToWest() { NOT position(X,Y), position(X - 1,Y), NOT points(Score), points(Score - 1), AgentAction(west) } {points(Score) AND position(X,Y) AND NOT wall(X,Y - 1)} StepToSouth() { NOT position(X,Y), position(X,Y - 1), NOT points(Score), points(Score - 1), AgentAction(south) } {position(X,Y) AND NOT visited(X,Y,T) } MarkVisited() { visited(X,Y,1) } {position(X,Y) AND visited(X,Y,T) } MarkVisited() { NOT visited(X,Y,T) , visited(X,Y,T+1) } { NOT possiblePit(X,Y) AND NOT pit(X,Y) } MarkPit(X,Y) { possiblePit(X,Y) , MarkPerception(possiblepit,X,Y) } { possiblePit(X,Y) AND position(Z,U) AND visited(Z,U,T) AND T < 2 } MarkPit(X,Y) { NOT possiblePit(X,Y), pit(X,Y), MarkPerception(isapit,X,Y) } { } MarkPit(X,Y) { default(1) } { } UnmarkPit(X,Y) { NOT possiblePit(X,Y), NOT pit(X,Y), okNotPit(X,Y) , MarkPerception(oknotpit,X,Y) } { NOT possibleWumpus(X,Y) } MarkWumpus(X,Y) { possibleWumpus(X,Y), MarkPerception(possiblewumpus,X,Y) } { possibleWumpus(X,Y) } MarkWumpus(X,Y) { NOT possibleWumpus(X,Y), wumpus(X,Y), MarkPerception(isawumpus,X,Y) } { } UnmarkWumpus(X,Y) { NOT possibleWumpus(X,Y), okNotWumpus(X,Y), MarkPerception(oknotwumpus,X,Y) } { arrow(1) AND wumpus(X,Y) } ShootToWumpus() { NOT arrow(1), arrow(0), NOT wumpus(X,Y), wumpus(died) , okNotWumpus(X,Y) , okNotPit(X,Y), NOT possiblePit(X,Y), NOT pit(X,Y), AgentAction(killtowumpus) } { } RemovePossibleWumpus(X,Y) { NOT possibleWumpus(X,Y) , okNotWumpus(X,Y)} { } RemoveVisitedSquares(X,Y,T) { NOT visited(X,Y,T) } { } ReplacePossiblePitByOkNotPit(X,Y) {NOT possiblePit(X,Y) , okNotPit(X,Y)} { gold(X,Y) AND points(Score) } TakeGold() { NOT gold(X,Y) , gather(treasure), NOT points(Score), points(Score+1000), AgentAction(takegold) } { agentStatus(X) AND points(Score) } KilledByWumpus() { NOT agentStatus(X), agentStatus(died), NOT points(Score), points(Score - 10000), AgentAction(agentdied)} { agentStatus(X) AND points(Score) } FallInaPit() { NOT agentStatus(X), agentStatus(died), NOT points(Score), points(Score - 10000), AgentAction(agentdied)} {rotationSequence(leftRightRight)} ChangeRotationSequence() {NOT rotationSequence(leftRightRight), rotationSequence(rightLeftLeft)} {rotationSequence(rightLeftLeft) } ChangeRotationSequence() {NOT rotationSequence(leftRightRight), rotationSequence(rightLeftLeft)} { nextX1Y1(A,B) AND position(X,Y) AND direction(north) } ObtainX1Y1() { NOT nextX1Y1(A, B) , nextX1Y1(X , Y + 1) } { nextX1Y1(A,B) AND position(X,Y) AND direction(south) } ObtainX1Y1() { NOT nextX1Y1(A, B) , nextX1Y1(X , Y - 1) } { nextX1Y1(A,B) AND position(X,Y) AND direction(east) } ObtainX1Y1() { NOT nextX1Y1(A, B) , nextX1Y1(X + 1 , Y) } { nextX1Y1(A,B) AND position(X,Y) AND direction(west) } ObtainX1Y1() { NOT nextX1Y1(A, B) , nextX1Y1(X - 1 , Y) } { } OK(X,Y) { MarkPerception(ok,X,Y) } BELIEFBASE: position(1,1). visited(1,1,1). direction(north). okNotPit(1,1). okNotWumpus(1,1). points(0). arrow(1). rotationSequence(leftRightRight). nextX1Y1(0,0). agentStatus(alive). pitCounter(0). GOALBASE: paintWorld(). findTreasure(). goHome(). RULEBASE: paintWorld() <- TRUE | paintPits(), paintWumpus(), paintGold(). paintPits() <- TRUE | loopPaintPits(). loopPaintPits() <- thereIsaPit(X,Y) AND NOT paintedPit(X,Y) | PaintPits(X,Y), PaintedPit(X,Y), loopPaintPits(). loopPaintPits() <- TRUE | SKIP. paintWumpus() <- thereIsaWumpus(X,Y) | PaintWumpus(X,Y). paintGold() <- gold(X,Y) | PaintGold(X,Y). findTreasure() <- gather(treasure) OR agentStatus(died) | SKIP. findTreasure() <- NOT gather(treasure) | sense(), moveTo(), doIProperAction(), amIclog(), findTreasure(). sense() <- gather(treasure) OR agentStatus(died) | SKIP. sense() <- position(X,Y) AND visited(X,Y,T) AND T < 2 | senseGlitter(), senseStench(), senseBreeze(). sense() <- position(X,Y) AND visited(X,Y,T) AND T > 1 | SKIP. senseStench() <- gather(treasure) | SKIP. senseStench() <- position(X,Y) AND NOT wumpus(died) AND square(X,Y,WHATEVER,stench,WHATEVER) | markPossibleWumpus(), foundWumpus(). markPossibleWumpus() <- position(X,Y) | mpw(X - 1,Y), mpw(X,Y+1), mpw(X+1,Y), mpw(X,Y - 1). mpw(X,Y) <- NOT wall(X,Y) AND NOT okNotWumpus(X,Y)| MarkWumpus(X,Y). mpw(X,Y) <- TRUE | SKIP. foundWumpus() <- wumpus(X,Y) | ShootToWumpus(), loopRemovePossibleWumpus(). foundWumpus() <- TRUE | SKIP. loopRemovePossibleWumpus() <- NOT possibleWumpus(X,Y) | SKIP. loopRemovePossibleWumpus() <- possibleWumpus(X,Y) | RemovePossibleWumpus(X,Y), loopRemovePossibleWumpus(). senseStench() <- wumpus(died) | unmarkPossibleWumpus(). senseStench() <- position(X,Y) AND NOT square(X,Y,WHATEVER,stench,WHATEVER) | unmarkPossibleWumpus(). unmarkPossibleWumpus() <- position(X,Y) | upw(X - 1,Y), upw(X,Y+1), upw(X+1,Y), upw(X,Y - 1). upw(X,Y) <- NOT wall(X,Y) AND NOT okNotWumpus(X,Y) | UnmarkWumpus(X,Y). upw(X,Y) <- TRUE | SKIP. senseBreeze() <- gather(treasure) | SKIP. senseBreeze() <- position(X,Y) AND NOT square(X,Y,breeze,WHATEVER,WHATEVER) | unmarkAllPit(). unmarkAllPit() <- position(X,Y) | uap(X - 1,Y), uap(X,Y+1), uap(X+1,Y), uap(X,Y - 1). uap(X,Y) <- NOT wall(X,Y) AND NOT okNotPit(X,Y) | UnmarkPit(X,Y). uap(X,Y) <- TRUE | SKIP. senseBreeze() <- position(X,Y) AND square(X,Y,breeze,WHATEVER,WHATEVER) | markAllPit(). markAllPit() <- position(X,Y) | map(X - 1,Y), map(X,Y+1), map(X+1,Y), map(X,Y - 1). map(X,Y) <- NOT wall(X,Y) AND NOT okNotPit(X,Y) | MarkPit(X,Y). map(X,Y) <- TRUE | SKIP. senseGlitter() <- position(X,Y) AND square(X,Y,WHATEVER,WHATEVER,glitter) | TakeGold(), loopRemoveVisitedSquare(), MarkVisited(). senseGlitter() <- TRUE | SKIP. moveTo() <- TRUE | firstTurnTo(), action(1). action(Counter) <- Counter == 4 | aStep(). action(Counter) <- TRUE | ObtainX1Y1() , check(Counter). check(Counter) <- nextX1Y1(X1,Y1) AND NOT wall(X1,Y1) AND okNotPit(X1,Y1) AND okNotWumpus(X1,Y1) AND NOT visited(X1,Y1,Times) | OK(X1,Y1), aStep(). check(Counter) <- TRUE | afterTurnTo(), action(Counter+1). firstTurnTo() <- rotationSequence(leftRightRight) | TurnLeft(). firstTurnTo() <- rotationSequence(rightLeftLeft) | TurnRight(). afterTurnTo() <- rotationSequence(leftRightRight) | TurnRight(). afterTurnTo() <- rotationSequence(rightLeftLeft) | TurnLeft(). aStep() <- direction(north) | StepToNorth(), MarkVisited(). aStep() <- direction(south) | StepToSouth(), MarkVisited(). aStep() <- direction(east) | StepToEast(), MarkVisited(). aStep() <- direction(west) | StepToWest(), MarkVisited(). doIProperAction() <- position(X,Y) AND therIsaWumpus(X,Y) | KilledByWumpus(). doIProperAction() <- position(X,Y) AND thereIsaPit(X,Y) | FallInaPit(). doIProperAction() <- TRUE | SKIP. amIclog()<- agentStatus(alive) AND position(X,Y) AND visited(X,Y,T) AND T == 3 | loopRemoveVisitedSquare(), loopReplacement(). amIclog()<- TRUE | SKIP. loopReplacement() <- NOT possiblePit(X,Y) | SKIP. loopReplacement() <- possiblePit(X,Y)| ReplacePossiblePitByOkNotPit(X,Y), loopReplacement(). loopRemoveVisitedSquare() <- NOT visited(X,Y,T) | SKIP. loopRemoveVisitedSquare() <- visited(X,Y,T) | RemoveVisitedSquares(X,Y,T), loopRemoveVisitedSquare(). goHome() <- agentStatus(alive) | loopGoBackHome(). loopGoBackHome() <- position(1,1) | SKIP. loopGoBackHome() <- TRUE | moveTo(), loopGoBackHome().