From bdaaf35a88ce3710e0a7394a4da42ae231936255 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Sat, 6 May 2023 18:35:45 +1000 Subject: [PATCH] coord: Fixed adjacency calculation --- src/comp1110/ass2/Coord.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/comp1110/ass2/Coord.java b/src/comp1110/ass2/Coord.java index ea21bfb..a7d9b8d 100644 --- a/src/comp1110/ass2/Coord.java +++ b/src/comp1110/ass2/Coord.java @@ -70,10 +70,20 @@ public record Coord(int y, int x) { */ public boolean isAdjacentDiagonal(Coord coord) { 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; - if (this.x == coord.x + 1 && this.y == coord.y - 1) return true; - return (this.x == coord.x + 1 && this.y == coord.y + 1); + + // Consider hex offsets + if (y%2 == 0){ + 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); + } } /**