A Crossroad in Computer Chess; Or Desperate Flailing for Relevance

Discussion of anything and everything relating to chess playing software and machines.

Moderators: hgm, Rebel, chrisw

Wilson
Posts: 81
Joined: Tue Oct 29, 2019 3:20 am
Full name: Anthony Wilson

Re: A Crossroad in Computer Chess; Or Desperate Flailing for Relevance

Post by Wilson »

AndrewGrant wrote: Wed Sep 30, 2020 7:36 pm I stopped reading after that. Go take a look at Ethereal.
Too bad. You would know I have done my homeworks before posting.
I missed that page however I don't understand why Stockfish is not mentioned in the main Github page of Ethereal.

Anyway, I read in the wiki:
If you see something in Ethereal that you believe should be listed here, contact me
Let me help you complete it then, I have a long list.

N.1: Evaluation of pawn shelter/storm. Anyone can see it's pretty much the same as Stockfish's one.

Ethereal:

Code: Select all

    // Evaluate King Shelter & King Storm threat by looking at the file of our King,
    // as well as the adjacent files. When looking at pawn distances, we will use a
    // distance of 7 to denote a missing pawn, since distance 7 is not possible otherwise.
    for (int file = MAX(0, fileOf(kingSq) - 1); file <= MIN(FILE_NB - 1, fileOf(kingSq) + 1); file++) {

        // Find closest friendly pawn at or above our King on a given file
        uint64_t ours = myPawns & Files[file] & forwardRanksMasks(US, rankOf(kingSq));
        int ourDist = !ours ? 7 : abs(rankOf(kingSq) - rankOf(backmost(US, ours)));

        // Find closest enemy pawn at or above our King on a given file
        uint64_t theirs = enemyPawns & Files[file] & forwardRanksMasks(US, rankOf(kingSq));
        int theirDist = !theirs ? 7 : abs(rankOf(kingSq) - rankOf(backmost(US, theirs)));

        // Evaluate King Shelter using pawn distance. Use separate evaluation
        // depending on the file, and if we are looking at the King's file
        ei->pkeval[US] += KingShelter[file == fileOf(kingSq)][file][ourDist];
        if (TRACE) T.KingShelter[file == fileOf(kingSq)][file][ourDist][US]++;

        // Evaluate King Storm using enemy pawn distance. Use a separate evaluation
        // depending on the file, and if the opponent's pawn is blocked by our own
        blocked = (ourDist != 7 && (ourDist == theirDist - 1));
        ei->pkeval[US] += KingStorm[blocked][mirrorFile(file)][theirDist];
        if (TRACE) T.KingStorm[blocked][mirrorFile(file)][theirDist][US]++;
    }
Stockfish:

Code: Select all

/// Entry::evaluate_shelter() calculates the shelter bonus and the storm
/// penalty for a king, looking at the king file and the two closest files.

template<Color Us>
Score Entry::evaluate_shelter(const Position& pos, Square ksq) const {

  constexpr Color Them = ~Us;

  Bitboard b = pos.pieces(PAWN) & ~forward_ranks_bb(Them, ksq);
  Bitboard ourPawns = b & pos.pieces(Us) & ~pawnAttacks[Them];
  Bitboard theirPawns = b & pos.pieces(Them);

  Score bonus = make_score(5, 5);

  File center = std::clamp(file_of(ksq), FILE_B, FILE_G);
  for (File f = File(center - 1); f <= File(center + 1); ++f)
  {
      b = ourPawns & file_bb(f);
      int ourRank = b ? relative_rank(Us, frontmost_sq(Them, b)) : 0;

      b = theirPawns & file_bb(f);
      int theirRank = b ? relative_rank(Us, frontmost_sq(Them, b)) : 0;

      int d = edge_distance(f);
      bonus += make_score(ShelterStrength[d][ourRank], 0);

      if (ourRank && (ourRank == theirRank - 1))
          bonus -= BlockedStorm[theirRank];
      else
          bonus -= make_score(UnblockedStorm[d][theirRank], 0);
  }

  return bonus;
}
After you update the page we can go on.
Tony P.
Posts: 216
Joined: Sun Jan 22, 2017 8:30 pm
Location: Russia

