How to determine the square mapping based on bitboards?

Programming Topics (Computer Chess) and technical aspects as test techniques, book building, program tuning etc

Moderator: Andres Valverde

How to determine the square mapping based on bitboards?

Postby gpapas123 » 27 Mar 2023, 13:31

Hello chess fanatics!
I downloaded a c++ code that calculates magic bitboards for bishop and rook.
The output is as follows:

Code: Select all
Const U64 RMagic[64]= {
0x0C80001828100040,0x0026004408400010,0x1060040000202048,0x0110141100800888,0x084420501A000802,0x1803002905002224,0x0104380106000182,0x0000208201001041,
0x4080118100002020,0x1C40120100004020,0x1009040000802020,0x0884002800841010,0x2220068801201011,0x1911442000004022,0x0004020802010011,0x0220004400102001,
0x4009608000842280,0x4060104318400210,0x0811002400040020,0x4801520000C41010,0x0004280020022204,0x0413000408404041,0x000C028800000101,0x100400E904000201,
0x03800242000100A5,0x00C0008008210321,0x2003002400001261,0x410028894A041001,0x0800041040002901,0x001002080204080E,0x0022218040040401,0x0024084103280482,
0x0020002020801040,0x1020200020400812,0x04082000000C0061,0x4042024001200804,0x5040040000024188,0x0100040008101A13,0x0408108018080802,0x0080408064000041,
0x0850400821800120,0x008100240008480B,0x6008080001100241,0x1EB0100200110248,0x0030202216010004,0x00802021000C6142,0x032200444020410A,0x00A0202004580041,
0x0080410000406180,0x08220200002040A3,0x093000200A002804,0x40080080010010B2,0x40080101012A1304,0x0004041000001012,0x010001000E840482,0x0C04020200004885,
0x1080006110001041,0x2081211102084250,0x1020001500014619,0x3810440A10000C23,0x0410484200860422,0x180B0201090B2004,0x1100040124410282,0x001820A101000443};

Const U64 BMagic[64]= {
0x1841160051A00401,0x0202000012224A02,0x0284003005412542,0x002800A220C40502,0x0068005050040308,0x440802C810020230,0x0240034002014417,0x045202411310208A,
0x1A08410602016172,0x0830464044100E08,0x411A31A010040808,0x0200124000484405,0x060020C80000120A,0x06A001002583420A,0x10082020084C0051,0x1325202008030692,
0x2002026A00045020,0x41051C000052122C,0x010200B000100803,0x0720204000610032,0x6818603041604002,0x1041040010020001,0x0301081420025204,0x0042024420826001,
0x0404304000131801,0x1041090C00842100,0x0144110020080240,0x1211004002202008,0x0105080000500401,0x2080600C62080131,0x0844100114022082,0x0841080020804B00,
0x0008240800080210,0x4002144012084210,0x0002052000060904,0x0088400420500C14,0x0000434000204404,0x1840240800212081,0x004208C019244184,0x000054DA10030841,
0x1200090011080A02,0x0800140C000414C8,0x4400382000401058,0x0100020140000105,0x0610040040044421,0x020001202848110A,0x0222011010300101,0x0106608008012304,
0x0220429002014A02,0x110800A005104208,0x0806201048200111,0x2082008A03000802,0x2041008034011420,0x0401006005004434,0x090A429004080204,0x2041040950041802,
0x1002200028441145,0x109004012802018A,0x0065100405500801,0x0284240458180A00,0x2002441020024020,0x4A10110101144112,0x01010A2C00005030,0x040C012121020424};


So far so good but I don't know which square mapping has been used. Little Endian File-Rank (LEFR) mapping, LERF or something else? Is it possible to tell from this data set?

Thanks in advance!
gpapas123
 
Posts: 9
Joined: 07 Jul 2010, 21:41

Re: How to determine the square mapping based on bitboards?

Postby H.G.Muller » 29 Mar 2023, 08:48

Would that even matter? The Rook and Bishop attack sets are 8-fold symmetric. So I could imagine that all raster scans of the board, no matter in which corner and direction they start, are equivalent.
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: How to determine the square mapping based on bitboards?

Postby gpapas123 » 31 Mar 2023, 10:34

Could you elaborate a bit more on this 8-fold symmetry idea please?
gpapas123
 
Posts: 9
Joined: 07 Jul 2010, 21:41

Re: How to determine the square mapping based on bitboards?

Postby H.G.Muller » 02 Apr 2023, 18:25

When you would look at the move diagram of a Rook or Bishop printed on a transparency, it would be valid in each of the four orientations that would result from rotating it such that another edge is the top one, and also when you look at it from the back. Imagine you would have to finish and end-game King + Rook vs King, and the position is already set up on a board without coordinate markings, in the middle of a square table with 4 chaisr around it. Accidentally you and your opponent sit down on the wrong two squares. Would you ever notice this?

Any numbering based on a raster scan of the board can be rotated and flipped such that it starts counting in the lower-left corner, in the horizontal direction (i.e. a1-...-h1-a2-...-h2-a3-...). So all these numberings are equivalent. Write an attacks getter for one of those, and it would be valid for all others as well.
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: How to determine the square mapping based on bitboards?

Postby gpapas123 » 04 Apr 2023, 17:36

Thank you for your reply! I guess you are saying that if you rotate the board by a multiple of 90 degrees or if you flip the board around a principal axis you still have the same game.
That's true of course because the board geometry is the same. However, I am not totally convinced. Which magic should I use for a rook on A2? Is it the same as on B1? or A7 or B8 etc?
This map of the board onto itself is necessary to put the magics in the right places no? Let alone there are positive and negative rays from a given square. That gives a preferred direction,
hence the game of chess is not isotropic.
gpapas123
 
Posts: 9
Joined: 07 Jul 2010, 21:41

Re: How to determine the square mapping based on bitboards?

Postby H.G.Muller » 05 Apr 2023, 07:59

The point is that both the placement of the magic and the interpretation of the looked-up data changes when you use a different square numbering. This should compensate each other.

So you should not think of the magics as being 'for a2' or 'for b1'. They are for the square that is represented by a certain bit in the bitboard. Which square that is depends on your numbering system. But you should use the first magic in the table (and the first occupancy mask in the table) for the square represented by the least significant bit of the bitboard, (whether that is a1, h1, a8 or h8), the next one for the square represented by bit 1, etc.
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: How to determine the square mapping based on bitboards?

Postby gpapas123 » 06 Apr 2023, 00:04

I see what you mean, the job of the magics is to take the masked occupation bits and put them next to each other so that they don't overlap to form low-dimensional keys. We now have the freedom of assigning attack sets to all such keys. Oh well, one week of more coding on my part... Don't you love chess programming ?!

Why did the word "tensor" come to my mind?

Thanks a bunch!
gpapas123
 
Posts: 9
Joined: 07 Jul 2010, 21:41


Return to Programming and Technical Discussions

Who is online

Users browsing this forum: No registered users and 9 guests