From 3e04727e7ce2adb94a42250e4393d7645aba304b Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Mon, 24 Apr 2023 18:25:07 +1000 Subject: [PATCH] coord: Add is adjacent methods --- src/comp1110/ass2/Coord.java | 29 +++++++++++++++++++++++++++++ src/comp1110/ass2/State.java | 5 +++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/comp1110/ass2/Coord.java b/src/comp1110/ass2/Coord.java index 41bdeed..6487cc2 100644 --- a/src/comp1110/ass2/Coord.java +++ b/src/comp1110/ass2/Coord.java @@ -18,6 +18,7 @@ public class Coord { this.y = y; } + // region Getters and Setters /** * Get the x coordinate * @return int x coordinate @@ -50,6 +51,8 @@ public class Coord { this.y = y; } + // endregion + /** * Check if two coordinates are equal * @param coord Coord object to compare to @@ -59,6 +62,32 @@ public class Coord { return (this.x == coord.x && this.y == coord.y); } + /** + * Check if two coordinates are adjacent (does not include diagonals) + * @param coord Coord object to compare to + */ + public boolean isAdjacent(Coord coord) { + if (this.y == coord.y) { + return (this.x == coord.x - 1 || this.x == coord.x + 1); + } + if (this.x == coord.x) { + return (this.y == coord.y - 1 || this.y == coord.y + 1); + } + return false; + } + + /** + * Check if two coordinates are adjacent (includes diagonals) + * @param coord Coord object to compare to + */ + 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); + } + /** * Get a string representation of the coordinate * @return String representation of the coordinate diff --git a/src/comp1110/ass2/State.java b/src/comp1110/ass2/State.java index 2a66ea4..3a9b5cb 100644 --- a/src/comp1110/ass2/State.java +++ b/src/comp1110/ass2/State.java @@ -517,8 +517,9 @@ public class State { * @return int score */ public int scoreLinks(int playerID) { - int score = 0; - return score; //! TODO + int maxIslands = 0; + + return maxIslands * 5; //! TODO } /**