kiwipete perft position

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Re: kiwipete perft position

Post by Henk »

Hi hi hi my class ChessPiece still exists but only containing constants and static methods now.
Took three years to get there.

Can you imagine how many bugs and time I would have saved when I would have taken the right design decision from start.

So for beginners who do object oriented programming: Don't create a class or a structure for a piece.
User avatar
flok
Posts: 481
Joined: Tue Jul 03, 2018 10:19 am
Full name: Folkert van Heusden

Re: kiwipete perft position

Post by flok »

Henk wrote: Wed Oct 09, 2019 10:27 am Hi hi hi my class ChessPiece still exists but only containing constants and static methods now.
Took three years to get there.

Can you imagine how many bugs and time I would have saved when I would have taken the right design decision from start.

So for beginners who do object oriented programming: Don't create a class or a structure for a piece.
A beginner should use libchess instead (https://github.com/Mk-Chan/libchess). Takes away a lot of uninteresting hassle like movegen.
Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Re: kiwipete perft position

Post by Henk »

flok wrote: Wed Oct 09, 2019 11:25 am
Henk wrote: Wed Oct 09, 2019 10:27 am Hi hi hi my class ChessPiece still exists but only containing constants and static methods now.
Took three years to get there.

Can you imagine how many bugs and time I would have saved when I would have taken the right design decision from start.

So for beginners who do object oriented programming: Don't create a class or a structure for a piece.
A beginner should use libchess instead (https://github.com/Mk-Chan/libchess). Takes away a lot of uninteresting hassle like movegen.
That library uses a class for a piece as well. Looks like I am not the only lemming.
Joost Buijs
Posts: 1563
Joined: Thu Jul 16, 2009 10:47 am
Location: Almere, The Netherlands

Re: kiwipete perft position

Post by Joost Buijs »

Henk wrote: Wed Oct 09, 2019 11:42 am
flok wrote: Wed Oct 09, 2019 11:25 am
Henk wrote: Wed Oct 09, 2019 10:27 am Hi hi hi my class ChessPiece still exists but only containing constants and static methods now.
Took three years to get there.

Can you imagine how many bugs and time I would have saved when I would have taken the right design decision from start.

So for beginners who do object oriented programming: Don't create a class or a structure for a piece.
A beginner should use libchess instead (https://github.com/Mk-Chan/libchess). Takes away a lot of uninteresting hassle like movegen.
That library uses a class for a piece as well. Looks like I am not the only lemming.
As such there is nothing wrong in using a struct or class for a piece, only it doesn't seem to suit any purpose. In my engine a piece is just an integer constant, and it doesn't have any methods attached. The board as a whole uses a struct, methods that interact with pieces (like movement or placement) are declared in the board-struct.
Henk
Posts: 7216
Joined: Mon May 27, 2013 10:31 am

Re: kiwipete perft position

Post by Henk »

Joost Buijs wrote: Wed Oct 09, 2019 1:45 pm
Henk wrote: Wed Oct 09, 2019 11:42 am
flok wrote: Wed Oct 09, 2019 11:25 am
Henk wrote: Wed Oct 09, 2019 10:27 am Hi hi hi my class ChessPiece still exists but only containing constants and static methods now.
Took three years to get there.

Can you imagine how many bugs and time I would have saved when I would have taken the right design decision from start.

So for beginners who do object oriented programming: Don't create a class or a structure for a piece.
A beginner should use libchess instead (https://github.com/Mk-Chan/libchess). Takes away a lot of uninteresting hassle like movegen.
That library uses a class for a piece as well. Looks like I am not the only lemming.
As such there is nothing wrong in using a struct or class for a piece, only it doesn't seem to suit any purpose. In my engine a piece is just an integer constant, and it doesn't have any methods attached. The board as a whole uses a struct, methods that interact with pieces (like movement or placement) are declared in the board-struct.
Type, material points and name. Can't think of any other properties. Value of a piece depends on position.
Material points, name and color all dependent on type. So are redundant. No extra storage needed only type. Type represented by an integer or an ordinal typ. (Or a piece is just a bit on a bitboard). A switch is not a witch they told me.
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: kiwipete perft position

Post by Sven »

Right: a "piece type" and a "color" do not have a state. But it is possible to model pieces as objects with a piece type and color that are assigned to squares, so moving them means changing that assignment and is therefore a state change. Also pawn promotion would be a state change. A problem of this approach is that you need to access the piece-square association from both sides: you want to know the current square of a piece but also which piece (if any) is currently on a given square. And for that purpose the model using pieces as objects is not superior to the simple, classical approach using an array of integers that encode piece type and color and either some kind of piece list (mailbox) or some bitboards.

I never actually used the "piece object" approach in any serious engine. Jumbo does not use that sophisticated modelling as well. But in Jumbo it is still possible to create a "piece" object on the fly in certain cases.
Sven Schüle (engine author: Jumbo, KnockOut, Surprise)
User avatar
xr_a_y
Posts: 1871
Joined: Sat Nov 25, 2017 2:28 pm
Location: France

Re: kiwipete perft position

Post by xr_a_y »

flok wrote: Wed Oct 09, 2019 11:25 am
Henk wrote: Wed Oct 09, 2019 10:27 am Hi hi hi my class ChessPiece still exists but only containing constants and static methods now.
Took three years to get there.

Can you imagine how many bugs and time I would have saved when I would have taken the right design decision from start.

So for beginners who do object oriented programming: Don't create a class or a structure for a piece.
A beginner should use libchess instead (https://github.com/Mk-Chan/libchess). Takes away a lot of uninteresting hassle like movegen.
I have to disagree about the "uninteresting" adjective. Everything about chess programing is important and very interresting. I think that move generation is an important thing as it is linked with your board representation choices.

libchess is a good stuff anyway.
JohnWoe
Posts: 491
Joined: Sat Mar 02, 2013 11:31 pm

Re: kiwipete perft position

Post by JohnWoe »

Board presentation is the first choice when starting to write chess engine from scratch. How pieces are encoded. Some uses just INTs for moves. From/To/Castle is encoded in 4 bytes. If you can debug that thing perfectly it is fast. In Sapeli I use a 184 bytes board as a "move".
JohnWoe
Posts: 491
Joined: Sat Mar 02, 2013 11:31 pm

Re: Position with eleven rocks.

Post by JohnWoe »

Ajedrecista wrote: Mon Mar 30, 2015 8:27 pm Hello:
Henk wrote:Skipper gives castling rights depending on rook number. So the position below might give a problem. Skipper gives perft(4) = 265703

[d] rrrrkr1r/rr1rr3/8/8/8/8/8/6KR w k - 0 1

Code: Select all

rrrrkr1r/rr1rr3/8/8/8/8/8/6KR w k - 0 1

Results by JetChess 1.0.0.0:

perft(1) =                 8
perft(2) =               388
perft(3) =             4,827
perft(4) =           266,260
perft(5) =         2,955,677
perft(6) =       174,627,748
perft(7) =     1,941,335,854
perft(8) =   120,165,734,022
perft(9) = 1,335,631,917,716
I hope no typos. Good luck with your debug!

Regards from Spain.

Ajedrecista.
Sapeli 1.53 numbers up to depth 8. So these numbers are confirmed.

Code: Select all

sapeli -fen "rrrrkr1r/rr1rr3/8/8/8/8/8/6KR w k - 0 1" -perft 8
+-+ Perft( 8 ) +-+
depth 0 nodes 1 mnps 0.000 time 0.000
depth 1 nodes 8 mnps 0.000 time 0.000
depth 2 nodes 388 mnps 0.000 time 0.000
depth 3 nodes 4827 mnps 4.827 time 0.001
depth 4 nodes 266260 mnps 20.482 time 0.013
depth 5 nodes 2955677 mnps 20.669 time 0.143
depth 6 nodes 174627748 mnps 47.948 time 3.642
depth 7 nodes 1941335854 mnps 42.063 time 46.153
depth 8 nodes 120165734022 mnps 63.054 time 1905.773
= nodes 122284924785 mnps 62.527 time 1955.725
User avatar
hgm
Posts: 27787
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: kiwipete perft position

Post by hgm »

My programming style is very low-level, so I never do things like objects, and even structs are rare. Pieces are just represented by small integers, usually unsigned char. The 'properties' are then simply stored in arrays, indexed by the piece number. (I prefer that over grouping them in structs, where you would have to worry about padding because of various sizes.)

But there usually are many properties. Of course they have a location (square number) and a piece type. But to avoid an extra level of indirection I usually store the properties that are common to the piece type with each individual instance of the piece. That includes the piece value in evaluation (opening and end-game packed in one int), the piece value in SEE, a pointer to the piece-square table, a pointer to the Zobrist piece-square key, the Zobrist Pawn key, the contribution to the material key, the piece ID in FEN, the promotability flags or the piece number of the promoted instance, a pointer to the move-generator list, capture flags for 0x88-type capture tests, etc. Where 'pointer' can also be an index in an array rather than a full memory address.

The piece numbers are often chosen such that the type can be easily deduced from the number even without a memory access, e.g. reserve 8-15 for Pawns (so that you can test with nr&8 whether a given piece is a Pawn).