| 123 | } |
| 124 | |
| 125 | public OutCome iterativeDeepening(final Board board, final long time) { |
| 126 | transpositionTable = new HashMap<>(); |
| 127 | final long start = System.currentTimeMillis(); |
| 128 | int depth = 1; |
| 129 | OutCome evaluation = alphaBeta(board, depth, Integer.MIN_VALUE, Integer.MAX_VALUE, 1000); |
| 130 | while (System.currentTimeMillis() - start < time * 1000 && Math.abs(evaluation.getScore()) - Integer.MAX_VALUE < 0.0001) { |
| 131 | depth++; |
| 132 | System.out.println("DEPTH: " + depth + " EVAL: " + evaluation + " TIME: " + ((System.currentTimeMillis() - start) / 1000)); |
| 133 | try { |
| 134 | int finalDepth = depth; |
| 135 | evaluation = CompletableFuture.supplyAsync(() -> alphaBeta(board, finalDepth, Integer.MIN_VALUE, Integer.MAX_VALUE, 1000)).get(time * 1000 - (System.currentTimeMillis() - start), TimeUnit.MILLISECONDS); |
| 136 | } catch (InterruptedException | ExecutionException | TimeoutException e) { |
| 137 | System.out.println("TIMEOUT: " + depth); |
| 138 | break; |
| 139 | } |
| 140 | } |
| 141 | return evaluation; |
| 142 | } |
| 143 | |
| 144 | private String getString(Move move) { |
| 145 | return move.piece.position.notation() + move.target.notation(); |