|
-
March 29th, 2008, 10:56 PM
#1
Pleas help out a beginner's maze program
Im trying to program a maze. It works but for some reason it stops in the middle of the thing. Its suppose to find the 2 but it dosent...
class maze{
public static void main(String args[]){
int mr = 0;
int mc = 0;
int m[][] = {{0,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{0,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{0,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{0,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{0,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{0,1,1,2,0,0,0,0,1,1,1,1,1,1,1},
{0,1,1,1,1,1,1,0,1,1,1,1,1,1,1},
{0,0,0,0,0,1,1,0,1,1,1,1,1,1,1},
{1,0,1,1,0,1,1,0,1,1,1,1,0,1,1},
{1,1,1,1,0,1,1,0,1,1,1,1,0,1,1},
{1,1,1,1,0,1,1,0,1,1,1,1,0,1,1},
{1,1,1,1,0,0,0,0,0,0,0,0,0,1,1},
{1,1,1,1,1,1,1,0,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,0,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
int ctr = 0;
while ( ctr < 100 ){
if (m[mr][mc] == 2 ){
System.out.print("Cheese found");
}
else if (m[mr+1][mc] ==0 ){
++mr;
}
else if (m[mr][mc+1] !=1 ){
++mc;
}
else if (m[mr-1][mc] != 1 ){
--mr;
}
else if (m[mr][mc-1] != 1 ){
--mc;
}
m[mr][mc]= 3;
++ctr;
for ( int r = 0; r < m.length; ++r){
for( int c = 0; c < m[0].length; ++c)
System.out.print( m[r][c] + " ");
System.out.println();
}
System.out.println();
}//end while loop
} //end main
}//end class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|