src/ai/MiniMaxAI.java
public Move min(Board board, int depth) {
        Random r = new Random();

        if ((board.checkForGameOver()) || (depth == maxDepth)) {
            Move lastMove = new Move(board.getLastMove().getRow(), board.getLastMove().getColumn(), board.evaluate());
            return lastMove;
        }
        ArrayList<Board> children = new ArrayList<Board>(board.getChildren(Constants.P2));
        Move minMove = new Move(Integer.MAX_VALUE);
        for (Board child : children) {
            Move move = max(child, depth + 1);
            if (move.getValue() <= minMove.getValue()) {
                if ((move.getValue() == minMove.getValue())) {
                    if (r.nextInt(2) == 0) {
                        minMove.setRow(child.getLastMove().getRow());
                        minMove.setColumn(child.getLastMove().getColumn());
                        minMove.setValue(move.getValue());
                    }
                } else {
                    minMove.setRow(child.getLastMove().getRow());
                    minMove.setColumn(child.getLastMove().getColumn());
                    minMove.setValue(move.getValue());
                }
            }
        }
        return minMove;
    }
// Min works similarly to max.
Min works similarly to max.
Min works similarly to max .
public Move min(Board board, int depth) {
        Random r = new Random();
        if ((board.checkForGameOver()) || (depth == maxDepth)) {
            Move lastMove = new Move(board.getLastMove().getRow(), board.getLastMove().getColumn(), board.evaluate());
            return lastMove;
        }
        ArrayList<Board> children = new ArrayList<Board>(board.getChildren(Constants.P2));
        Move minMove = new Move(Integer.MAX_VALUE);
        for (Board child : children) {
            Move move = max(child, depth + 1);
            if (move.getValue() <= minMove.getValue()) {
                if ((move.getValue() == minMove.getValue())) {
                    if (r.nextInt(2) == 0) {
                        minMove.setRow(child.getLastMove().getRow());
                        minMove.setColumn(child.getLastMove().getColumn());
                        minMove.setValue(move.getValue());
                    }
                } else {
                    minMove.setRow(child.getLastMove().getRow());
                    minMove.setColumn(child.getLastMove().getColumn());
                    minMove.setValue(move.getValue());
                }
            }
        }
        return minMove;
    }
public Move min ( Board board , int depth ) { Random r = new Random ( ) ; if ( ( board . checkForGameOver ( ) ) || ( depth == maxDepth ) ) { Move lastMove = new Move ( board . getLastMove ( ) . getRow ( ) , board . getLastMove ( ) . getColumn ( ) , board . evaluate ( ) ) ; return lastMove ; } ArrayList < Board > children = new ArrayList < Board > ( board . getChildren ( Constants . P2 ) ) ; Move minMove = new Move ( Integer . MAX_VALUE ) ; for ( Board child : children ) { Move move = max ( child , depth + 1 ) ; if ( move . getValue ( ) <= minMove . getValue ( ) ) { if ( ( move . getValue ( ) == minMove . getValue ( ) ) ) { if ( r . nextInt ( 2 ) == 0 ) { minMove . setRow ( child . getLastMove ( ) . getRow ( ) ) ; minMove . setColumn ( child . getLastMove ( ) . getColumn ( ) ) ; minMove . setValue ( move . getValue ( ) ) ; } } else { minMove . setRow ( child . getLastMove ( ) . getRow ( ) ) ; minMove . setColumn ( child . getLastMove ( ) . getColumn ( ) ) ; minMove . setValue ( move . getValue ( ) ) ; } } } return minMove ; }
Min works similarly to max.
Min works similarly to max .