Ookay...
Meinst du sowas?
[highlight=Java]
import java.util.*;
public class Labyrinth{
String mapData=
"########################################"+
"# ## ## ## ####### #"+
"# ### ## ######## ## ##### ###### ### #"+
"# ## ## #### ### # ## ### ## #"+
"## ## ### ##### ###### ### ## ##"+
"## ######### ### ###### ###### ### ## #"+
"## #### ### #### #### ### #"+
"### ### ## ### #### ######## ## #"+
"### # ####### ## ## ## ##"+
"# # # ####### ## ## ###### ## ## ## #"+
"# ### # ## ## # ## ## ### #"+
"# ########## ## ### # ######### ## #"+
"# ############ ## # ## ## ##"+
"# ### ## ### ## ######## ###### #"+
"# ######## ## ### ## # ### # ## #"+
"# #### ## ## #### # # #"+
"#### # ### ############ ## # # ####"+
"# # ###### ## ## ## # ### ####"+
"# ## ### ### ## ## # #"+
"######### ######## ## ############# ##"+
"#################### ## ## ## #"+
"# ## ## ## ## ## ## ####### ##"+
"# ### ## ######## ## ## ## ## ####### ##"+
"# ## ## #### ### ## ## ## ## ####### ##"+
"## ## ### # # ## ####### ##"+
"## ######### ### ## ## ############## ##"+
"## #### ### # ##### ##"+
"### ### ## ### #### ##### ### ##"+
"### # ####### ## ## ### ##"+
"########################################";
int w=40, h=30;
public static class Point{
int x,y;
Point(int _x, int _y){ x=_x; y=_y; }
List<Point> getNeighbors(boolean[][] map){
int w=map.length;
int h=map[0].length;
List<Point> neighbors=new LinkedList<Point>();
for(int i:new int[]{x-1,x+1}){
if(i<0 || i>=w) continue;
if(map
[y]){
neighbors.add(new Point(i,y));
}
}
for(int i:new int[]{y-1,y+1}){
if(i<0 || i>=h) continue;
if(map[x]){
neighbors.add(new Point(x,i));
}
}
return neighbors;
}
@Override
public String toString(){ return "("+x+"|"+y+")"; }
@Override
public boolean equals(Object other){
return other instanceof Point
&& ((Point)other).x == this.x
&& ((Point)other).y == this.y;
}
}
boolean[][] map=new boolean[w][h];
{
for(int x=0; x<w; x++){
for(int y=0; y<h; y++){
map[x][y]=mapData.charAt(y*w+x)==' ';
}
}
}
//######################################################################### IRGENDEINEN WEG SUCHEN
public List<Point> deepFirstSearch(Point from, Point to){
return deepFirstSearch(from,to,new boolean[w][h]);
}
private LinkedList<Point> deepFirstSearch(Point from, Point to, boolean[][] visited){
//diesen punkt als besucht markieren
visited[from.x][from.y]=true;
//wenn ziel erreicht: rekursionsende
if(from.equals(to)){
LinkedList<Point> path=new LinkedList<Point>();
path.add(to);
return path;
}
//guggen, ob von einem nachbar das ziel erreichbar ist
for(Point p:from.getNeighbors(map)){
//nachbar muss unbesucht und begehbar sein
if(!visited[p.x][p.y] && map[p.x][p.y]){
LinkedList<Point> path=deepFirstSearch(p,to,visited);
if(path!=null){
path.addFirst(from);
return path;
}
}
}
//kein weg gefunden
return null;
}
public String toString(Point... markedPoints){
StringBuilder b=new StringBuilder();
for(int y=0; y<h; y++){
for(int x=0; x<w; x++){
if(Arrays.asList(markedPoints).contains(new Point(x,y))){
b.append("* ");
}else{
b.append(map[x][y]?" ":"||");//(char)0+""+(char)0);
}
}
b.append('\n');
}
return b.toString();
}
public static void main(String..._){
Labyrinth lab=new Labyrinth();
Point startPoint, target=new Point(1,1);
while(true){
startPoint=target;
target=null;
Random rand=new Random();
while(target==null){
int x=rand.nextInt(lab.w);
int y=rand.nextInt(lab.h);
if(lab.map[x][y]){
target=new Point(x,y);
}
}
Collection<Point> path=lab.deepFirstSearch(startPoint,target);
if(path!=null){
for(Point path){
for(int i=0; i<40; i++) System.out.println();
System.out.println(lab.toString(p,target));
try{
Thread.sleep(200);
}catch(Exception e){}
}
}else{
continue;
}
for(int i=0; i<40; i++) System.out.println();
System.out.println(lab.toString(path.toArray(new Point[path.size()])));
try{
Thread.sleep(1500);
}catch(Exception e){}
}
}
}
[/highlight]
(beim asuführen bitte die Konsole etwas in die höhe ziehen, hatte keine lust eine ordentliche animation zu basteln^^)
Bringt's dich weiter?
bemerkung: es ist besser, solche informationen wie "visited j/n" direkt in den Zellen unterzubringen, wie du es getan hast, ich habe mir hier nicht so doll viele gedanken gemacht, deswegen ist das etwas plump mit zwei arrays gelöst worden, ist eigentlich nicht so schön.