New engine: Peacekeeper

Discussion of chess software programming and technical issues.

Moderator: Ras

User avatar
hgm
Posts: 28354
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: New engine: Peacekeeper

Post by hgm »

If you keep track not only of total mobility, but the mobility of each piece separately, then it is very easy to correct the total for this contribution when the piece gets moved or captured. You then would have to calculate the mobility of the moved piece in its new location.

In addition you would have to account for blocking and discovering of slider moves by the moved piece. The blocking is less of a concern, as it only happens on moves to empty squares, which make up only about 5% of the tree. So it is mainly about discovering of slider moves that would modify the mobility of those sliders (and of course the total).
Sazgr
Posts: 66
Joined: Thu Dec 09, 2021 8:26 pm
Full name: Kyle Zhang

Re: New engine: Peacekeeper

Post by Sazgr »

hgm wrote: Mon Jan 23, 2023 6:24 pm If you keep track not only of total mobility, but the mobility of each piece separately, then it is very easy to correct the total for this contribution when the piece gets moved or captured. You then would have to calculate the mobility of the moved piece in its new location.

In addition you would have to account for blocking and discovering of slider moves by the moved piece. The blocking is less of a concern, as it only happens on moves to empty squares, which make up only about 5% of the tree. So it is mainly about discovering of slider moves that would modify the mobility of those sliders (and of course the total).
The blocking may be less of a concern because normal piece moves would not affect any other mobility, as pieces are not counted as blockers in the first place. I think the only times in which I will have to recompute the total or do more expensive computation is moves or captures of a pawn. I do not know if that is less, maybe about the same.
Sazgr
Posts: 66
Joined: Thu Dec 09, 2021 8:26 pm
Full name: Kyle Zhang

Re: New engine: Peacekeeper

Post by Sazgr »

The queen blunder I saw earlier was not unique... After looking at played CCRL 40/15 games

Qxh2+??



Qh7+??


Nc6??



Even though my engine is not that good, I cannot see how it would fail to see those simple one-move blunders. Since opening it up from scratch gives different results, maybe it is the TT problem's fault. The blunders are not even that rare, and it loses terribly stupidly sometimes.
User avatar
Ras
Posts: 2696
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: New engine: Peacekeeper

Post by Ras »

Sazgr wrote: Mon Feb 06, 2023 6:08 pmEven though my engine is not that good, I cannot see how it would fail to see those simple one-move blunders.
Maybe it's the stalemate detection in main search: if all moves get pruned, the move counter stays 0, and without being in check, that's misclassified as stalemate. The solution is to only score stalemate if also the legal-but-pruned move counter is 0.
Rasmus Althoff
https://www.ct800.net
User avatar
lithander
Posts: 915
Joined: Sun Dec 27, 2020 2:40 am
Location: Bremen, Germany
Full name: Thomas Jahn

Re: New engine: Peacekeeper

Post by lithander »

Sazgr wrote: Mon Feb 06, 2023 6:08 pm Even though my engine is not that good, I cannot see how it would fail to see those simple one-move blunders. Since opening it up from scratch gives different results, maybe it is the TT problem's fault. The blunders are not even that rare, and it loses terribly stupidly sometimes.
Sometimes the sequence of moves leading to the position matters when reproducing a bug. E.g. for the first position what the engine get's from the GUI is actually:

position startpos moves e2e4 c7c5 g1f3 e7e6 d2d4 c5d4 f3d4 g8f6 b1c3 b8c6 d4b5 d7d6 c1f4 e6e5 f4g5 a7a6 b5a3 f8e7 g5f6 e7f6 c3d5 b7b5 c2c4 b5b4 a3c2 a8b8 d5f6 d8f6 f1e2 e8g8 e1g1 f8d8 b2b3 f6f4 a2a3 c6d4 c2d4

