|
132 | 132 | # Constants to be removed later
|
133 | 133 | USE_BOUND_FOR_CHECK_TEST = 1
|
134 | 134 | IID_LIMIT = 2 # depth > 2
|
135 |
| -IID_REDUCE = 1 # depth reduction in IID |
136 |
| -IID_TYPE = 2 # None, gamma=pos.score, gamma=gamma, iterative |
| 135 | +IID_REDUCE = 3 # depth reduction in IID |
| 136 | +IID_TYPE = 4 # None, gamma=pos.score, gamma=gamma, iterative, depth-reduce |
137 | 137 | REPEAT_NULL = 1 # Whether a null move can be responded too by another null move
|
| 138 | +NULL_LIMIT = 2 # Only null-move if depth > NULL_LIMIT |
138 | 139 |
|
139 | 140 | # minifier-hide start
|
140 | 141 | opt_ranges = dict(
|
|
144 | 145 | USE_BOUND_FOR_CHECK_TEST = (0, 2),
|
145 | 146 | IID_LIMIT = (0, 5),
|
146 | 147 | IID_REDUCE = (1, 5),
|
147 |
| - IID_TYPE = (0, 3), |
| 148 | + IID_TYPE = (0, 4), |
148 | 149 | REPEAT_NULL = (0, 1),
|
| 150 | + NULL_LIMIT = (0, 5), |
149 | 151 | )
|
150 | 152 | # minifier-hide end
|
151 | 153 |
|
@@ -323,12 +325,41 @@ def bound(self, pos, gamma, depth, root=True):
|
323 | 325 | # self.tp_score[pos, depth, root] = Entry(0, 0)
|
324 | 326 | return 0
|
325 | 327 |
|
| 328 | + # TODO: This seems like a great optimization! Maybe an alternative to IID? |
| 329 | + # But it also messes with stalemate detection without the depth limit. |
| 330 | + #if depth > 3 and pos not in self.tp_move: |
| 331 | + if IID_TYPE == 4 and pos not in self.tp_move: |
| 332 | + depth -= IID_REDUCE |
| 333 | + |
| 334 | + # This seems to work, but only detects stale_mates if null_limit = 0 |
| 335 | + #null_score = -self.bound(pos.rotate(nullmove=True), 1 - gamma, depth - 3, root=not REPEAT_NULL) if depth > NULL_LIMIT else None |
| 336 | + |
| 337 | + # TODO: Play with check extensions... |
| 338 | + # For some reason it gives me recursion errors... |
| 339 | + # Also, in stockfish check-extension gives like 1 ELO. It seems it doesn't |
| 340 | + # help me much either. However, singular extension (when one move is much |
| 341 | + # better than all others) gives stockfish like 100 ELO gain. Maybe I need that. |
| 342 | + #if depth > 2 and null_score == -MATE_UPPER: |
| 343 | + #depth += 1 |
| 344 | + |
| 345 | + # Singular extension: |
| 346 | + # Assume hash-move >= gamma. |
| 347 | + # For each move other than the hash-move, check they are <= gamma - margin. |
| 348 | + # (or <= hash-move-val - margin, since we are fail-soft.) |
| 349 | + # Or something like that. |
| 350 | + # But how do we make it not search-unstable? |
| 351 | + |
326 | 352 | # Generator of moves to search in order.
|
327 | 353 | # This allows us to define the moves, but only calculate them if needed.
|
328 | 354 | def moves():
|
329 | 355 | # First try not moving at all. We only do this if there is at least one major
|
330 | 356 | # piece left on the board, since otherwise zugzwangs are too dangerous.
|
331 |
| - if depth > 0 and not root and any(c in pos.board for c in "RBNQ"): |
| 357 | + # TODO: Since we nearly always null-move anyway, can't we just save the value |
| 358 | + # and use it to detect checks? It would interfer a bit with the zugswang detection |
| 359 | + # (the RBNQ check), but in Micromax he just does null-move and then checks that |
| 360 | + # afterwards, before he returns the score. |
| 361 | + if depth > NULL_LIMIT and not root and any(c in pos.board for c in "RBNQ"): |
| 362 | + #yield None, null_score |
332 | 363 | yield None, -self.bound(pos.rotate(nullmove=True), 1 - gamma, depth - 3, root=not REPEAT_NULL)
|
333 | 364 | # For QSearch we have a different kind of null-move, namely we can just stop
|
334 | 365 | # and not capture anything else.
|
@@ -472,6 +503,11 @@ def reduce(val):
|
472 | 503 | in_check = self.bound(flipped, MATE_UPPER, 0, root=False) == MATE_UPPER
|
473 | 504 | else:
|
474 | 505 | in_check = any(flipped.value(m) >= MATE_LOWER for m in flipped.gen_moves())
|
| 506 | + |
| 507 | + # null_in_check = null_score == -MATE_UPPER |
| 508 | + # if in_check != null_in_check: |
| 509 | + # print(in_check, null_in_check, null_score) |
| 510 | + |
475 | 511 | best = 0 if not in_check else -MATE_LOWER
|
476 | 512 |
|
477 | 513 | # Table part 2
|
|
0 commit comments