Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Logical programming. i. Write, execute, and test a Prolog program to simulate a mouse traversing a maze. Use a predicate d/2 to specify the doors

Logical programming.

i. Write, execute, and test a Prolog program to simulate a mouse traversing a maze.

Use a predicate d/2 to specify the doors between rooms of the maze, e.g., d(a,b) means that there is a door linking rooms a and b.

Assume that the mouse always starts in the room named enter, and that the room named exit has the only door out of the maze,

although room exit may also have doors leading to other rooms. Show all solutions for the mouse running the maze in each test case.

Use at least the following 5 test cases:

(A) d(enter,b). d(b,c). d(b,e). d(d,e). d(c,d). d(e,f). d(e,exit).

(B) d(enter,e). d(b,c). d(b,e). d(d,e). d(c,d). d(e,f). d(f,exit).

(C)d(enter.e). d(b,c). d(d,e). d(c,d). d(e,f). d(g,e).

(D)d(enter,e). d(b,c). d(d,e). d(c,d). d(e,f). d(c.exit).

(E) d(enter,a). d(a,exit).

I have First part so only look for second part.

Code for first part is

connected(X,Y):-d(X,Y);d(Y,X).

path(A,B,Path):-go(A,B,[A],Q).

go(A,B,P,[B|P]):-connected(A,B).

go(A,B,Visited,Path):-connected(A,C), C\==B, not(member(C,Visited)),go(C,B,[C|Visited],Path).

ii.Revise your program from part (i) above as follows.

Then run the same 5 test cases from part (i), as well as at least the following additional 5 test cases:

(F) d(enter,b). d(b,e). d(b,c). d(c,d). d(d,e). d(e,exit). cheese(c).

G) d(enter,a). d(a,b). d(b,c). d(c,d). d(d,e). d(e,exit). cheese(a). cheese(d).

(H) d(enter,a). d(a,b). d(b,c). d(b,exit). d(a,exit). d(c,d).

(I) d(enter,e). d(e,c). d(d,e). d(c,d). d(e,f). d(f,exit). cheese(c).

(J) d(enter,a). d(a,b). d(b,c). cheese(b). d(b,exit). d(a,d). d(d,e). d(e,b).

Some mice do not reach the exit because they become weak with hunger after visiting more than 3 rooms.

Add a predicate cheese/1 that specifies which rooms have food (i.e., cheese), e.g., cheese(d) is true if and only if room d contains cheese.

Change your program so that a mouse eats some cheese at least once every 3 rooms traversed. In other words,

the mouse eats a little bit of cheese in any room that contains cheese,

but if the mouse visits more than 3 rooms without eating cheese then that mouse must backtrack and try another path through the maze.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Joline Morrison, Mike Morrison

2nd Edition

? 061906448X, 978-0619064488

More Books

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago