There is some problem with your java parser.
Given this class :
public static class Position {
public int x=-1;
public int y=-1;
public Position(int x, int y) {
this.x = x;
this.y = y;
}
public Position() {
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Position position = (Position) o;
return x == position.x && y == position.y;
}
@Override
public int hashCode() {
return Objects.hash(x, y);
}
@Override
public String toString() {
return "Position{" +
"x=" + x +
", y=" + y +
'}';
}
}
when i do :
Set<Position> visited = new HashSet<>();
[...]
Position current_position=new Position(KC, KR);
visited.add(current_position);
[...]
System.err.println("visited "+visited);
I have this output :
visited [Position{x=8, y=6}, Position{x=7, y=6}, Position{x=7, y=6}, Position{x=6, y=6}, Position{x=12, y=6}, Position{x=12, y=6}, Position{x=11, y=6}, Position{x=11, y=6}, Position{x=10, y=6}, Position{x=10, y=6}, Position{x=9, y=6}, Position{x=9, y=6}, Position{x=8, y=6}]
(there is doublon, but should not have any doublon because of the datastruct)
to fix it, I have to use a strange trick :
Position current_position=new Position((KC+1), (KR+1));
and it’s work like a charm.
I’ve also noted another strange behavior. When I do :
System.err.println("world["+KR+1+"]["+(KC)+"]=" +world[KR][KC]);
i have this output :
"world[61][7]=1"instead of “world[7][7]=1”