From 27423d33370183867b47f5a0eed4c1c56a5527d3 Mon Sep 17 00:00:00 2001 From: lieght Date: Mon, 15 Sep 2025 20:29:37 +0200 Subject: [PATCH] Renamed TTT to TicTacToe, fixed grammer and spelling --- .../{MinMaxTTT.java => MinMaxTicTacToe.java} | 24 ++++++++----------- .../toop/game/{TTT.java => TicTacToe.java} | 8 +++---- 2 files changed, 14 insertions(+), 18 deletions(-) rename src/main/java/org/toop/game/{MinMaxTTT.java => MinMaxTicTacToe.java} (83%) rename src/main/java/org/toop/game/{TTT.java => TicTacToe.java} (89%) diff --git a/src/main/java/org/toop/game/MinMaxTTT.java b/src/main/java/org/toop/game/MinMaxTicTacToe.java similarity index 83% rename from src/main/java/org/toop/game/MinMaxTTT.java rename to src/main/java/org/toop/game/MinMaxTicTacToe.java index 24231de..936e3d2 100644 --- a/src/main/java/org/toop/game/MinMaxTTT.java +++ b/src/main/java/org/toop/game/MinMaxTicTacToe.java @@ -4,15 +4,11 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.toop.Main; -/* - * TTT = TIC TAC TOE FOR THE LESS EDUCATED POPULATION ON THIS CODE - */ - -public class MinMaxTTT { +public class MinMaxTicTacToe { private static final Logger logger = LogManager.getLogger(Main.class); - public int findBestMove(TTT game) { + public int findBestMove(TicTacToe game) { /** * This method tries to find the best move by seeing if it can set a winning move, if not, it will do a minimax. */ @@ -22,7 +18,7 @@ public class MinMaxTTT { // simulate all possible moves on the field for (int i = 0; i < game.grid.length; i++) { if (game.validateMove(i)) { // check if the move is legal here - TTT copyGame = game.copyBoard(); // make a copy of the game + TicTacToe copyGame = game.copyBoard(); // make a copy of the game State result = copyGame.playMove(i); // play a move on the copy board int thisMoveValue; @@ -42,7 +38,7 @@ public class MinMaxTTT { return bestMove; // return the best move when we've done everything } - public int doMinimax(TTT game, int depth, boolean maximizing) { + public int doMinimax(TicTacToe game, int depth, boolean maximizing) { /** * This method simulates all the possible future moves in the game through a copy in search of the best move. */ @@ -50,17 +46,17 @@ public class MinMaxTTT { if (state) { if (maximizing) { - // its the maximizing players turn and someone has won. this is not good, so return a negative value + // it's the maximizing players turn and someone has won. this is not good, so return a negative value return -10 + depth; } else { - // it is the turn of the ai and it has won! this is good for us, so return a positive value above 0 + // it is the turn of the AI and it has won! this is good for us, so return a positive value above 0 return 10 - depth; } } else { boolean empty = false; - for (char cell : game.grid) { // else, look at draw conditions. we check per cell if its empty or not + for (char cell : game.grid) { // else, look at draw conditions. we check per cell if it's empty or not if (cell == ' ') { empty = true; // if a thing is empty, set to true break; // break the loop @@ -71,11 +67,11 @@ public class MinMaxTTT { } } - if (maximizing) { // its the maximizing players turn, the AI + if (maximizing) { // it's the maximizing players turn, the AI int bestVal = -100; // set the value to lowest as possible for (int i = 0; i < game.grid.length; i++) { // loop through the grid if (game.validateMove(i)) { - TTT copyGame = game.copyBoard(); + TicTacToe copyGame = game.copyBoard(); copyGame.playMove(i); // play the move on a copy board int value = doMinimax(copyGame, depth - 1, false); // keep going with the minimax bestVal = Math.max(bestVal, value); // select the best value for the maximizing player (the AI) @@ -88,7 +84,7 @@ public class MinMaxTTT { int bestVal = 100; // set the value to the highest possible for (int i = 0; i < game.grid.length; i++) { // loop through the grid if (game.validateMove(i)) { - TTT copyGame = game.copyBoard(); + TicTacToe copyGame = game.copyBoard(); copyGame.playMove(i); // play the move on a copy board int value = doMinimax(copyGame, depth - 1, true); // keep minimaxing bestVal = Math.min(bestVal, value); // select the lowest score for the minimizing player, they want to make it hard for us diff --git a/src/main/java/org/toop/game/TTT.java b/src/main/java/org/toop/game/TicTacToe.java similarity index 89% rename from src/main/java/org/toop/game/TTT.java rename to src/main/java/org/toop/game/TicTacToe.java index 1d448e6..ace4a39 100644 --- a/src/main/java/org/toop/game/TTT.java +++ b/src/main/java/org/toop/game/TicTacToe.java @@ -4,11 +4,11 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.toop.Main; -public class TTT extends GameBase { +public class TicTacToe extends GameBase { public int moveCount; private static final Logger logger = LogManager.getLogger(Main.class); - public TTT(String player1, String player2) { + public TicTacToe(String player1, String player2) { super(3); // 3x3 Grid players = new Player[2]; players[0] = new Player(player1, 'X'); @@ -79,11 +79,11 @@ public class TTT extends GameBase { return false; } - public TTT copyBoard() { + public TicTacToe copyBoard() { /** * This method copies the board, mainly for AI use. */ - TTT clone = new TTT(players[0].Name(), players[1].Name()); + TicTacToe clone = new TicTacToe(players[0].Name(), players[1].Name()); System.arraycopy(this.grid, 0, clone.grid, 0, this.grid.length); clone.moveCount = this.moveCount; clone.currentPlayer = this.currentPlayer;