I'm completely new to Prolog and working on a homework assignment My program is supposed to solve flow free problem using depth first, I don't need the whole code for it as its what supposed to do but I need to know how to think to solve it or what parts it will contain.
the points look like that:
dot('R',[3,1],[0,3]).
so this 2 points is red and suppose to connect them
so I was thinking that there will be moves to move from 1 point to another and already it works
move([R,C],[NR,NC]):-
move_right(R,C,NR,NC).
move([R,C],[NR,NC]):-
move_Left(R,C,NR,NC).
move([R,C],[NR,NC]):-
move_Up(R,C,NR,NC).
move([R,C],[NR,NC]):-
move_Down(R,C,NR,NC).
I think now I need to think about the start and the goal so the start is initial grid which contain points with there colors and they all are not connected so I need to take element from start for example red point and find all paths between the 2 points by using moves then for each element I will have multiple paths so what should I do and is there a goal which I will stop for it ?
May be the question is confusing but really don't know how to solve it specially when trying to
get useful from backtracking.
All I need to know that I need for example a function to take something and return another something and so on, without its implementation and I will do that
This is some extensive problem.
Here are some quick hints:
Represent a state of the search space as 5x5 tiles, each of which is non-colored or colored in one of the 5 available colours. With SWI-Prolog, you have the fantastic dict datastructure (an associative array), so we can put this to good use instead of messing around with low-level index computations (might be a bit slower, but who cares!)
Our convention is row number first, column number second
Our clean board is then represented as:
We also have 5 pens, starting off a one or the end extremity of a path. The pens have the status
fesh
(they haven't even put to the board),done
(a valid path has been traced and the pen won't nove) orready
.A state of the search space is thus given by:
And now the depth-first search
A predicate
move(Board,Pens)
is given theState
and deterministically:done
yet (the colors are selected in fixed, but otherwise freely selectable order; a fun way to do that would be to generate a random sequence of the colors determinsitically from the board state).fresh
, the only possible move is to color the tile under the pen and set the pen toready
.done
.Board
andPens
.