diff --git a/AI/src/at/dropical/wolliAI/AiMain.java b/AI/src/at/dropical/wolliAI/AiMain.java index b91aa8e..caa8ce5 100644 --- a/AI/src/at/dropical/wolliAI/AiMain.java +++ b/AI/src/at/dropical/wolliAI/AiMain.java @@ -12,6 +12,9 @@ public class AiMain { public static void main(String[] args) throws InterruptedException { AI ai = new BestPossibilityAI(new ServerAdapter()); + //Temp + //AI ai2 = new BestPossibilityAI(new ServerAdapter()); + while(true) { Thread.sleep(100); try { diff --git a/AI/src/at/dropical/wolliAI/bestPossibility/GameField.java b/AI/src/at/dropical/wolliAI/bestPossibility/GameField.java index 08048ec..04eaed7 100644 --- a/AI/src/at/dropical/wolliAI/bestPossibility/GameField.java +++ b/AI/src/at/dropical/wolliAI/bestPossibility/GameField.java @@ -84,12 +84,14 @@ public GameField clone() { /** Move the tetromino as far left as possible. */ void moveToLeftBorder() { - while(arena.checkTetromino(mino, posH, posW -1, true)) + //replaced while with for loop and sanity check. + for(int i = 0; i= 1) { + emptyTetromino = false; // If space is occupied Or out of bounds of actual arena if(arena[marginTop + h + i][marginLeftRight + w + j] >= 1 @@ -95,7 +97,8 @@ public boolean checkTetromino(Tetromino tetromino, int h, int w, boolean overTop } } // Only when all 4*4 spaces of the Tetromino are ok. - return true; + // Special case when tetromino is empty, then return false. To prevent endless loops. + return !emptyTetromino; } /** Only the actual arena. */ diff --git a/AI/src/at/dropical/wolliAI/serverAdapter/ServerAdapter.kt b/AI/src/at/dropical/wolliAI/serverAdapter/ServerAdapter.kt index 6b5505e..8a775c3 100644 --- a/AI/src/at/dropical/wolliAI/serverAdapter/ServerAdapter.kt +++ b/AI/src/at/dropical/wolliAI/serverAdapter/ServerAdapter.kt @@ -26,7 +26,7 @@ import java.util.* * in this class. */ class ServerAdapter( - player: String = "Wolli AI", + player: String = "Wolli AI "+ Math.random(), hostName: String = "localhost", port: Int = 45000 ): DropicalListener { @@ -37,6 +37,7 @@ class ServerAdapter( private val server: DropicalProxy = DropicalProxy(hostName, port, this) private val playerName = player + init { /** Auto-queue to a game on the server. */ server.writeToServer(JoinRequest(playerName)) @@ -47,12 +48,13 @@ class ServerAdapter( /* The DropicalProxy calls these functions. */ override fun updateUI(container: GameDataContainer?) { if (container != null) { - val i = 0 + var i = 0 while (i < container.playernames.size) { if (container.playernames[i] == playerName) { index = i break } + i++; } newestGameDataContainer = container }