But if Peacekeeper still replies with the right move e5d4 I'd also take a closer look at your TT implementation.
Minimal Chess (simple, open source, C#) - Youtube & Github
Leorik (competitive, in active development, C#) - Github & Lichess
Sazgr
Posts: 66
Joined: Thu Dec 09, 2021 8:26 pm
Full name: Kyle Zhang

Re: New engine: Peacekeeper

Post by Sazgr »

lithander wrote: Tue Feb 07, 2023 12:18 am
Sazgr wrote: Mon Feb 06, 2023 6:08 pm Even though my engine is not that good, I cannot see how it would fail to see those simple one-move blunders. Since opening it up from scratch gives different results, maybe it is the TT problem's fault. The blunders are not even that rare, and it loses terribly stupidly sometimes.
Sometimes the sequence of moves leading to the position matters when reproducing a bug. E.g. for the first position what the engine get's from the GUI is actually:

position startpos moves e2e4 c7c5 g1f3 e7e6 d2d4 c5d4 f3d4 g8f6 b1c3 b8c6 d4b5 d7d6 c1f4 e6e5 f4g5 a7a6 b5a3 f8e7 g5f6 e7f6 c3d5 b7b5 c2c4 b5b4 a3c2 a8b8 d5f6 d8f6 f1e2 e8g8 e1g1 f8d8 b2b3 f6f4 a2a3 c6d4 c2d4

But if Peacekeeper still replies with the right move e5d4 I'd also take a closer look at your TT implementation.
Yes the bugs have never been replicated when starting a new instance of the engine.

But I found the bug essentially!

In an effort to replicate the stupid blunders, I looked at my TT code, and nothing seemed wrong. So I ran a hundred games against MinimalChess (chosen as a trusty, pretty normal engine) at 5+0.05 with 64mb hash. Peacekeeper beat MinimalChess pretty convincingly, by +80 elo or so. But then I ran another match with 1mb hash for each engine instead, it lost by 90 elo, and when I looked at some of the short games, there were queen blunders. And I looked closer at the pgns too, and saw that Peacekeeper thought that the blunders were Mate in 1! Obviously they weren't, but looking back on the games and my code, the checked side had only one response (namely to capture the queen). Because I always search at least one move in every node (ruling out something like Ras said), I was puzzled at the checkmate detection. And then I saw this

Code: Select all

if (movelist[i] == entry.bestmove) continue; //continuing if we already searched the hash move
which has less conditions than the part of staged move generation which searches the hash move

Code: Select all

if (entry.type != tt_none && entry.full_hash == position.hashkey() && entry.bestmove.not_null() && position.board[entry.bestmove.start()] == entry.bestmove.piece() && position.board[entry.bestmove.end()] == entry.bestmove.captured()) {//searching best move from hashtable
        position.make_move(entry.bestmove);
so apparently the only check evasion was not searched because it was the same as the best move in (a possibly completely different) TT entry. I am very dumb sometimes.

So I fixed that and ran a selfplay test with 1mb hash still, and my engine lost 20 elo!! :cry: I do not understand why pruning random moves can gain 20 elo, but I am inclined to fix the bug anyways for correctness' sake.
Sazgr
Posts: 66
Joined: Thu Dec 09, 2021 8:26 pm
Full name: Kyle Zhang

Re: New engine: Peacekeeper

Post by Sazgr »

New stupid thing that seems to gain elo.

Yesterday I tried putting the first generated move (after sorting) into the TT entry in a cut-node instead of leaving the entry blank (i.e. inserting a null move as the bestmove). I think maybe I saw this somewhere in talkchess, but I'm not sure where it was, and not sure if I even saw it instead of my brain creating illusions.

Anyway, after some games, it seems to be testing pretty well compared to all the common-sense features that I've tried (pawn structure, mobility, killers)

Code: Select all

   # PLAYER              : RATING  ERROR   POINTS  PLAYED    (%)
   1 peacekeeper-more    :   47.2   21.7    283.5     500   56.7%
   2 peacekeeper-less    :    0.0   ----    216.5     500   43.3%
Does anyone also do this or know whether it is a valid thing to do? Thanks a lot for everybody who answers this and all of my previous dumb questions.
lingfors
Posts: 4
Joined: Sun Feb 05, 2023 7:31 pm
Full name: Anders Lingfors

Re: New engine: Peacekeeper

Post by lingfors »

Sazgr wrote: Tue Feb 14, 2023 5:52 pm New stupid thing that seems to gain elo.

Yesterday I tried putting the first generated move (after sorting) into the TT entry in a cut-node instead of leaving the entry blank (i.e. inserting a null move as the bestmove). I think maybe I saw this somewhere in talkchess, but I'm not sure where it was, and not sure if I even saw it instead of my brain creating illusions.

Anyway, after some games, it seems to be testing pretty well compared to all the common-sense features that I've tried (pawn structure, mobility, killers)

Code: Select all

   # PLAYER              : RATING  ERROR   POINTS  PLAYED    (%)
   1 peacekeeper-more    :   47.2   21.7    283.5     500   56.7%
   2 peacekeeper-less    :    0.0   ----    216.5     500   43.3%
Does anyone also do this or know whether it is a valid thing to do? Thanks a lot for everybody who answers this and all of my previous dumb questions.
I do it in my engine as well. The move was the best one found in the position, and it was good enough to cause a cut-off. Sounds like a good idea to keep around and try first in case we come back to the same position again on a deeper depth.
Sazgr
Posts: 66
Joined: Thu Dec 09, 2021 8:26 pm
Full name: Kyle Zhang

Re: New engine: Peacekeeper

Post by Sazgr »

lingfors wrote: Tue Feb 14, 2023 6:45 pm
Sazgr wrote: Tue Feb 14, 2023 5:52 pm New stupid thing that seems to gain elo.

Yesterday I tried putting the first generated move (after sorting) into the TT entry in a cut-node (SHOULD BE ALL-NODE :oops: :oops: :oops: ) instead of leaving the entry blank (i.e. inserting a null move as the bestmove). I think maybe I saw this somewhere in talkchess, but I'm not sure where it was, and not sure if I even saw it instead of my brain creating illusions.

Anyway, after some games, it seems to be testing pretty well compared to all the common-sense features that I've tried (pawn structure, mobility, killers)

Code: Select all

   # PLAYER              : RATING  ERROR   POINTS  PLAYED    (%)
   1 peacekeeper-more    :   47.2   21.7    283.5     500   56.7%
   2 peacekeeper-less    :    0.0   ----    216.5     500   43.3%
Does anyone also do this or know whether it is a valid thing to do? Thanks a lot for everybody who answers this and all of my previous dumb questions.
I do it in my engine as well. The move was the best one found in the position, and it was good enough to cause a cut-off. Sounds like a good idea to keep around and try first in case we come back to the same position again on a deeper depth.
I just realized the "cut-node" was a typing mistake and should actually be all-node. Sorry for that misunderstanding, it happens often with me. :oops:
lingfors
Posts: 4
Joined: Sun Feb 05, 2023 7:31 pm
Full name: Anders Lingfors

Re: New engine: Peacekeeper

Post by lingfors »

It's okay, I mix upp the terms as well. ^^

For an all-node, i.e. fail-low node, you have no clue which move is the best one, all you know is that no move managed to exceed alpha (the lower bound), so what are you even accomplishing by saving any move in the TT?

But in the end, the only thing that matters is if a code change increase the playing strength or not. And the only way to find that out is to let the new version play against the old version for a few (hundred) games.