A laic's remark: when you yourself play chess you use move ordering as well, albeit subconsciously. You won't consider putting your queen en prise, for example.
MinimalChess 0.2 released
Moderator: Ras
-
- Posts: 1452
- Joined: Sat Jul 21, 2018 7:43 am
- Location: Budapest, Hungary
- Full name: Gabor Szots
Re: MinimalChess 0.2 released
Gabor Szots
CCRL testing group
CCRL testing group
-
- Posts: 915
- Joined: Sun Dec 27, 2020 2:40 am
- Location: Bremen, Germany
- Full name: Thomas Jahn
Re: MinimalChess 0.2 released
.Net is open source so you can just look at the implementation of List<T>.Clear() and find:
Code: Select all
// Clears the contents of List.
public void Clear() {
if (_size > 0)
{
Array.Clear(_items, 0, _size); // Don't need to doc this but we clear the elements so that the gc can reclaim the references.
_size = 0;
}
_version++;
}
The way I've explained it to myself is that MVV-LVA orders the moves by the likelihood of the move making significant changes to the evaluation providing a chance to narrow down the search window as early as possible. What I feel is arbitrary about it is that it is very specific to chess and the value of it's pieces and not as generic as other pruning techniques. But I'm programming a chess engine after all, right? So version 0.3 will include it.Gabor Szots wrote: ↑Wed Feb 24, 2021 1:32 pmA laic's remark: when you yourself play chess you use move ordering as well, albeit subconsciously. You won't consider putting your queen en prise, for example.

-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: MinimalChess 0.2 released
Yes, I forgot reference types since I was thinking in terms of a chess engine that would usually never use such a kind of highly dynamic container data structures at all ... If there were a container class designed for "plain" objects that do not contain references to other objects then this might be the better choice performance-wise than List<T>, right?lithander wrote: ↑Wed Feb 24, 2021 2:30 pm.Net is open source so you can just look at the implementation of List<T>.Clear() and find:
So the entire range of elements is set to their default value for value types and null for reference types!Code: Select all
// Clears the contents of List. public void Clear() { if (_size > 0) { Array.Clear(_items, 0, _size); // Don't need to doc this but we clear the elements so that the gc can reclaim the references. _size = 0; } _version++; }
Sven Schüle (engine author: Jumbo, KnockOut, Surprise)
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: MinimalChess 0.2 released
That is not the intention of MVV/LVA, its goal is to get a smaller search tree by removing the most aggressive enemy pieces from the board as early as possible. The width of the search window is not relevant there, it is about the effective branching factor.lithander wrote: ↑Wed Feb 24, 2021 2:30 pmThe way I've explained it to myself is that MVV-LVA orders the moves by the likelihood of the move making significant changes to the evaluation providing a chance to narrow down the search window as early as possible. What I feel is arbitrary about it is that it is very specific to chess and the value of it's pieces and not as generic as other pruning techniques. But I'm programming a chess engine after all, right? So version 0.3 will include it.Gabor Szots wrote: ↑Wed Feb 24, 2021 1:32 pmA laic's remark: when you yourself play chess you use move ordering as well, albeit subconsciously. You won't consider putting your queen en prise, for example.![]()
Sven Schüle (engine author: Jumbo, KnockOut, Surprise)
-
- Posts: 915
- Joined: Sun Dec 27, 2020 2:40 am
- Location: Bremen, Germany
- Full name: Thomas Jahn
Re: MinimalChess 0.2 released
I'm still learning the lingo. The search window I meant was the one between alpha and beta. The faster it converges the better is your effective branching factor. So alpha-beta with move ordering narrows the gap between alpha and beta faster than an alpha-beta search with unsorted moves and this reduces the branching factor and makes the searched tree smaller. Right?
All I'm saying is that the .Net runtime is quite fast and some long hold beliefs you may have borrowed from C/C++ like avoiding allocations are counter-productive in .Net.Sven wrote: ↑Wed Feb 24, 2021 2:42 pm Yes, I forgot reference types since I was thinking in terms of a chess engine that would usually never use such a kind of highly dynamic container data structures at all ... If there were a container class designed for "plain" objects that do not contain references to other objects then this might be the better choice performance-wise than List<T>, right?
I don't think you should micro-optimize C# like that. C# just puts another abstraction layer between you and the hardware. Make this layer your friend and don't try to outsmart it or get rid of it entirely. If you don't trust the runtime, the garbage collector and the JIT compiler then by all means stick with C/C++. (No offense meant!)
-
- Posts: 915
- Joined: Sun Dec 27, 2020 2:40 am
- Location: Bremen, Germany
- Full name: Thomas Jahn
Re: MinimalChess 0.2 released
Which I really considered by the way. But it's been so long ago that I worked with C++ that it would have been like trying to learn two new topics at once.
-
- Posts: 4052
- Joined: Thu May 15, 2008 9:57 pm
- Location: Berlin, Germany
- Full name: Sven Schüle
Re: MinimalChess 0.2 released
Almost right. But "narrowing the alpha/beta window" is not the key point of MVV/LVA. Instead it simply reduces the number of nodes to be searched by trying to obtain an early cutoff without leaving the enemy with a lot of possible captures you would have to examine. Therefore you try grabbing his queen, for instance, as early as possible whenever you can, even if that is "only" exchanging material instead of winning a pawn or a minor piece. It has been proven that this reduces tree size significantly in contrast to ordering based on the expected material gain. Even in a "human-like" search tree, refuting a bad move does not require the best refutation and can often be achieved with less effort by simply exchanging material and reducing the foreign forces.lithander wrote: ↑Wed Feb 24, 2021 3:06 pmI'm still learning the lingo. The search window I meant was the one between alpha and beta. The faster it converges the better is your effective branching factor. So alpha-beta with move ordering narrows the gap between alpha and beta faster than an alpha-beta search with unsorted moves and this reduces the branching factor and makes the searched tree smaller. Right?
Not using data structures that do "magic" allocation/deallocation or even garbage collection behind the curtains is no "micro-optimization" in my view, it is how I think writing a chess engine should be approached ... And regarding that additional abstraction layer, I really prefer taking my bike to go to the bakery instead of booking a flight for that purposelithander wrote: ↑Wed Feb 24, 2021 3:06 pmAll I'm saying is that the .Net runtime is quite fast and some long hold beliefs you may have borrowed from C/C++ like avoiding allocations are counter-productive in .Net.Sven wrote: ↑Wed Feb 24, 2021 2:42 pm Yes, I forgot reference types since I was thinking in terms of a chess engine that would usually never use such a kind of highly dynamic container data structures at all ... If there were a container class designed for "plain" objects that do not contain references to other objects then this might be the better choice performance-wise than List<T>, right?
I don't think you should micro-optimize C# like that. C# just puts another abstraction layer between you and the hardware. Make this layer your friend and don't try to outsmart it or get rid of it entirely. If you don't trust the runtime, the garbage collector and the JIT compiler then by all means stick with C/C++. (No offense meant!)

