@Override public String getNextAction(int[] grid, int _playerNumber) { String ret = "X"; // as fallback, make a random move playerNumber = _playerNumber; // now try to come up with something more clever long startTime = new Date().getTime(); situations = 0; IAICallback logCallBack = new IAICallback() { @Override public void callback(String message) { System.out.println(message); } }; int opponentNumber = playerNumber - 1; if (opponentNumber == 0) { opponentNumber = 2; } Situation rootSituation = new Situation(-1, opponentNumber, grid, 0, null); bestSituation = rootSituation; // may never be null! rootSituation.callback = logCallBack; rootSituation.computeNextSituations(TREE_DEPTH); long timePassed = new Date().getTime() - startTime; double seconds = (double) timePassed / 1000.0; double sps = (double) situations / seconds; System.out.println( "computed " + situations + " situation in " + timePassed + "ms: " + sps + " situations per second."); // found something! if (bestSituation._parentSituation != null && bestSituation._parentSituation._followingSituationsAreWins != 0) { ret = getNextStepToSituation(bestSituation); } else { System.out.println("Couldn't find any good moves... spamming random move."); ret = computeRandomAction(); } return ret; }