Optimized task 11 scoreLink #1

Signed-off-by: Immanuel Alvaro Bhirawa <u7280427@anu.edu.au>
This commit is contained in:
Immanuel Alvaro Bhirawa 2023-05-06 20:12:30 +10:00
parent 3d84fa1e83
commit 199a50b088

View File

@ -563,9 +563,7 @@ public class State {
public int scoreLinks(int playerID) {
Coord[] playerCoords = players[playerID].getPieces();
Set<Coord> playerCoordsSet = new HashSet<>(Arrays.asList(playerCoords));
int maxScore = findLongestLinkScore(playerCoordsSet, islands);
return maxScore;
}
@ -574,7 +572,6 @@ public class State {
Set<Coord> current = new HashSet<>();
Coord now;
int max = scoreForLink(longest,islands);
for(Island islandIter : islands) {
@ -608,19 +605,16 @@ public class State {
}
public static int scoreForLink(Set<Coord> longestLink, Island[] islands) {
int numOfIslands = 0;
outerLoop:
Set<Island> connectedIslands = new HashSet<>();
for (Coord c : longestLink) {
for (Island i : islands) {
for ( Coord c : longestLink ) {
if (i.containsCoord(c)) {
numOfIslands++;
continue outerLoop;
connectedIslands.add(i);
break;
}
}
}
return numOfIslands * 5;
return connectedIslands.size() * 5;
}
/**