MadChess 2.0 Development

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
emadsen
Posts: 434
Joined: Thu Apr 26, 2012 1:51 am
Location: Oak Park, IL, USA
Full name: Erik Madsen

MadChess 2.0 Development

Post by emadsen »

I've been writing a new version of MadChess. For this 2.0 version, I'm writing code using procedural techniques rather than the object-oriented techniques I used in MadChess 1.x. I've reached a milestone- legal move generation.

I'm happy with the performance of the code, which is 4x faster than MadChess 1.x. Details at http://www.madchess.net/post/procedural-code.
Image
My C# chess engine: https://www.madchess.net
Henk
Posts: 7218
Joined: Mon May 27, 2013 10:31 am

Re: MadChess 2.0 Development

Post by Henk »

I think that if I would use bit boards only, evaluation would be slower. I also have separate lists for whitePawns .. blackKing etc where each list contains chessPieces that have a location.

So speeding up move generation doesn't help if evaluation gets much slower, but I might be wrong for my engine is not fast (actually slow).
kinderchocolate
Posts: 454
Joined: Mon Nov 01, 2010 6:55 am
Full name: Ted Wong

Re: MadChess 2.0 Development

Post by kinderchocolate »

Henk wrote:I think that if I would use bit boards only, evaluation would be slower. I also have separate lists for whitePawns .. blackKing etc where each list contains chessPieces that have a location.

So speeding up move generation doesn't help if evaluation gets much slower, but I might be wrong for my engine is not fast (actually slow).
Thanks, Erik I'll follow your posts. Is there any reason that you don't want to switch to bitboard????

Henk, do you have any idea what you're talking about?
Henk
Posts: 7218
Joined: Mon May 27, 2013 10:31 am

Re: MadChess 2.0 Development

Post by Henk »

Henk wrote:I think that if I would use bit boards only, evaluation would be slower. I also have separate lists for whitePawns .. blackKing etc where each list contains chessPieces that have a location.

So speeding up move generation doesn't help if evaluation gets much slower, but I might be wrong for my engine is not fast (actually slow).
Maybe I might be wrong for evaluation is not executed for every move generated.
Henk
Posts: 7218
Joined: Mon May 27, 2013 10:31 am

Re: MadChess 2.0 Development

Post by Henk »

I thought Erik was using bit boards only. OK bye I'm out of this discussion, before making more mistakes and wrong assumptions.
User avatar
emadsen
Posts: 434
Joined: Thu Apr 26, 2012 1:51 am
Location: Oak Park, IL, USA
Full name: Erik Madsen

Re: MadChess 2.0 Development

Post by emadsen »

kinderchocolate wrote:Thanks, Erik I'll follow your posts. Is there any reason that you don't want to switch to bitboard????
I like the simplicity of an array of squares. But mostly I enjoy the process of slowing increasing the sophistication of the code, from the direct and intelligible to the arcane. I'm very methodical as you can see. Perhaps I'll use bitboards for version 3.
I thought Erik was using bit boards only. OK bye I'm out of this discussion, before making more mistakes and wrong assumptions.
Henk, I use bit shift operations to encode moves and castling rights. But the board is represented as an int[64].
My C# chess engine: https://www.madchess.net
matthewlai
Posts: 793
Joined: Sun Aug 03, 2014 4:48 am
Location: London, UK

Re: MadChess 2.0 Development

Post by matthewlai »

emadsen wrote:
kinderchocolate wrote:Thanks, Erik I'll follow your posts. Is there any reason that you don't want to switch to bitboard????
I like the simplicity of an array of squares. But mostly I enjoy the process of slowing increasing the sophistication of the code, from the direct and intelligible to the arcane. I'm very methodical as you can see. Perhaps I'll use bitboards for version 3.
I thought Erik was using bit boards only. OK bye I'm out of this discussion, before making more mistakes and wrong assumptions.
Henk, I use bit shift operations to encode moves and castling rights. But the board is represented as an int[64].
That's what abstractions are for, so you can isolate complexity to small parts of the code to make it fast, yet present a simple interface for the rest of the program.

One way to do that is OOP, but in higher level languages like C# or Java, OOP probably does come with a performance penalty. That's why most object-oriented performance-critical programs (including chess engines) are written in C++. It's not as "clean" as C# or Java, but it allows you to do a lot of OOP with minimal/no performance penalty.

For example, if you look at the Stockfish source code. You'll see how simple it is. Most of the high level code reads like pseudo-code. Yet it's obviously extremely fast.
Disclosure: I work for DeepMind on the AlphaZero project, but everything I say here is personal opinion and does not reflect the views of DeepMind / Alphabet.
User avatar
emadsen
Posts: 434
Joined: Thu Apr 26, 2012 1:51 am
Location: Oak Park, IL, USA
Full name: Erik Madsen

