@Override
    public Coordinates nextMove(GameBoard gb) {
        oldTime = System.currentTimeMillis() - timeoutOffset;
        timeoutHasOccured = false;
        boardSize = gb.getSize();
        int alpha = LOOSE;

        Coordinates bestMove = null;
        int bestScore = 0;

        ArrayList<Coordinates> openCoordinatesList = getOpenCoordinates(gb, player);

        if (openCoordinatesList.size() == 0) {
            return null;
        }

        int depth = beginningDepth;

        //try
        //{
        while (!timeoutHasOccured) {
            checkTimeout();
            alpha = LOOSE;

            Coordinates depthBestMove = null;

            for (Coordinates coord : openCoordinatesList) {
                GameBoard gbClone = gb.clone();
                gbClone.checkMove(player, coord);
                gbClone.makeMove(player, coord);

                int score = RecursionStep(gbClone, alpha, WIN, depth - 1, -1);

                //System.out.print(score+": ");
                if (score > alpha) {
                    alpha = score;
                    depthBestMove = coord;
                    //System.out.println("no failure atm");
                }
	                //else
                //System.out.println("failure while trying depth "+depth);
            }

            if (depthBestMove != null) {
                bestMove = depthBestMove;
                bestScore = alpha;
            }

            depth++;
        }
        //}
        //catch(Exception e)
        //{}

        if (timeoutHasOccured) {
            long timer = System.currentTimeMillis() - oldTime;
            if (bestMove != null) {
                System.out.println("Ingwer got till depth "
                        + (depth - 1)
                        + ", and is expecting a approximate score of "
                        + String.valueOf(bestScore)
                        + ". "
                        + "It needed "
                        + (timer)
                        + " milliseconds.");
                return bestMove;
            } else {
                System.out.println("Ingwer couldn't finish lowest depth "
                        + depth + " and is therefore returning a pseudo-random coord. "
                        + "It needed "
                        + (timer)
                        + " milliseconds.");
                return openCoordinatesList.get(0);
            }
        } else {
            return null;
        }
    }