Hello,
We're trying for an array to search coördinates on a grid. This is done per 3 lines and then putting them in the order of lowest x coördinate first after which he puts the lowest y coördinate first. Problem is that this way it checks every point.
The code I used is the following:
However, we can't code it in such way that it checks if the array contains coords on for example x=0 in array2. If it has none, it should skip the rest of the points on x=0 and commence to x=1. When it has found a coord on the specified x=i, it should do put the ycoords on that x=i in the order of lowest y first.
Anyone who understands the problem and has any tips?
Greetings,
Daniel.
We're trying for an array to search coördinates on a grid. This is done per 3 lines and then putting them in the order of lowest x coördinate first after which he puts the lowest y coördinate first. Problem is that this way it checks every point.
The code I used is the following:
Code:
public class VetCooleSolver implements Solver {
public VetCooleSolver() {
}
//assuming coördinates are non-null
public Point[] computeRoute(Point[] coords) {
Point[] route = new Point[coords.length];
route[0] = new Point(coords[0]);
// starting point should not change
int[] array1 = new int[route.length];
int[] array2 = new int[route.length];
for (int i=0; i<route.length; i++) {
array2[i] = coords[i].x; //the xcoord
array1[i] = cities[i].y; //the ycoord
System.out.println(array2[i] + ", " + array1[i]);
}
System.out.println("route.length = " + route.length);
int scanpointx;
int scanpointy = 1;
int direction = 1;
int height;
int half = 2;
int arraypos;
int[] indexofthefound = new int[array1.length];
int indexofthefoundpos = 0;
for (scanpointx = -1; scanpointx >= -1;) {
scanpointx = scanpointx + direction;
if (scanpointx < 10){
for (height = (half-3); height != half; height++) {
for (arraypos = 0; arraypos < array1.length; arraypos++) {
System.out.println(scanpointx + " " + (scanpointy + height));
if (scanpointx == array2[arraypos] && (scanpointy + height) == array1[arraypos]) {
indexofthefound[indexofthefoundpos] = arraypos;
indexofthefoundpos++;
}
}
}
}
if (scanpointx == 0 && helft == 5) break;
if (scanpointx == 10) {
direction = -1;
half = 5;
}
}
for (int i=0; i<route.length; i++) {
route[i] = coords[indexofthefound[i]];
System.out.println(indexofthefound[i]);
}
return route;
}
public String getAuthors() {
return "J. Dam & D. Dam";
}
public String getDescription() {
return "VetCooleSolver: Search coords 3-3 method.";
}
public static void main(String[] args) {
Solver solver = new VetCooleSolver();
new View(solver);
}
}
However, we can't code it in such way that it checks if the array contains coords on for example x=0 in array2. If it has none, it should skip the rest of the points on x=0 and commence to x=1. When it has found a coord on the specified x=i, it should do put the ycoords on that x=i in the order of lowest y first.
Anyone who understands the problem and has any tips?
Greetings,
Daniel.