Magic Bitboards AND optimal shifts

Discussion of chess software programming and technical issues.

Moderator: Ras

User avatar
Desperado
Posts: 879
Joined: Mon Dec 15, 2008 11:45 am

Magic Bitboards AND optimal shifts

Post by Desperado »

Hi all,

i am interested in what you are thinking about the following...(rook/queen shifts as example)

Code: Select all


/*
#define MSK_R(OCC,SQ) (OCC & msk_r[SQ])

#define MAGIC_R(OCC,SQ) ((MSK_R(OCC,SQ) * mgc_r[SQ]) >> shr_r[SQ])

// a normal shift set...
    extern const UI_08 shr_r[ID_64] = 
		{
		 52,53,53,53,53,53,53,52,
		 53,54,54,54,54,54,54,53,
		 53,54,54,54,54,54,54,53,
		 53,54,54,54,54,54,54,53,
		 53,54,54,54,54,54,54,53,
		 53,54,54,54,54,54,54,53,
		 53,54,54,54,54,54,54,53,
		 53,54,54,53,53,53,53,53
		};
	*/
	
	//optimal shifts
	extern const UI_08 shr_r[ID_64] = 
		{
		 52,53,53,53,53,53,53,52,
		 53,54,54,54,54,54,54,53,
		 53,54,54,54,54,54,54,53,
		 53,54,54,54,54,54,54,53,
		 53,54,54,54,54,54,54,53,
		 53,54,54,54,54,54,54,53,
		 53,54,54,54,54,54,54,53,
		 52,53,53,53,53,53,53,52
		};

	extern const UI_64 mgc_r[ID_64]=
		{
		 0x0080001020400080, 0x0040001000200040, 0x0080081000200080, 0x0080040800100080,
		 0x0080020400080080, 0x0080010200040080, 0x0080008001000200, 0x0080002040800100,
		 0x0000800020400080, 0x0000400020005000, 0x0000801000200080, 0x0000800800100080,
		 0x0000800400080080, 0x0000800200040080, 0x0000800100020080, 0x0000800040800100,
		 0x0000208000400080, 0x0000404000201000, 0x0000808010002000, 0x0000808008001000,
		 0x0000808004000800, 0x0000808002000400, 0x0000010100020004, 0x0000020000408104,
		 0x0000208080004000, 0x0000200040005000, 0x0000100080200080, 0x0000080080100080,
		 0x0000040080080080, 0x0000020080040080, 0x0000010080800200, 0x0000800080004100,
		 0x0000204000800080, 0x0000200040401000, 0x0000100080802000, 0x0000080080801000,
		 0x0000040080800800, 0x0000020080800400, 0x0000020001010004, 0x0000800040800100,
		 0x0000204000808000, 0x0000200040008080, 0x0000100020008080, 0x0000080010008080,
		 0x0000040008008080, 0x0000020004008080, 0x0000010002008080, 0x0000004081020004,
		 0x0000204000800080, 0x0000200040008080, 0x0000100020008080, 0x0000080010008080,
		 0x0000040008008080, 0x0000020004008080, 0x0000800100020080, 0x0000800041000080,
		 0x00FFFCDDFCED714A, 0x007FFCDDFCED714A, 0x003FFFCDFFD88096, 0x0000040810002101,
		 0x0001000204080011, 0x0001000204000801, 0x0001000082000401, 0x0001FFFAABFAD1A2
		};
Of course using these shift values are causing an index collision , BUT did you ever realized that the value stored in the index might be correct !?
(it's now few months ago i worked with it, and i tested it in different ways)
i wasnt able to find any "buggy" entries (on index collision).
So why not using the optimal shift. (in hope it is correct what i say, try it out ) :-)
Gerd Isenberg
Posts: 2251
Joined: Wed Mar 08, 2006 8:47 pm
Location: Hattingen, Germany

Re: Magic Bitboards AND optimal shifts

Post by Gerd Isenberg »

Desperado wrote:Hi all,

i am interested in what you are thinking about the following...(rook/queen shifts as example)

Of course using these shift values are causing an index collision , BUT did you ever realized that the value stored in the index might be correct !?
(it's now few months ago i worked with it, and i tested it in different ways)
i wasnt able to find any "buggy" entries (on index collision).
So why not using the optimal shift. (in hope it is correct what i say, try it out ) :-)
Hi Michael,
I don't exactly understand what you mean by optimal shift, since better shifts are the higher ones (less remaining bits -> shorter index range -> smaller tables). As long as different occupancies share equal attack sets (if redundant outer squares vary), index collisions are very welcome and even necessary to map n relevant occupied bits to n or even n-1 bits in the index range.

Gerd
User avatar
Desperado
Posts: 879
Joined: Mon Dec 15, 2008 11:45 am

Re: Magic Bitboards AND optimal shifts

Post by Desperado »

if i could i would delete my totally confused post.

:oops: Sorry...
Gerd Isenberg
Posts: 2251
Joined: Wed Mar 08, 2006 8:47 pm
Location: Hattingen, Germany

Re: Magic Bitboards AND optimal shifts

Post by Gerd Isenberg »

Desperado wrote:if i could i would delete my totally confused post.

:oops: Sorry...
No problem ;-)