If I have the following predicate door, which declare that there is a door between the two rooms:
door(office, hall). door(kitchen, office). door(hall, 'dining room'). door(kitchen, cellar). door('dining room', kitchen).
And the predicate doorstate which declares the state of a door:
doorstate(hall, office, closed). doorstate(hall, 'dining room', opened). doorstate('dining room', kitchen, opened). doorstate(kitchen, office, opened). doorstate(kitchen, cellar, opened).
There is a pathway between two rooms if all of the doors between them are open.
How can I write a rule to discover if there is such a pathway between two rooms?
The abject horror of prolog returns too quickly.
So I’m not just doing your homework for you, here’s how to understand it:
Note that these rules can only go through doors in one direction. Your homework is to make it work in both directions.
Where can we get to from the hall?
Here are all the rooms you can get from and to: