public Move move(Situation situation, int timeLeft) { resourceManager.startTurn(sideOfAI, timeLeft); // creating fallback mode; Move nextMove = moveEvaluator.getFallBackMove(situation); try { // popping out of this loop when time limiter hits the wall or nextMove is known to be Winning // game path. for (int searchDepth = 1; searchDepth < resourceManager.calculateCutDepth(timeLeft); searchDepth++) { nextMove = moveEvaluator.getBesMove(situation, searchDepth); if (moveEvaluator.isPathOfWinningMove(nextMove)) { return nextMove; } } } catch (SoftTimeLimitException e) { // catch Halting condition, at the moment nextMove has best possible move (naturally // incomplete stateSearch is discarded). return nextMove; } catch (Exception e) { e.printStackTrace(); return moveEvaluator.getFallBackMove(situation); } // To get here we have been searched all the game states, and then some but not found winning // condition... so. return nextMove; }