Questions on Updating the Killer Moves Heuristic

Discussion of chess software programming and technical issues.

Moderator: Ras

StackFish5
Posts: 18
Joined: Fri Dec 24, 2021 5:48 pm
Full name: Andrew Zhuo

Questions on Updating the Killer Moves Heuristic

Post by StackFish5 »

I understand how the killer moves heuristic functions. But I do not know how to properly implement it in search. The main problem I'm having isn't scoring them but is how to update the heuristic during a beta-cutoff. Help would be greatly appreciated and so would some code examples on how to do so.

Thanks.
tcusr
Posts: 325
Joined: Tue Aug 31, 2021 10:32 pm
Full name: tcusr

Re: Questions on Updating the Killer Moves Heuristic

Post by tcusr »

StackFish5 wrote: Wed Sep 14, 2022 6:19 pm I understand how the killer moves heuristic functions. But I do not know how to properly implement it in search. The main problem I'm having isn't scoring them but is how to update the heuristic during a beta-cutoff. Help would be greatly appreciated and so would some code examples on how to do so.

Thanks.
update your table with the current move before returning beta.
User avatar
hgm
Posts: 28353
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Questions on Updating the Killer Moves Heuristic

Post by hgm »

If(move != killer1[ply]) { killer2[ply] = killer1[ply]; killer1[ply] = move; }
StackFish5
Posts: 18
Joined: Fri Dec 24, 2021 5:48 pm
Full name: Andrew Zhuo

Re: Questions on Updating the Killer Moves Heuristic

Post by StackFish5 »

hgm wrote: Wed Sep 14, 2022 8:09 pm If(move != killer1[ply]) { killer2[ply] = killer1[ply]; killer1[ply] = move; }
Killer1 would be scored higher compared to killer2 right?
User avatar
lithander
Posts: 915
Joined: Sun Dec 27, 2020 2:40 am
Location: Bremen, Germany
Full name: Thomas Jahn

Re: Questions on Updating the Killer Moves Heuristic

Post by lithander »

StackFish5 wrote: Thu Sep 15, 2022 12:42 am
hgm wrote: Wed Sep 14, 2022 8:09 pm If(move != killer1[ply]) { killer2[ply] = killer1[ply]; killer1[ply] = move; }
Killer1 would be scored higher compared to killer2 right?
Yes. You can also defer generating the quiet moves and just check the killers for legality and play them. Maybe you get a cutoff and save generating the quiet moves entirely. Then you will never have to score them for sorting
Minimal Chess (simple, open source, C#) - Youtube & Github
Leorik (competitive, in active development, C#) - Github & Lichess
StackFish5
Posts: 18
Joined: Fri Dec 24, 2021 5:48 pm
Full name: Andrew Zhuo

Re: Questions on Updating the Killer Moves Heuristic

Post by StackFish5 »

Thank you all for the advice on how to update the killer move heuristic. It really helped me a lot.
User avatar
j.t.
Posts: 263
Joined: Wed Jun 16, 2021 2:08 am
Location: Berlin
Full name: Jost Triller

Re: Questions on Updating the Killer Moves Heuristic

Post by j.t. »

I also have, additionally to the two traditional killermoves, a third killer move for each color that is valid through all heights (opposed to the normal killermoves which are only used/updated on their specific tree height).
User avatar
hgm
Posts: 28353
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Questions on Updating the Killer Moves Heuristic

Post by hgm »

How do you set that 3rd killer?
User avatar
j.t.
Posts: 263
Joined: Wed Jun 16, 2021 2:08 am
Location: Berlin
Full name: Jost Triller

Re: Questions on Updating the Killer Moves Heuristic

Post by j.t. »

hgm wrote: Mon Sep 19, 2022 9:07 pm How do you set that 3rd killer?
Basically always, whenever the normal killers are updated, too:

Code: Select all

struct KillerTable{
  Move table[MAX_PLY][2];
  Move goodMove[2];
  
  void update(Ply height, Move move){
    goodMove[height % 2] = move;
    if(table[height][0] != move){
      table[height][1] = table[height][0];
      table[height][0] = move;
    }    
  }
};
(real code)