Re: A Crossroad in Computer Chess; Or Desperate Flailing for Relevance

Post by Tony P. »

AndrewGrant wrote: Tue Sep 29, 2020 9:33 am I released a tuning paper a few months ago. It was the culmination of a years effort on various implementations, as well as likely over a hundred different methodologies for building datasets. I shared that paper, and I shared pieces of the Ethereal data, about 10 million positions at a time, to all those who asked. I think, two years ago, this would have made a splash. In fact, I still believe that someone could perform the same exercise as I outline, and gain +15 elo or more to Stockfish's static evaluation (pre-NNUE). But now my work is futile?
Upon a look at the paper, I feel sorry for you. Some newcomers will delegate the tuning job to automatic differentiation libraries and still manage to beat Ethereal by NNs. Surprisingly, autodiff does seem to give correct results for most of the non-differentiable functions used in ML. The preprint is recent, pending peer review. You were just unlucky to spend effort on deriving the gradient formulas manually at the time when the abuse of autodiff had no mathematical validation.
AndrewGrant
Posts: 1750
Joined: Tue Apr 19, 2016 6:08 am
Location: U.S.A
Full name: Andrew Grant

Re: A Crossroad in Computer Chess; Or Desperate Flailing for Relevance

Post by AndrewGrant »

Tony P. wrote: Wed Sep 30, 2020 9:04 pm
AndrewGrant wrote: Tue Sep 29, 2020 9:33 am I released a tuning paper a few months ago. It was the culmination of a years effort on various implementations, as well as likely over a hundred different methodologies for building datasets. I shared that paper, and I shared pieces of the Ethereal data, about 10 million positions at a time, to all those who asked. I think, two years ago, this would have made a splash. In fact, I still believe that someone could perform the same exercise as I outline, and gain +15 elo or more to Stockfish's static evaluation (pre-NNUE). But now my work is futile?
Upon a look at the paper, I feel sorry for you. Some newcomers will delegate the tuning job to automatic differentiation libraries and still manage to beat Ethereal by NNs. Surprisingly, autodiff does seem to give correct results for most of the non-differentiable functions used in ML. The preprint is recent, pending peer review. You were just unlucky to spend effort on deriving the gradient formulas manually at the time when the abuse of autodiff had no mathematical validation.
Well I'm still happy with it. I can run a few thousand epochs an hour on 45 million positions.

