How would I go about creating the board given any x and y coordinates for the start nodes. For example, if x=3 and y=2 the board should like:
1 2 3
4 5 x
6 7 8
An example in java or pseudocode would be extremely useful.
How would I go about creating the board given any x and y coordinates for the start nodes. For example, if x=3 and y=2 the board should like:
1 2 3
4 5 x
6 7 8
An example in java or pseudocode would be extremely useful.
hope this helps. Let me know if you have any questions.
int x_lim = 2;
int y_lim = 3;
int count=1;
for(int x=1;x<3+1;x++)
{
for(int y=1;y<3+1;y++)
{
if(x_lim==x && y_lim==y) //skip case (blank tile)
{
System.out.println("x"+" ");
}
else //other numbers
{
System.out.println(count+" ");
count++;
}
}
}
Before posting the code, I would recommend only one thing. In programming you have to start thinking in a zero-based indexing. Also, if the format you posted doesn't have any typos in indexing (because rationally after printing the 'x' you must print 7 and not 6, so that the 3x3 board ends up in the index 9) maybe the code below will help you.
int coord_x = 3;
int coord_y = 2;
int rows = 3;
int columns = 3;
int counter = 1;
for (int i = 1; i <= rows; i++){
for (int j = 1; j <= columns; j++){
if (i == coord_y && j == coord_x){
System.out.print("x ");
continue;
}
System.out.print(counter + " ");
counter++;
}
System.out.println();
}