MCPcopy Index your code
hub / github.com/coding-parrot/chess-engine / minMax

Method minMax

src/main/java/Engine.java:43–66  ·  view source on GitHub ↗
(final Board board, final int depth, final int printAt)

Source from the content-addressed store, hash-verified

41 }
42
43 public Evaluation minMax(final Board board, final int depth, final int printAt) {
44 final List<Move> legalMoves = board.getLegalMoves();
45 nodesEvaluated++;
46 if (legalMoves.isEmpty() || depth == 0) {
47 return new Evaluation(null, -board.evaluation(legalMoves.size()));
48 }
49 Evaluation bestMove = null;
50 for (Move move : legalMoves) {
51 final Board copy = board.copy();
52 copy.makeMove(move);
53 final Evaluation eval = minMax(copy, depth - 1, printAt);
54 if (depth == printAt) {
55 System.out.println(getString(move) + ": " + eval.getScore() + " " + move +
56 " " + copy.fenRepresentation());
57 }
58 if (bestMove == null || bestMove.getScore() > -eval.getScore()) {
59 bestMove = new Evaluation(move, -eval.getScore());
60 if (bestMove.getScore() < 0 && bestMove.getScore() + Integer.MAX_VALUE < 0.0001) {
61 return bestMove;
62 }
63 }
64 }
65 return bestMove;
66 }
67
68 public OutCome alphaBeta(final Board board, final int depth, double alpha, double beta, final int printAt) {
69 final List<Move> legalMoves = board.getLegalMoves();

Callers 4

mateInOneMethod · 0.95
mateInThreeMethod · 0.95
mateInTwoMethod · 0.95

Calls 8

makeMoveMethod · 0.95
getStringMethod · 0.95
getScoreMethod · 0.95
fenRepresentationMethod · 0.95
isEmptyMethod · 0.80
evaluationMethod · 0.80
copyMethod · 0.80
getLegalMovesMethod · 0.45

Tested by 4

mateInOneMethod · 0.76
mateInThreeMethod · 0.76
mateInTwoMethod · 0.76