coord: Add is adjacent methods

This commit is contained in:
Nathan Woodburn 2023-04-24 18:25:07 +10:00
parent 741ddc2cf0
commit 3e04727e7c
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
2 changed files with 32 additions and 2 deletions

View File

@ -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

View File

@ -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
}
/**