Thread: a question
View Single Post
  #3 (permalink)  
Old August 11th, 2003, 07:41 AM
Olorin Olorin is offline
Authorized User
 
Join Date: Jun 2003
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

natmaster is suggesting a Depth-First Search. Looking at the brief description of the problem, I'd go for a Breadth First approach, wioth a recursive fn:
Solve Routine:
==============
LET v be a set (ArrayList, Hashtable, what-have-you);
Add the starting board configuration to v;
RETURN the result of doit(v, 0);

doit Routine:
=============
Parameters:
edge: a set (ArrayList, Hashtable, what-have-you) of the current possible position(s);
n: the number of moves done so far;

LET nextEdge be an empty set;
FOREACH boardConfiguration in edge:
  IF the boardConfiguration is the goal
    RETURN n;
  LET children be the set of board configuration that may be created from boardConfiguration
  by applying all the possible moves;
  ADD to nextEdge all the element of children;
LET nn be n+1;
RETURN doit(nextEdge, nn);

HTH,
Olorin
Reply With Quote