hi,
- From: "kiran007.r@xxxxxxxxxxxxxx" <kiran007.r@xxxxxxxxxxxxxx>
- Date: 28 Aug 2006 03:44:08 -0700
can some one provide me code for the following program in sicstus
prolog code please.
1. Exploring a Maze
A maze is represented as a fact with four arguments (maze/4): the first
its name, the
second how many cells wide it is, the third how many cells high it is,
the fourth the maze
itself represented as a list of lists. The cells are either variables,
which the explorer can
move into, or '*'s which are walls. For example:
maze(mymaze, 3, 3, [[_, *, _],
[_, _, _],
[*, *, _]]).
The explorer can move up/down/left/right. Write code that will find a
way through the
maze from the top left (1-1) cell to the bottom right (width-height, in
this case 3-3) cell.
Note that detecting that the explorer has escaped the maze is the only
reason the
height/width arguments above are needed. The code should work for any
maze of any
dimensions.In addition, the path through the
maze should be displayed to the terminal, with each cell visited
numbered in turn. E.g.:
|1|*| |
|2|3|4|
|*|*|5|
or
|1|*| |*|
|2|*| | |
|3|4|5|6|
|*| |*|7|
You are advised to approach the problem as follows: treat the maze as a
logical object
becoming instantiated as the depth first search progresses. To do this,
follow these steps:
a) [view a cell] write a predicate called get_y/3 where the first
argument is the maze,
the second is a positive integer and the third is the row of the maze
as given by the
integer. Similarly write get_x/3; using the two allows you to view a
cell.
b) [make a move] write a predicate called move/6, where the arguments
are the maze,
the current position as co-ordinates, the next position as co-ordinates
and the current
move count. This should have four cases, each attempting to perform a
move in one of
the four possible directions and failing if this is not possible. Once
a successful, the cell
moved to should be unified with the move count.
c) [control the search] write a predicate called search/6. This should
include a case
that captures success.
d) [display a solution] write a predicate that will display a maze to
the terminal (see, for
example, above).
e) [run the code] write a predicate that will ask the user for the name
of a maze, will get
that maze from the maze facts (assuming there is a corresponding maze),
find a route
through it and display it to terminal.
.
- Prev by Date: Re: The n-knights problem
- Next by Date: Re: hi,
- Previous by thread: The n-knights problem
- Next by thread: Re: hi,
- Index(es):
Relevant Pages
|
|