Sven Schüle (engine author: Jumbo, KnockOut, Surprise)
-
- Posts: 1784
- Joined: Wed Jul 03, 2019 4:42 pm
- Location: Netherlands
- Full name: Marcel Vanthoor
Re: MinimalChess 0.2 released
And that makes developing a chess engine slow, because I did exactly that: learning about chess programming and Rust at the same time. If had wanted to write the engine faster (but possibly not _better_), I would have written it in C; that's the programming language I know best. (I've been doing stuff around web development languages for some time now, but I think I can't ever forget the basics of C. I read C books as light reading as a teenager, before going to bed, in the 90's...)
Anything else but C, or would have needed to learn the language anyway. C++11, 17 or 20 would not have been easier to learn than Rust, let alone C# where most of the things I already know are basically either useless, or invalidated.
-
- Posts: 65
- Joined: Sat Oct 24, 2020 6:39 pm
- Full name: Taimo Peelo
Re: MinimalChess 0.2 released
IIRC EOF is not Ctrl+C on windows, but Ctrl+Z, if using simple pipe does not reproduce behaviour.
Ah, then this should naturally improve if instead 'forbidding' repetitions, they were to just be scored as 0 (draw).lithander wrote: ↑Wed Feb 24, 2021 12:29 pm ... So I forbade it to repeat positions that had been previously encountered. So when MMC or it's opponent fails to convert an endgame and the history gets longer and longer after a while MMC will starts to blunder because all good moves would lead into the repetition of a previous position.
Monchester 1.0, chess engine playing at scholastic level: https://github.com/unserializable/monchester ("Daddy, it is gonna take your horsie!")
Tickle Monchester at: https://lichess.org/@/monchester
Tickle Monchester at: https://lichess.org/@/monchester