Trying to do Task 11 Link
Signed-off-by: Immanuel Alvaro Bhirawa <u7280427@anu.edu.au>
This commit is contained in:
@@ -564,31 +564,6 @@ public class BlueLagoon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// public static ArrayList<Integer> islandCoords(String stateString) {
|
|
||||||
// String[] parts = stateString.split("; ?");
|
|
||||||
//
|
|
||||||
// // Coords of the island tiles
|
|
||||||
// ArrayList<Integer> coordsContainer = new ArrayList<>();
|
|
||||||
//
|
|
||||||
// for (String part : parts) {
|
|
||||||
// String[] parseSplit = part.split(" ");
|
|
||||||
// String stateCases = parseSplit[0];
|
|
||||||
//
|
|
||||||
// switch (stateCases) {
|
|
||||||
// // Get the Land coords (Island Coords)
|
|
||||||
// case "i":
|
|
||||||
// for (int i = 2; i < parseSplit.length; i++) {
|
|
||||||
// String coords = parseSplit[i];
|
|
||||||
// coordsContainer.add(Integer.parseInt(coords));
|
|
||||||
// }
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return coordsContainer;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// region Scoring
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a state string, calculate the "Islands" portion of the score for
|
* Given a state string, calculate the "Islands" portion of the score for
|
||||||
* each player as if it were the end of a phase. The return value is an
|
* each player as if it were the end of a phase. The return value is an
|
||||||
@@ -619,93 +594,6 @@ public class BlueLagoon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*// ArrayList<Integer> islandCoords = islandCoords(stateString);
|
|
||||||
|
|
||||||
String[] parts = stateString.split("; ?");
|
|
||||||
|
|
||||||
ArrayList<Integer> islandCoords = new ArrayList<>();
|
|
||||||
int numberOfIslandCounter = 0; // Count the number of players
|
|
||||||
int p1IslandCounter = 0;
|
|
||||||
int p2IslandCounter = 0;
|
|
||||||
int p3IslandCounter = 0;
|
|
||||||
int p4IslandCounter = 0;
|
|
||||||
|
|
||||||
int pStatePlayerId;
|
|
||||||
|
|
||||||
ArrayList<Integer> player1Coords = new ArrayList<>();
|
|
||||||
ArrayList<Integer> player2Coords = new ArrayList<>();
|
|
||||||
ArrayList<Integer> player3Coords = new ArrayList<>();
|
|
||||||
ArrayList<Integer> player4Coords = new ArrayList<>();
|
|
||||||
|
|
||||||
for (String part : parts) {
|
|
||||||
String[] parseSplit = part.split(" ");
|
|
||||||
String stateCases = parseSplit[0];
|
|
||||||
|
|
||||||
switch (stateCases) {
|
|
||||||
case "i":
|
|
||||||
for (int i = 2; i < parseSplit.length; i++) {
|
|
||||||
islandCoords.add(99); // A separator between islands
|
|
||||||
|
|
||||||
String coords = parseSplit[i];
|
|
||||||
islandCoords.add(Integer.parseInt(coords));
|
|
||||||
numberOfIslandCounter++;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "p":
|
|
||||||
pStatePlayerId = Integer.parseInt(parseSplit[1]);
|
|
||||||
|
|
||||||
// Collecting the settler Coords that has been placed
|
|
||||||
for (int i = 9; i < parseSplit.length; i++) {
|
|
||||||
if(pStatePlayerId == 1){
|
|
||||||
player1Coords.add(Integer.parseInt(parseSplit[i]));
|
|
||||||
}
|
|
||||||
else if(pStatePlayerId == 2){
|
|
||||||
player2Coords.add(Integer.parseInt(parseSplit[i]));
|
|
||||||
}
|
|
||||||
else if(pStatePlayerId == 3){
|
|
||||||
player3Coords.add(Integer.parseInt(parseSplit[i]));
|
|
||||||
}
|
|
||||||
else if(pStatePlayerId == 4){
|
|
||||||
player4Coords.add(Integer.parseInt(parseSplit[i]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = 0; i < islandCoords.size(); i++){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// check the size of the arrayList to set the size for the int[]
|
|
||||||
}
|
|
||||||
|
|
||||||
return new int[]{0, 0};
|
|
||||||
}
|
|
||||||
|
|
||||||
// for (int i = 9; i < parseSplit.length; i++) {
|
|
||||||
// while (!parseSplit[i].equals("T")) {
|
|
||||||
// settlerCoords.add(parseSplit[i]); // Store all the settler coords
|
|
||||||
//
|
|
||||||
// // If the current player ID is the same as the placed settler's player ID
|
|
||||||
// // Store it into array
|
|
||||||
// if (pStatePlayerId.equals(currentPlayer)) playerSettlerCoords.add(parseSplit[i]);
|
|
||||||
// i++;
|
|
||||||
// }
|
|
||||||
// i++;
|
|
||||||
//
|
|
||||||
// // Collecting the village coords that has been placed
|
|
||||||
// while (i < parseSplit.length) {
|
|
||||||
// villageCoords.add(parseSplit[i]); // Store all the village Coords
|
|
||||||
//
|
|
||||||
// // If the current player ID is the same as the placed Village's player ID
|
|
||||||
// // Store it into array
|
|
||||||
// if (pStatePlayerId.equals(currentPlayer)) playerVillageCoords.add(parseSplit[i]);
|
|
||||||
// i++;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a state string, calculate the "Links" portion of the score for
|
* Given a state string, calculate the "Links" portion of the score for
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package comp1110.ass2;
|
package comp1110.ass2;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object to store coordinates
|
* Object to store coordinates
|
||||||
* This stores the x and y coordinates of a point
|
* This stores the x and y coordinates of a point
|
||||||
|
|||||||
@@ -551,12 +551,217 @@ public class State {
|
|||||||
* @param playerID int player to score
|
* @param playerID int player to score
|
||||||
* @return int score
|
* @return int score
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public Player(int playerID) {
|
||||||
|
// this.playerID = playerID;
|
||||||
|
// this.score = 0;
|
||||||
|
// this.numCoconuts = 0;
|
||||||
|
// this.numBamboo = 0;
|
||||||
|
// this.numWater = 0;
|
||||||
|
// this.numPreciousStones = 0;
|
||||||
|
// this.numStatuette = 0;
|
||||||
|
// this.settlers = new Coord[0];
|
||||||
|
// this.villages = new Coord[0];
|
||||||
|
// }
|
||||||
|
// // endregion
|
||||||
|
// // region Getters and Setters
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * Get the player's ID
|
||||||
|
// * @return int player ID
|
||||||
|
// */
|
||||||
|
// public int getPlayerID() {
|
||||||
|
// return playerID;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * Get the player's settlers
|
||||||
|
// * @return Coord[] list of the player's settlers coords
|
||||||
|
// */
|
||||||
|
// public Coord[] getSettlers() {
|
||||||
|
// return settlers;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * Get the player's villages
|
||||||
|
// * @return Coord[] list of the player's villages coords
|
||||||
|
// */
|
||||||
|
// public Coord[] getVillages() {
|
||||||
|
// return villages;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public Coord[] getPieces() {
|
||||||
|
// Coord[] pieces = new Coord[settlers.length + villages.length];
|
||||||
|
// for (int i = 0; i < settlers.length; i++) {
|
||||||
|
// pieces[i] = settlers[i];
|
||||||
|
// }
|
||||||
|
// for (int i = 0; i < villages.length; i++) {
|
||||||
|
// pieces[settlers.length + i] = villages[i];
|
||||||
|
// }
|
||||||
|
// return pieces;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * Get number of pieces on island
|
||||||
|
// * @param island Island island to check
|
||||||
|
// * @return int number of pieces on island
|
||||||
|
// */
|
||||||
|
// public int getNumPiecesOnIsland(Island island) {
|
||||||
|
// int numPieces = 0;
|
||||||
|
// for (Coord piece : getPieces()) {
|
||||||
|
// if (island.containsCoord(piece)) {
|
||||||
|
// numPieces++;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return numPieces;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * Get the coordinates of the island
|
||||||
|
// * @return Coord[] coordinates of the island
|
||||||
|
// */
|
||||||
|
// public Coord[] getCoords() {
|
||||||
|
// return coords;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * Check if the island contains a coordinate
|
||||||
|
// * @param coord the coordinate to be checked
|
||||||
|
// * @return boolean true if the island contains the coordinate
|
||||||
|
// */
|
||||||
|
// public boolean containsCoord(Coord coord) {
|
||||||
|
// for (Coord c : this.coords) {
|
||||||
|
// if (c.equals(coord)) {
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
public int scoreLinks(int playerID) {
|
public int scoreLinks(int playerID) {
|
||||||
int maxIslands = 0;
|
int maxIslands = 0;
|
||||||
|
int distinctIslandsCounter = 0;
|
||||||
|
int score = 0;
|
||||||
|
|
||||||
|
Coord[] playerCoords = players[playerID].getPieces(); // playerCoords
|
||||||
|
|
||||||
|
for(Island island : islands) {
|
||||||
|
Coord[] islandCoords = island.getCoords();
|
||||||
|
|
||||||
|
for ( Coord playerCoord : playerCoords ) {
|
||||||
|
if (island.containsCoord(playerCoord)) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// for(Island island : islands) {
|
||||||
|
// Coord[] islandCoords = island.getCoords(); // Island Coords
|
||||||
|
//
|
||||||
|
// for ( Coord playerCoord : playerCoords) {
|
||||||
|
// for( Coord islandCoord : islandCoords) {
|
||||||
|
// if (playerCoord.areTwoCoordsLink(islandCoord) && )
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
return maxIslands * 5; //! TODO
|
return maxIslands * 5; //! TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public boolean areTwoCoordsLink ( Coord coord) {
|
||||||
|
// if(isAdjacent(coord) || isAdjacentDiagonal(coord)) return true;
|
||||||
|
// else return false;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public Coord[] longestLink ( Coord coord) {
|
||||||
|
// ArrayList<Coord> linkContainer = new ArrayList<>();
|
||||||
|
// if (areTwoCoordsLink(coord)) {
|
||||||
|
// linkContainer.add(coord);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Coord[] endLinkContainer = new Coord[linkContainer.size()];
|
||||||
|
// return endLinkContainer;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Score Links
|
||||||
|
// * A (potentially) branching path of neighbouring settlers and villages
|
||||||
|
// * belonging to a player forms a chain. Players earn points from the chain
|
||||||
|
// * of their pieces which links the most islands. Players earn 5 points
|
||||||
|
// * per linked island in this chain.
|
||||||
|
|
||||||
|
// public int scoreTotalIslands(int playerID) {
|
||||||
|
// int score = 0;
|
||||||
|
// int islandCount = 0;
|
||||||
|
// for (Island island : islands) {
|
||||||
|
// // Get island coords
|
||||||
|
// Coord[] islandCoords = island.getCoords();
|
||||||
|
// // Get player's coords
|
||||||
|
// Coord[] playerCoords = players[playerID].getPieces();
|
||||||
|
// // Check if player has a piece on the island
|
||||||
|
// boolean hasPiece = false;
|
||||||
|
// for (Coord playerCoord : playerCoords) {
|
||||||
|
// for (Coord islandCoord : islandCoords) {
|
||||||
|
// if (playerCoord.equals(islandCoord)) {
|
||||||
|
// hasPiece = true;
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if (hasPiece) break;
|
||||||
|
// }
|
||||||
|
// if (hasPiece) islandCount++;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (islandCount >= 8) score = 20;
|
||||||
|
// else if (islandCount == 7) score = 10;
|
||||||
|
//
|
||||||
|
// return score;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Score resources
|
* Score resources
|
||||||
* @param playerID int player to score
|
* @param playerID int player to score
|
||||||
|
|||||||
Reference in New Issue
Block a user