gayass
This commit is contained in:
parent
9f946701c8
commit
c10eb85957
9 changed files with 47 additions and 3 deletions
|
|
@ -437,6 +437,16 @@ public class Main extends JFrame {
|
||||||
}
|
}
|
||||||
sb.append("\n");
|
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(
|
sb.append(
|
||||||
"\nYour goal is to WIN. If you cannot win immediately, BLOCK the opponent. If neither, play optimally to force a draw.\n");
|
"\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");
|
sb.append("Analyze the board carefully. Don't make random moves.\n");
|
||||||
|
|
@ -444,6 +454,38 @@ public class Main extends JFrame {
|
||||||
return sb.toString();
|
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 {
|
private String callOpenRouter(String prompt) throws IOException, InterruptedException {
|
||||||
HttpClient client = HttpClient.newHttpClient();
|
HttpClient client = HttpClient.newHttpClient();
|
||||||
String jsonBody = "{"
|
String jsonBody = "{"
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
|
|
@ -1,5 +1,5 @@
|
||||||
#Generated by Maven
|
#Generated by Maven
|
||||||
#Tue Feb 10 14:58:36 CET 2026
|
#Tue Feb 10 15:06:20 CET 2026
|
||||||
artifactId=ai-client
|
artifactId=ai-client
|
||||||
groupId=com.lona.tictactoe
|
groupId=com.lona.tictactoe
|
||||||
version=1.0-SNAPSHOT
|
version=1.0-SNAPSHOT
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -161,7 +161,8 @@ input[type="text"]:focus {
|
||||||
|
|
||||||
.board {
|
.board {
|
||||||
display: grid;
|
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;
|
gap: 10px;
|
||||||
aspect-ratio: 1;
|
aspect-ratio: 1;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
|
|
|
||||||
|
|
@ -161,7 +161,8 @@ input[type="text"]:focus {
|
||||||
|
|
||||||
.board {
|
.board {
|
||||||
display: grid;
|
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;
|
gap: 10px;
|
||||||
aspect-ratio: 1;
|
aspect-ratio: 1;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Loading…
Add table
Reference in a new issue