Re: MadChess 2.0 Development

Post by emadsen »

That's what abstractions are for, so you can isolate complexity to small parts of the code to make it fast, yet present a simple interface for the rest of the program.
Yes, I know. I live in that world every day. I wrote MadChess 1.x to answer the question, if I write a chess engine using the business OO style code I write at work, how strong will it be? The answer is 2200 ELO, and more likely 2400 against human opposition.
That's why most object-oriented performance-critical programs (including chess engines) are written in C++. It's not as "clean" as C# or Java, but it allows you to do a lot of OOP with minimal/no performance penalty.
I agree. The main performance penalty coming from runtime-managed memory / garbage collection versus developer-allocated / deallocated memory. Though, I thought most strong engines are written in plain C, not C++.
If you look at the Stockfish source code.
I'm not interested in reading the Stockfish source code, though I understand and respect those who do. MadChess is done purely for my own intellectual satisfaction, so I'm quite content to build it ignorant of the state of the art. I am happy to reinvent the wheel- in fact that's the whole point since writing a chess engine is pretty much a solved problem at this point. Of course, if this was a professional project, I'd read the Stockfish source and incorporate as much as possible into the project. The mental effort of devising my own solutions, while intellectually satisfying, would be a waste of time to my employer.
My C# chess engine: https://www.madchess.net
matthewlai
Posts: 793
Joined: Sun Aug 03, 2014 4:48 am
Location: London, UK

Re: MadChess 2.0 Development

Post by matthewlai »

emadsen wrote: Yes, I know. I live in that world every day. I wrote MadChess 1.x to answer the question, if I write a chess engine using the business OO style code I write at work, how strong will it be? The answer is 2200 ELO, and more likely 2400 against human opposition.

I agree. The main performance penalty coming from runtime-managed memory / garbage collection versus developer-allocated / deallocated memory. Though, I thought most strong engines are written in plain C, not C++.

I'm not interested in reading the Stockfish source code, though I understand and respect those who do. MadChess is done purely for my own intellectual satisfaction, so I'm quite content to build it ignorant of the state of the art. I am happy to reinvent the wheel- in fact that's the whole point since writing a chess engine is pretty much a solved problem at this point. Of course, if this was a professional project, I'd read the Stockfish source and incorporate as much as possible into the project. The mental effort of devising my own solutions, while intellectually satisfying, would be a waste of time to my employer.
Well, Stockfish is one example of a very strong chess engine written in C++ :).

Going through the CEGT list (http://www.husvankempen.de/nunn/40_4_Ra ... liste.html) and skipping closed source engines -
Stockfish - C++
Gull - C++
Critter - C++
Strelka - no idea
Protector - C
Senpai - C++

I believe most/all of the top few closed source engines are C++ as well.

A few switched from C to C++ at some point, Crafty being a notable exception.

I have a lot of respect for Stockfish's authors not just because they made the strongest engine in the world, but also because they did it in extremely clean and easily-readable OOP C++ code. I would have enjoyed reading Stockfish code even if I had little interest in chess. It's living proof that clean OO style and performance aren't always against each other.

Though I feel that can only be said about C++, because C++'s implementation of OOP is very light, and in most cases incur no performance penalty at all.

Crafty's code is also very clean for a C program... but that's for a C program. Stockfish is still much easier to read.

I do respect that you are trying to be ignorant of the state of the art, but would highly recommend reading it if one day you lose interest in chess (or in being ignorant of the state of the art) :).

I wouldn't say chess is a solved problem. There are still many unexplored promising approaches. They may or may not be stronger, but are definitely very interesting. I am exploring a very interesting approach at the moment as my MSc thesis, but I can't say much about it at the moment, so that's for another time. I am basing it on Stockfish so I can focus my efforts on the novel parts, and not have to spend time reinventing wheels.
Disclosure: I work for DeepMind on the AlphaZero project, but everything I say here is personal opinion and does not reflect the views of DeepMind / Alphabet.
User avatar
emadsen
Posts: 434
Joined: Thu Apr 26, 2012 1:51 am
Location: Oak Park, IL, USA
Full name: Erik Madsen

Re: MadChess 2.0 Development

Post by emadsen »

MadChess 2.0 can play a timed game of chess.

I've implemented an alpha / beta negamax search with aspiration windows and a capture / check evasion quiescence search. Evaluation is limited to material and middlegame piece square tables. No tapered evaluation, no passed pawn bonus, no piece mobility, no king safety, no reductions or pruning of moves, etc.

Rated about 1500 ELO.

Details at http://www.madchess.net/post/madchess-2-0-beta-build-20.
My C# chess engine: https://www.madchess.net