coord: Add is adjacent methods
This commit is contained in:
parent
741ddc2cf0
commit
3e04727e7c
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user