+ 1

Creating a 2-Dimensional Array with coordinates

Hi , imagine you Look on a 2-D maze with directions NORTH, EAST , SOUTH and WEST now there are some deadlocks you walk around with int x and int y ( x for left and right and y for up and down ) when you come into a deadlock ((so for example you cannot go EAST && WEST && SOUTH ... )) the programme should give : deadEnd [y] [x] = true; return true; is there an elegant and short way to progame this as a Boolean? public static final int NORTH, EAST , WEST , SOUTH are given (0,1,2,3)

20th Nov 2016, 6:59 PM
thejokahr
thejokahr - avatar
2 Respuestas
+ 3
I don't know the exact situation, but I would create a boolean method wich does this for you. Then, in a coordinate system normally +Y means up, -Y means down, +X means right and -X means left. You can check inside the method the four contigous points, and return true in case 3 of them are full/wall Example: public boolean isDeadEnd (int X, int Y){ /* The check method returns true if the point is a wall */ boolean tile1 = check (--X, Y); boolean tile2 = check (++X, Y); boolean tile3 = check (X, --Y); boolean tile4 = check (X, ++Y); //Return true if any of the 4 combinations is a dead end return (tile1 && tile2 && tile3) || (tile1 && tile2 && tile4) || (tile1 && tile3 && tile4) || (tile2 && tile3 && tile4) Now, I don't know why you are using a dimensional array, or if you have a way to check walls, but I hope it helps
20th Nov 2016, 8:16 PM
Goio
0
thank you so much it Helped me a Lot !!
20th Nov 2016, 8:27 PM
thejokahr
thejokahr - avatar