coord: Fixed adjacency calculation

This commit is contained in:
Nathan Woodburn 2023-05-06 18:35:45 +10:00
parent d0c3d0faee
commit bdaaf35a88
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1

View File

@ -70,10 +70,20 @@ public record Coord(int y, int x) {
*/ */
public boolean isAdjacentDiagonal(Coord coord) { public boolean isAdjacentDiagonal(Coord coord) {
if (isAdjacent(coord)) return true; if (isAdjacent(coord)) return true;
if (this.x == coord.x - 1 && this.y == coord.y - 1) return true;
if (this.x == coord.x - 1 && this.y == coord.y + 1) return true; // Consider hex offsets
if (this.x == coord.x + 1 && this.y == coord.y - 1) return true; if (y%2 == 0){
return (this.x == coord.x + 1 && this.y == coord.y + 1); if (this.x == coord.x && this.y == coord.y + 1) return true;
if (this.x == coord.x && this.y == coord.y - 1) return true;
if (this.x == coord.x - 1 && this.y == coord.y + 1) return true;
return (this.x == coord.x - 1 && this.y == coord.y - 1);
}
else {
if (this.x == coord.x && this.y == coord.y + 1) return true;
if (this.x == coord.x && this.y == coord.y - 1) return true;
if (this.x == coord.x + 1 && this.y == coord.y + 1) return true;
return (this.x == coord.x + 1 && this.y == coord.y - 1);
}
} }
/** /**