manyoso / allie

Allie: A UCI compliant chess engine
GNU General Public License v3.0
104 stars 21 forks source link

Proposal to add Transposition Difference Value: #12

Closed TesseractA closed 4 years ago

TesseractA commented 4 years ago

EDIT: I've revised this pseudo-code to make more slightly more sense. I realize the actual code will somewhat different (and maybe fewer lines), but the principles should be the same.

I made 2 functions allowing 50-move-rule transpositions in with NNCache;

function makeTD(board.plyPlayed(original_position))
    cutoff = 20 #tunable; also is a somewhat arbitrary number
    distance_factor = 8 #tunable; linearly increases the TD value.
    ply_until_100 = ply_played - 100
    if ply_until_100>cutoff: #prevents the log function being 0 or lower
        return TD=abs(int(distance_factor*log(ply_until_100-cutoff))) #This function does not have to be a log function, but it probably works better that way.
#Two numbers in this function are tunable. Notably, odd number outputs should be rounded to even numbers because transpositions do not happen with a difference of 1 in ply, as it is then the other side's turn.
#Another option is just to divide 100 by 2 beforehand and count moves instead of ply.

#NNCache search code
#invoked when comparing boards/FENs to see whether a new position was already searched or not
#first compare boards, then compare 50-MRs using TD
function comparePositions_withTD(original_position, new_position)
    if board.position(new_position) == board.position(original_position): #comparing old and new positions without 50MR
        TD=makeTD(board.plyPlayed(original_position))
        OP=board.plyPlayed(original_position) #original position's ply count
        NP=board.plyPlayed(original_position) #new position's ply count
        if OP+TD>NP and NP>OP-TD: #comparing 50MRs with bounds TD
            return True #means the search code treats the old position as if it were the new position
        else:
            return False #means the search code treats the old position as if it wasn't the original position
   else:
       continue

I only expect TD to fail in certain conditions, which I believe the distance of 10 moves from the 50MR as (x-10); x>10 accounts for. If functional errors are accounted for and TD fails, it is because: -X is small -Somehow, repetitions are encouraged and expands search unnecessarily on multiple fronts -Descending evaluations due to approaching the 50MR are delayed and hampered by a single visit -Evaluations don't descend enough and serve as an ineffective or proactive draw avoidance mechanism -Being practically useless? (Which I do not expect at all if implemented correctly) -Could need to be paired with a policy boosting/subtracting mechanism that increases/decreases priority to searching transpositions in NNcache (maybe causing a small but noticeable slowdown?) -could also need to be paired with an additional visit beyond the transposition (for worst-case 50MR faults) -conflicts with moves-left head when the moves-left head's prediction approaches -> 50MR only because the transposition is closer to the 50MR, therefore necessitating that transpositions should only be allowed as equal or less distance to root. -Extremely high depth searches requiring precise and stable evaluations may spike and increase expected time needed for moves during games -Multivariable tunes could be required, possibly including the function I've defined above

As for training: -training could not like it (for various unknown outerspace reasons) -positive feedback loops in training due to high Q insensitivity, wildly differing evaluations between places in the 50 MR, and preference to positions with/without transpositions could cause overfitting of some kind -everything needs retuning? (heavy rocks to be lifted?)

A possible remedy to the encouragement of high-depth related repetitions (which would unnecessarily allow for expansion of the search tree along already explored paths) would be to reconsider implementing 2-fold draw scoring, but perhaps only for already searched positions.

TesseractA commented 4 years ago

Closing as I seem to be at the whim of my procrastination.