From e0bc262c6a3006304a50866b0029a0a3766d1a79 Mon Sep 17 00:00:00 2001 From: Immanuel Alvaro Bhirawa Date: Fri, 14 Apr 2023 08:16:42 +1000 Subject: [PATCH] Task 7 [Debug-In-Process], made some progress Signed-off-by: Immanuel Alvaro Bhirawa --- src/comp1110/ass2/BlueLagoon.java | 52 +++++++++++++++++++++---------- src/comp1110/ass2/gui/Viewer.java | 2 +- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/comp1110/ass2/BlueLagoon.java b/src/comp1110/ass2/BlueLagoon.java index fee02ef..1df9e48 100644 --- a/src/comp1110/ass2/BlueLagoon.java +++ b/src/comp1110/ass2/BlueLagoon.java @@ -229,8 +229,8 @@ public class BlueLagoon { ArrayList villageCoords = new ArrayList<>(); // Placed villags coordinates ArrayList playerSettlerCoords = new ArrayList<>(); ArrayList playerVillageCoords = new ArrayList<>(); - String[] split = moveString.split(" "); + String[] split = moveString.split(" "); String pieceType = split[0]; // Move coord piece type S or T String moveCoords = split[1]; String[] splitCoords = moveCoords.split(","); @@ -329,29 +329,43 @@ public class BlueLagoon { // for out of bound stuff if(yMoveCoords % 2 != 0 && yMoveCoords > boardHeight - 1) return false; if(xMoveCoords > boardHeight - 2 + (xMoveCoords % 2)) return false; -// * In the Exploration Phase, the move must either be: -// * - A settler placed on any unoccupied sea space -// * - A settler or a village placed on any unoccupied land space +//*

+// * In the Exploration Phase, the move must either be: +// * - A settler placed on any unoccupied sea space +// * - A settler or a village placed on any unoccupied land space // * adjacent to one of the player's pieces. switch(currentPhase){ case "E": - // If the move pos is an occupied space, return false; - if(settlerCoords.contains(moveCoords)) return false; - if(villageCoords.contains(moveCoords)) return false; +// System.out.println("Island Coords" + coordsContainer); +// System.out.println("Settler" + settlerCoords); +// System.out.println("Village" + villageCoords); +// +// System.out.println(pieceType); +// System.out.println(moveString); +// System.out.println("If the spot is occupied return true " + (settlerCoords.contains(moveCoords) || villageCoords.contains(moveCoords))); +// System.out.println("Village placed on sea returns true " + (pieceType.equals("T") && !coordsContainer.contains(moveCoords))); +// System.out.println("if the village is placed on the land and is adjacent return true" + (pieceType.equals("T") && ((!isAdjacent(moveCoords, playerVillageCoords)) && +// (!isAdjacent(moveCoords, playerSettlerCoords))))); +// System.out.println("If the settler is on land return true" + (pieceType.equals("S") && coordsContainer.contains(moveCoords))); +// System.out.println("if the settlers are adjacent return true" + (!isAdjacent(moveCoords, playerSettlerCoords) && +// !isAdjacent(moveCoords, playerVillageCoords))); + + // If the move Coords is an occupied space, return false; + if(settlerCoords.contains(moveCoords) || villageCoords.contains(moveCoords)) return false; // If the Village is being placed on the sea return false if(pieceType.equals("T") && !coordsContainer.contains(moveCoords)) return false; // if the village is placed on Land and it's not adjacent to any // of the pieces return false - if(pieceType.equals("T") && ((!isAdjacent(moveCoords, playerVillageCoords)) && + if(pieceType.equals("T") && (!isAdjacent(moveCoords, playerVillageCoords) && !isAdjacent(moveCoords, playerSettlerCoords))) return false; // If settler is on land and it's not adjacent to any of the pieces // return false if(pieceType.equals("S") && coordsContainer.contains(moveCoords)){ if(!isAdjacent(moveCoords, playerSettlerCoords) && - !isAdjacent(moveCoords, playerVillageCoords)) return false; + !isAdjacent(moveCoords, playerVillageCoords)) return false; } break; // *

@@ -385,21 +399,25 @@ public class BlueLagoon { } private static boolean isAdjacent(String centerCoords, ArrayList coordsContainer) { + // for (String coord : coordsContainer) System.out.println(coord); + // if(xMoveCoords > boardHeight - 2 + (xMoveCoords % 2)) return false; + String[] coordsSplit = centerCoords.split(","); - int mainX = Integer.parseInt(coordsSplit[0]); - int mainY = Integer.parseInt(coordsSplit[1]); + int mainX = Integer.parseInt(coordsSplit[1]); + int mainY = Integer.parseInt(coordsSplit[0]); int[][] adjacentModifiers = { - {0 + mainX % 2 * -1, -1}, - {1 + mainX % 2 * -1, -1}, + {0 - mainY % 2, -1}, + {1 - mainY % 2, -1}, {-1, 0}, {1, 0}, - {0 + mainX % 2 * -1, 1}, - {1 + mainX % 2 * -1, 1}, + {0 - mainY % 2, 1}, + {1 - mainY % 2, 1}, }; - for (int[] mod : adjacentModifiers) - if (coordsContainer.contains(String.format("%s,%s", mainX + mod[0], mainY + mod[1]))) + for (int[] mod : adjacentModifiers) { + if (coordsContainer.contains(String.format("%s,%s", mainY + mod[1], mainX + mod[0]))) return true; + } return false; } diff --git a/src/comp1110/ass2/gui/Viewer.java b/src/comp1110/ass2/gui/Viewer.java index cd00544..bd9f6e5 100644 --- a/src/comp1110/ass2/gui/Viewer.java +++ b/src/comp1110/ass2/gui/Viewer.java @@ -153,7 +153,7 @@ public class Viewer extends Application { // Generating the water tiles ( the background water map ) for(int i = 0; i < boardHeight; i++){ - for(int j = 0; j < boardHeight - (-1 * i % 2 + 1); j++){ + for(int j = 0; j < boardHeight - (-1 * i % 2 + 1); j++){ addBoardTile(viewerGrid, boardHeightPx/boardHeight, String.format("%s,%s", i, j), Color.DARKBLUE); }