Changes

Jump to: navigation, search

OliThink

17 bytes added, 12:35, 7 June 2021
no edit summary
<span id="SlidingPieceAttacks"></span>
==Sliding Piece Attacks==
OliThink pre 5 versions used [[Rotated Bitboards|rotated bitboards]] to determine [[Sliding Piece Attacks|sliding piece attacks]]. Since version 5, only the usual [[Occupancy|occupancy]] is used to [[Occupancy of any Line|map the masked line to an index]], for [[Files|files]] and [[Diagonals|diagonals]] by a [[General Setwise Operations#Multiplication|north-fill multiplication]] and right shift as also applied in [[Kindergarten Bitboards|kindergarten bitboards]] <ref>[http://www.talkchess.com/forum/viewtopic.php?t=24724 Kindergarten Bitboard Approach by Gerd Isenberg] by [[Edsel Apostol]], [[CCC]], November 05, 2008</ref>, with the addition not only to lookup attack bitboards, but also [[X-ray Attacks (Bitboards)#Xray1|X-ray attacks]] through the first blocking pieces (if any) of both [[Direction|ray-directions]] <ref>[http://www.talkchess.com/forum/viewtopic.php?topic_view=threads&p=166649&t=18750 Re: Question about SEE (Static exchange evaluation)] by [[Oliver Brausch]], [[CCC]], December 18, 2007</ref> . A pre-initialized [[Array|array]] of 8 times 8K bitboards (512 Kbyte in total) is used for attacks on [[Ranks|ranks]], files, diagonals and [[Anti-Diagonals|anti-diagonals]] in its lower half, while the upper half holds appropriate x-ray attacks. Per line, a 1312-bit index is composed of the 6-bit square index and a 76-bit occupancy key<ref>[http://www.talkchess.com/forum3/viewtopic.php?f=2&t=77339&start=44 Re: OliThink 5.9.5 is very small] by [[Oliver Brausch]], [[CCC]], June 06, 2021</ref>.
===C Source===
These are the relevant code snippets and data declarations of the attack and x-ray attack getter in the [[C]] source, initialization omitted <ref>[httphttps://brauschgithub.orgcom/homeolithink/OliThink/chesscommit/index.html Chess Engine OliThink - OliThink Source Code Vers. 78fa794f777bd5e851fc0abbcfc1bca22e6c0dcf 5.3.2 Native - olithink9.c 8a Half sized bitboards (slightly edited)]</ref>. Using addition instead of bitwise-or might take advantage of the [[x86]] lea instruction, specially for the line-offsets:
<pre>
static u64 rays[0x100000x8000]; /* 8*64 = 512 256 KByte */
u64 bmask45[64];
u64 bmask135[64];
#define BOARD (colorb[0] | colorb[1])
#define RATT1(f) rays[((f) << 76) | key000(BOARD, f) ]#define RATT2(f) rays[((f) << 76) | key090(BOARD, f) | 0x20000x1000]#define BATT3(f) rays[((f) << 76) | key045(BOARD, f) | 0x40000x2000]#define BATT4(f) rays[((f) << 76) | key135(BOARD, f) | 0x60000x3000]#define RXRAY1(f) rays[((f) << 76) | key000(BOARD, f) | 0x80000x4000]#define RXRAY2(f) rays[((f) << 76) | key090(BOARD, f) | 0xA0000x5000]#define BXRAY3(f) rays[((f) << 76) | key045(BOARD, f) | 0xC0000x6000]#define BXRAY4(f) rays[((f) << 76) | key135(BOARD, f) | 0xE0000x7000]
int key000(u64 b, int f) {return (int) ((b >> ((f & 56) + 1)) & 0x7E0x3F);}
int key090(u64 b, int f) {
u64 _b = (b >> (f&7)) & 0x0101010101010101LL;
_b = _b * 0x0080402010080400LL;
return (int)(_b >> 5758);
}
int keyDiag(u64 _b) {
_b = _b * 0x0202020202020202LL;
return (int)(_b >> 5758);
}
int key045(u64 b, int f) {return keyDiag(b & bmask45[f]);}
</pre>
===Java Source===
In [[Java]], the code looks quite similar, embedded inside the class OliThink <ref>[http://brausch.org/home/chess/index.html Chess Engine OliThink - OliThink Source Code Vers. 5.3.2 Java - olithink.java (slightly edited)]</ref>, using the [https://en.wikipedia.org/wiki/Bitwise_operation#Shifts_in_Java unsigned right shift operator] (>>>) instead the arithmetical one (>>) inside the keyxxx routines would safe the post-masking with 0x7f:
<pre>
final static long[] rays = new long[0x100000x8000];
final static long[] bmask45 = new long[64];
final static long[] bmask135 = new long[64];
static long BOARD() { return (colorb[0] | colorb[1]); }
static long RATT1(int f) {return rays[((f) << 76) | key000(BOARD(), f) ];}static long RATT2(int f) {return rays[((f) << 76) | key090(BOARD(), f) | 0x20000x1000];}static long BATT3(int f) {return rays[((f) << 76) | key045(BOARD(), f) | 0x40000x2000];}static long BATT4(int f) {return rays[((f) << 76) | key135(BOARD(), f) | 0x60000x3000];}static long RXRAY1(int f) {return rays[((f) << 76) | key000(BOARD(), f) | 0x80000x4000];}static long RXRAY2(int f) {return rays[((f) << 76) | key090(BOARD(), f) | 0xA0000x5000];}static long BXRAY3(int f) {return rays[((f) << 76) | key045(BOARD(), f) | 0xC0000x6000];}static long BXRAY4(int f) {return rays[((f) << 76) | key135(BOARD(), f) | 0xE0000x7000];}
static int key000(long b, int f) {return (int) ((b >> ((f & 56) + 1)) & 0x7E0x3f);}
static int key090(long b, int f) {
long _b = (b >> (f&7)) & 0x0101010101010101L;
_b = _b * 0x0080402010080400L;
return (int)((_b >> 5758) & 0x7F0x3F);
}
static int keyDiag(long _b) {
_b = _b * 0x0202020202020202L;
return (int)((_b >> 5758) & 0x7F0x3F);
}
static int key045(long b, int f) {return keyDiag(b & bmask45[f]);}
* [http://www.talkchess.com/forum3/viewtopic.php?f=7&t=75670 Ancient olithink fossils] by [[Dann Corbit]], [[CCC]], November 03, 2020
: [http://www.talkchess.com/forum3/viewtopic.php?f=7&t=75670&start=1 Re: Ancient olithink fossils] by Ajedrecista, [[CCC]], November 03, 2020
'''2021'''
* [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=77339 OliThink 5.9.5 is very small] by [[Oliver Brausch]], [[CCC]], May 18, 2021
: [http://www.talkchess.com/forum3/viewtopic.php?f=2&t=77339&start=44 Re: OliThink 5.9.5 is very small] by [[Oliver Brausch]], [[CCC]], June 06, 2021 » [[Kindergarten Bitboards]]
=External Links=

Navigation menu