Re: hi,



Hi



kiran007.r@xxxxxxxxxxxxxx wrote:

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.

SNIPPED..................






Take the code implemented for you.
I have made it in SWI,
Now its your duty to convert it in SICSTUS code
also replace the *write* call by some apropriate
functions to get better output.
I have not tested the code properly.
Try it n enjoy.

%%%%%%%%%%%%% START %%%%%%%%%


maze(Row,Col,Maze):-
move(pos(1,1),Row,Col,1,Maze),
write(Maze).


move(pos(R,C),Rmax,Cmax,Count,Puzz):-
R>0, C>0, R=<Rmax, C=<Cmax,
nth1(R,Puzz,L1), nth1(C,L1,Element), var(Element),
(
(
R=Rmax,C=Cmax,Element=Count);

Element=Count,
Count2 is Count+1,
(
C2 is C+1, R2=R ;
C2 is C-1, R2=R ;
R2 is R+1, C2=C ;
R2 is R-1, C2=C
),
move(pos(R2,C2),Rmax,Cmax,Count2,Puzz)
).


%%%%%%%%%%%%%% END %%%%%%%%

sample query.
?- maze(3,3,[[_, *, _],[_, _, _],[*, *, _]]).

[[1, *, _G447], [2, 3, 4], [*, *, 5]]


Suggestions are welcome

yours
Advait

.



Relevant Pages

  • Re: Making a maze....
    ... # I just removed some unused functions -- Georgy Pruss 20031118-002204 ... import Maze ... # A maze cell is a vector of three items: ... # (for top and left walls refer to upper and left cells resp.) ...
    (comp.lang.python)
  • hi,
    ... Exploring a Maze ... The explorer can move up/down/left/right. ... this case 3-3) cell. ... write a predicate called search/6. ...
    (comp.lang.prolog)
  • Re: maze creation - longest path for the left wall follower
    ... > solver cannot step in a cell or walk through it if the cell is a ... > the maze has to be designed such that: ... Each position inside can be either blank or a hedge. ... The bot can make a left move. ...
    (comp.programming)
  • Re: Design/Inheritance Question
    ... IsoscelesTriangle subclasses, but it's not clear to me what the best ... duplication is preferable to a misleading attempt to reuse the "shared" code. ... Presumably, for a maze, the /most/ important fact ... need different classes for each kind of cell. ...
    (comp.lang.java.programmer)
  • Re: Design/Inheritance Question
    ... Topological categorization is more difficult for me, because each topology for the cell seems independent, and I don't have language to describe them -- I don't want to end up with obscure names that I cannot mentally associate with the meanings of the classes. ... My main background is with database analysis, and in fact I'm biased towards data-driven, parametric approaches rather than implementing functionality through subclasses. ... And I'd need a way of representing which variation is at each cell in the maze. ... public int nDirections() ...
    (comp.lang.java.programmer)