static double alphabeta(Position p, int depth, double alpha, double beta, int player) {
        // 0 tries to maximize, 1 tries to minimize
        if (p.winner == -1) {
            return -1E10 - depth; // prefer to win sooner
        }
        if (p.winner == +1) {
            return +1E10 + depth; // and lose later
        }
        if (depth == 0) {
            return ce.eval(p);
        }
        Vector<Position> P = p.getNextPositions();
        Collections.sort(P, new PositionComparator(P));
        if (player == 0) {
            Collections.reverse(P);
        }

        //System.out.println("Pelaaja: "+player+" koko: "+P.size());
        //System.out.println("Ensimmäinen: "+eval(P.elementAt(0)));
        //System.out.println("Viimeinen: "+eval(P.lastElement()));

        if (player == 0) {
            for (int i = 0; i < P.size(); ++i) {
                alpha = Math.max(alpha, alphabeta(P.elementAt(i), depth - 1, alpha, beta, 1));
                if (beta <= alpha) {
                    break;
                }
            }
            return alpha;
        }

        for (int i = 0; i < P.size(); ++i) {
            beta = Math.min(beta, alphabeta(P.elementAt(i), depth - 1, alpha, beta, 0));
            if (beta <= alpha) {
                break;
            }
        }

        return beta;
    }