You don't get that speed with anything more abstract.
#WeAreAllDraude #JusticeForDraude #RememberDraude #LeptirBigUltra
"Those who can't do, clone instead" - Eduard ( A real life friend, not this forum's Eduard )
AndrewGrant
Posts: 1750
Joined: Tue Apr 19, 2016 6:08 am
Location: U.S.A
Full name: Andrew Grant

Re: A Crossroad in Computer Chess; Or Desperate Flailing for Relevance

Post by AndrewGrant »

Wilson wrote: Wed Sep 30, 2020 8:05 pm
AndrewGrant wrote: Wed Sep 30, 2020 7:36 pm I stopped reading after that. Go take a look at Ethereal.
Too bad. You would know I have done my homeworks before posting.
I missed that page however I don't understand why Stockfish is not mentioned in the main Github page of Ethereal.

Anyway, I read in the wiki:
If you see something in Ethereal that you believe should be listed here, contact me
Let me help you complete it then, I have a long list.

N.1: Evaluation of pawn shelter/storm. Anyone can see it's pretty much the same as Stockfish's one.

Ethereal:

Code: Select all

    // Evaluate King Shelter & King Storm threat by looking at the file of our King,
    // as well as the adjacent files. When looking at pawn distances, we will use a
    // distance of 7 to denote a missing pawn, since distance 7 is not possible otherwise.
    for (int file = MAX(0, fileOf(kingSq) - 1); file <= MIN(FILE_NB - 1, fileOf(kingSq) + 1); file++) {

        // Find closest friendly pawn at or above our King on a given file
        uint64_t ours = myPawns & Files[file] & forwardRanksMasks(US, rankOf(kingSq));
        int ourDist = !ours ? 7 : abs(rankOf(kingSq) - rankOf(backmost(US, ours)));

        // Find closest enemy pawn at or above our King on a given file
        uint64_t theirs = enemyPawns & Files[file] & forwardRanksMasks(US, rankOf(kingSq));
        int theirDist = !theirs ? 7 : abs(rankOf(kingSq) - rankOf(backmost(US, theirs)));

        // Evaluate King Shelter using pawn distance. Use separate evaluation
        // depending on the file, and if we are looking at the King's file
        ei->pkeval[US] += KingShelter[file == fileOf(kingSq)][file][ourDist];
        if (TRACE) T.KingShelter[file == fileOf(kingSq)][file][ourDist][US]++;

        // Evaluate King Storm using enemy pawn distance. Use a separate evaluation
        // depending on the file, and if the opponent's pawn is blocked by our own
        blocked = (ourDist != 7 && (ourDist == theirDist - 1));
        ei->pkeval[US] += KingStorm[blocked][mirrorFile(file)][theirDist];
        if (TRACE) T.KingStorm[blocked][mirrorFile(file)][theirDist][US]++;
    }
Stockfish:

Code: Select all

/// Entry::evaluate_shelter() calculates the shelter bonus and the storm
/// penalty for a king, looking at the king file and the two closest files.

template<Color Us>
Score Entry::evaluate_shelter(const Position& pos, Square ksq) const {

  constexpr Color Them = ~Us;

  Bitboard b = pos.pieces(PAWN) & ~forward_ranks_bb(Them, ksq);
  Bitboard ourPawns = b & pos.pieces(Us) & ~pawnAttacks[Them];
  Bitboard theirPawns = b & pos.pieces(Them);

  Score bonus = make_score(5, 5);

  File center = std::clamp(file_of(ksq), FILE_B, FILE_G);
  for (File f = File(center - 1); f <= File(center + 1); ++f)
  {
      b = ourPawns & file_bb(f);
      int ourRank = b ? relative_rank(Us, frontmost_sq(Them, b)) : 0;

      b = theirPawns & file_bb(f);
      int theirRank = b ? relative_rank(Us, frontmost_sq(Them, b)) : 0;

      int d = edge_distance(f);
      bonus += make_score(ShelterStrength[d][ourRank], 0);

      if (ourRank && (ourRank == theirRank - 1))
          bonus -= BlockedStorm[theirRank];
      else
          bonus -= make_score(UnblockedStorm[d][theirRank], 0);
  }

  return bonus;
}
After you update the page we can go on.
Responding to this only in the correct thread : http://talkchess.com/forum3/viewtopic.p ... 17#p863417
#WeAreAllDraude #JusticeForDraude #RememberDraude #LeptirBigUltra
"Those who can't do, clone instead" - Eduard ( A real life friend, not this forum's Eduard )
gladius
Posts: 568
Joined: Tue Dec 12, 2006 10:10 am
Full name: Gary Linscott

Re: A Crossroad in Computer Chess; Or Desperate Flailing for Relevance

Post by gladius »

AndrewGrant wrote: Tue Sep 29, 2020 9:33 am I could be all wrong. I could be out of touch. But if I'm not, then the future of computer chess, the future of unique and diverse engines, depends upon all of us, as individuals, to encourage and promote new ideas while discouraging those who take from Stockfish without trying their hand at the problem. I'm already concerned when I see engines with Stockfish nets being placed onto rating lists.
There are many motivations for being involved in computer chess. IMO, most do it for the enjoyment. Very few engines hit the level where cloning even starts to be a consideration.

If your desire is to be the top engine, there needs to be something fundamentally new. The leading engines have all had something fundamentally different in their approach. Fruit demonstrating the importance of search over eval, Rybka showing blitz testing of patches applied at scale generates a linear increase in ELO, and Stockfish flipping what was previously a huge disadvantage (open-source) into a key advantage through distributed testing. AlphaZero (and now LCZero) was a fundamentally new approach to the game of chess, and still has a lot of headroom to grow.

NNUE is a continuation of the trend - it's a fundamental advance. It just so happens that it was implemented in SF first (although really it was done by the Shogi folks). I don't think it's specific to SF, and as you say, the idea is simple enough it's not too hard to rebuild from scratch. There might be other competing ideas that can replace it, but NNs have proven to be tough to unseat once they've taken the lead. From now on, it's going to be much easier to build an incredibly strong eval, even without directly taking one of SF nets. It's just part of the toolkit now, and it can't be avoided if strength is a focus.
MikeGL
Posts: 1010
Joined: Thu Sep 01, 2011 2:49 pm

Re: A Crossroad in Computer Chess; Or Desperate Flailing for Relevance

Post by MikeGL »

gladius wrote: Thu Oct 01, 2020 1:24 am
AndrewGrant wrote: Tue Sep 29, 2020 9:33 am I could be all wrong. I could be out of touch. But if I'm not, then the future of computer chess, the future of unique and diverse engines, depends upon all of us, as individuals, to encourage and promote new ideas while discouraging those who take from Stockfish without trying their hand at the problem. I'm already concerned when I see engines with Stockfish nets being placed onto rating lists.
~
~
Fruit demonstrating the importance of search over eval, Rybka showing blitz testing of patches applied at scale generates a linear increase in ELO, and Stockfish flipping what was previously a huge disadvantage (open-source) into a key advantage through distributed testing. AlphaZero (and now LCZero) was a fundamentally new approach to the game of chess, and still has a lot of headroom to grow.
~
~
You've got an excellent point. Innovation is the key to be on top of the list.

Prior to the advent of NNs and ML, who would've thought of the idea that a computer can defeat humans in handcrafted eval terms.
That's impossible you say, nobody can defeat deep understanding of humans when it comes to specific Eval Terms and
humans handcrafted eval func will be always stronger. NOT ANYMORE!

Now NNs proved this haughty stance of humans TO BE WRONG already. Wait when ML /NNs also defeats the best F1 drivers on the planet. But that's quite impossible, one might claim. Humans will always be a better driver than machines. But this haughty stance of humans will fail in the future too. Machine learning is here for good and better embrace it or be extinguished, as posted by Ronald above about the demise of Kodak, Nokia and RIM because those companies didn't adjust with the times.

Now enough of the Eval Function.
Just imagine if NN goes on and replaces the handcrafted Search Function of Chess engines. That's impossible one might claim, handcrafted Search Techniques by humans will always be stronger.
I told my wife that a husband is like a fine wine; he gets better with age. The next day, she locked me in the cellar.
Daniel Shawul
Posts: 4185
Joined: Tue Mar 14, 2006 11:34 am
Location: Ethiopia

Re: A Crossroad in Computer Chess; Or Desperate Flailing for Relevance

Post by Daniel Shawul »

MikeGL wrote: Thu Oct 01, 2020 1:45 am Now enough of the Eval Function.
Just imagine if NN goes on and replaces the handcrafted Search Function of Chess engines. That's impossible one might claim, handcrafted Search Techniques by humans will always be stronger.
That is what A0's MCTS basically did.
It is still astounding to me a search that has been designed and tuned over decades was replaced
by a generic search method that essentially has one formula to tune, namely, UCB selection of moves to search deeper.

Classic AB search on the other hand, have a bunch of methods each with a paper dedicated to it
a) minmax to alpha-beta
b) PVS and aspiration search
c) Null move pruning
d) futility pruning and razoring
d) Late move reduction
e) Probcut
etc...

