diff --git a/ai-client/src/main/java/com/lona/tictactoe/client/Main.java b/ai-client/src/main/java/com/lona/tictactoe/client/Main.java index bff54f7..7d32d42 100644 --- a/ai-client/src/main/java/com/lona/tictactoe/client/Main.java +++ b/ai-client/src/main/java/com/lona/tictactoe/client/Main.java @@ -437,6 +437,16 @@ public class Main extends JFrame { } sb.append("\n"); } + + // Threat Detection + char opponent = (mySymbol == 'X') ? 'O' : 'X'; + String threats = findThreats(opponent); + if (!threats.isEmpty()) { + sb.append("\n!!! CRITICAL WARNING !!!\n"); + sb.append(threats); + sb.append("You MUST block this threat immediately or you will lose.\n"); + } + sb.append( "\nYour goal is to WIN. If you cannot win immediately, BLOCK the opponent. If neither, play optimally to force a draw.\n"); sb.append("Analyze the board carefully. Don't make random moves.\n"); @@ -444,6 +454,38 @@ public class Main extends JFrame { return sb.toString(); } + private String findThreats(char opponent) { + int[][] wins = { + { 0, 1, 2 }, { 3, 4, 5 }, { 6, 7, 8 }, // rows + { 0, 3, 6 }, { 1, 4, 7 }, { 2, 5, 8 }, // cols + { 0, 4, 8 }, { 2, 4, 6 } // diags + }; + StringBuilder threatMsg = new StringBuilder(); + for (int[] w : wins) { + // Check if 2 cells are opponent and 1 is empty + int opCount = 0; + int emptyCount = 0; + int emptyIndex = -1; + + for (int idx : w) { + if (boardState[idx] == opponent) + opCount++; + else if (boardState[idx] == ' ') { + emptyCount++; + emptyIndex = idx; + } + } + + if (opCount == 2 && emptyCount == 1) { + int r = emptyIndex / 3; + int c = emptyIndex % 3; + threatMsg.append("Opponent '").append(opponent).append("' is about to win at row ").append(r) + .append(", col ").append(c).append(".\n"); + } + } + return threatMsg.toString(); + } + private String callOpenRouter(String prompt) throws IOException, InterruptedException { HttpClient client = HttpClient.newHttpClient(); String jsonBody = "{" diff --git a/ai-client/target/ai-client-1.0-SNAPSHOT.jar b/ai-client/target/ai-client-1.0-SNAPSHOT.jar index d8ce2e3..025a776 100644 Binary files a/ai-client/target/ai-client-1.0-SNAPSHOT.jar and b/ai-client/target/ai-client-1.0-SNAPSHOT.jar differ diff --git a/ai-client/target/classes/com/lona/tictactoe/client/Main.class b/ai-client/target/classes/com/lona/tictactoe/client/Main.class index 47f3e47..3c62e1b 100644 Binary files a/ai-client/target/classes/com/lona/tictactoe/client/Main.class and b/ai-client/target/classes/com/lona/tictactoe/client/Main.class differ diff --git a/ai-client/target/maven-archiver/pom.properties b/ai-client/target/maven-archiver/pom.properties index 7c34246..eebd829 100644 --- a/ai-client/target/maven-archiver/pom.properties +++ b/ai-client/target/maven-archiver/pom.properties @@ -1,5 +1,5 @@ #Generated by Maven -#Tue Feb 10 14:58:36 CET 2026 +#Tue Feb 10 15:06:20 CET 2026 artifactId=ai-client groupId=com.lona.tictactoe version=1.0-SNAPSHOT diff --git a/ai-client/target/original-ai-client-1.0-SNAPSHOT.jar b/ai-client/target/original-ai-client-1.0-SNAPSHOT.jar index f971395..6ba3f7b 100644 Binary files a/ai-client/target/original-ai-client-1.0-SNAPSHOT.jar and b/ai-client/target/original-ai-client-1.0-SNAPSHOT.jar differ diff --git a/web-client/src/main/resources/static/css/style.css b/web-client/src/main/resources/static/css/style.css index 1ab084c..d7b848d 100644 --- a/web-client/src/main/resources/static/css/style.css +++ b/web-client/src/main/resources/static/css/style.css @@ -161,7 +161,8 @@ input[type="text"]:focus { .board { display: grid; - grid-template-columns: repeat(3, 1fr); + grid-template-columns: repeat(3, minmax(0, 1fr)); + grid-template-rows: repeat(3, minmax(0, 1fr)); gap: 10px; aspect-ratio: 1; margin: 0 auto; diff --git a/web-client/target/classes/static/css/style.css b/web-client/target/classes/static/css/style.css index 1ab084c..d7b848d 100644 --- a/web-client/target/classes/static/css/style.css +++ b/web-client/target/classes/static/css/style.css @@ -161,7 +161,8 @@ input[type="text"]:focus { .board { display: grid; - grid-template-columns: repeat(3, 1fr); + grid-template-columns: repeat(3, minmax(0, 1fr)); + grid-template-rows: repeat(3, minmax(0, 1fr)); gap: 10px; aspect-ratio: 1; margin: 0 auto; diff --git a/web-client/target/web-client-1.0-SNAPSHOT.jar b/web-client/target/web-client-1.0-SNAPSHOT.jar index 04cd654..4028d37 100644 Binary files a/web-client/target/web-client-1.0-SNAPSHOT.jar and b/web-client/target/web-client-1.0-SNAPSHOT.jar differ diff --git a/web-client/target/web-client-1.0-SNAPSHOT.jar.original b/web-client/target/web-client-1.0-SNAPSHOT.jar.original index 096d031..b6f1921 100644 Binary files a/web-client/target/web-client-1.0-SNAPSHOT.jar.original and b/web-client/target/web-client-1.0-SNAPSHOT.jar.original differ