Skip to content

Commit 512acf4

Browse files
committed
new iid idea
1 parent faecfc1 commit 512acf4

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

sunfish_lmr.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,10 @@
132132
# Constants to be removed later
133133
USE_BOUND_FOR_CHECK_TEST = 1
134134
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
137137
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
138139

139140
# minifier-hide start
140141
opt_ranges = dict(
@@ -144,8 +145,9 @@
144145
USE_BOUND_FOR_CHECK_TEST = (0, 2),
145146
IID_LIMIT = (0, 5),
146147
IID_REDUCE = (1, 5),
147-
IID_TYPE = (0, 3),
148+
IID_TYPE = (0, 4),
148149
REPEAT_NULL = (0, 1),
150+
NULL_LIMIT = (0, 5),
149151
)
150152
# minifier-hide end
151153

@@ -323,12 +325,41 @@ def bound(self, pos, gamma, depth, root=True):
323325
# self.tp_score[pos, depth, root] = Entry(0, 0)
324326
return 0
325327

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+
326352
# Generator of moves to search in order.
327353
# This allows us to define the moves, but only calculate them if needed.
328354
def moves():
329355
# First try not moving at all. We only do this if there is at least one major
330356
# 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
332363
yield None, -self.bound(pos.rotate(nullmove=True), 1 - gamma, depth - 3, root=not REPEAT_NULL)
333364
# For QSearch we have a different kind of null-move, namely we can just stop
334365
# and not capture anything else.
@@ -472,6 +503,11 @@ def reduce(val):
472503
in_check = self.bound(flipped, MATE_UPPER, 0, root=False) == MATE_UPPER
473504
else:
474505
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+
475511
best = 0 if not in_check else -MATE_LOWER
476512

477513
# Table part 2

0 commit comments

Comments
 (0)