MCTS just replaced all these methods. Even if it turned out to be say 200 elo weaker than the Stockfish search, it was able to counter with a better NN eval. Anyone working on general AI would take MCTS any day and that is why domain-specific methods (while they may turn out to be stronger eventually) would never amount to the MCTS + NN combo.

Here is an interesting look at MCTS as a neural network
https://www.davidsilver.uk/wp-content/u ... ctsnet.pdf
MikeGL
Posts: 1010
Joined: Thu Sep 01, 2011 2:49 pm

Re: A Crossroad in Computer Chess; Or Desperate Flailing for Relevance

Post by MikeGL »

Daniel Shawul wrote: Thu Oct 01, 2020 1:57 am
MikeGL wrote: Thu Oct 01, 2020 1:45 am Now enough of the Eval Function.
Just imagine if NN goes on and replaces the handcrafted Search Function of Chess engines. That's impossible one might claim, handcrafted Search Techniques by humans will always be stronger.
That is what A0's MCTS basically did.
It is still astounding to me a search that has been designed and tuned over decades was replaced
by a generic search method that essentially has one formula to tune, namely, UCB selection of moves to search deeper.

Classic AB search on the other hand, have a bunch of methods each with a paper dedicated to it
a) minmax to alpha-beta
b) PVS and aspiration search
c) Null move pruning
d) futility pruning and razoring
d) Late move reduction
e) Probcut
etc...

MCTS just replaced all these methods. Even if it turned out to be say 200 elo weaker than the Stockfish search, it was able to counter with a better NN eval. Anyone working on general AI would take MCTS any day and that is why domain-specific methods (while they may turn out to be stronger eventually) would never amount to the MCTS + NN combo.

Here is an interesting look at MCTS as a neural network
https://www.davidsilver.uk/wp-content/u ... ctsnet.pdf
Last July 2017, while replying to Lyudmil, I also posted a similar topic about Monte Carlo with wiki link,
that's 5 months before SF-AlphaZero match. http://talkchess.com/forum3/viewtopic.p ... 70#p724929

In my above post, I was referring to improvement in A-B search using NN. There will also be a huge jump in strength once AB search is refined.
Classic AB search on the other hand, have a bunch of methods each with a paper dedicated to it
a) minmax to alpha-beta
b) PVS and aspiration search
c) Null move pruning
d) futility pruning and razoring
d) Late move reduction
e) Probcut
etc...
As an analogy, there are a bunch of papers and volumes of books too written about evaluation, like
a) Piece Placement
b) Rook endgame Technique
c) Pawn blockade
etc...

edit: sorry not 6 yrs, only 5 months. July 2017
I told my wife that a husband is like a fine wine; he gets better with age. The next day, she locked me in the cellar.
Dann Corbit
Posts: 12537
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: A Crossroad in Computer Chess; Or Desperate Flailing for Relevance

Post by Dann Corbit »

Matthew Lai talked about using the NN to power the search in his original paper.
MC searching is simpler, but I think part of the reason SF is stronger than LC0 is the combination of NN eval with alpha-beta search.
As further evidence, the MCTS Komodo is not as strong as the AB Komodo.
But I expect that MCTS can have the same sort of improvement phases as AB.
Taking ideas is not a vice, it is a virtue. We have another word for this. It is called learning.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.
smatovic
Posts: 2639
Joined: Wed Mar 10, 2010 10:18 pm
Location: Hamburg, Germany
Full name: Srdja Matovic

Re: A Crossroad in Computer Chess; Or Desperate Flailing for Relevance

Post by smatovic »

Dann Corbit wrote: Thu Oct 01, 2020 6:05 am Matthew Lai talked about using the NN to power the search in his original paper.
MC searching is simpler, but I think part of the reason SF is stronger than LC0 is the combination of NN eval with alpha-beta search.
As further evidence, the MCTS Komodo is not as strong as the AB Komodo.
But I expect that MCTS can have the same sort of improvement phases as AB.
Yea, maybe we will see a kind of merger, there are different approaches to
combine a Best-First with Depth-First search, like Best-First-MiniMax, MCAB,
or the Rolllout Paradigm and alike.

--
Srdja