Changes

Jump to: navigation, search

X-ray Attacks (Bitboards)

7,544 bytes added, 11:01, 8 May 2018
Created page with "'''Home * Board Representation * Bitboards * X-ray Attacks''' The term '''X-ray attack''' was apparently originated by [https://en.wikipedia.org/wiki/Ke..."
'''[[Main Page|Home]] * [[Board Representation]] * [[Bitboards]] * X-ray Attacks'''

The term '''X-ray attack''' was apparently originated by [https://en.wikipedia.org/wiki/Kenneth_Harkness Kenneth Harkness]. On page 25 of the April 1947 [https://en.wikipedia.org/wiki/Chess_Review Chess Review], in his series ''Picture Guide to Chess'', he mentioned forks and then wrote <ref>[[Jack O’Keefe]] in [http://www.chesshistory.com/winter/winter20.html#4245._X-ray_attack_C.N._4231 Chess Note 4245. X-ray attack] by [https://en.wikipedia.org/wiki/Edward_Winter_%28chess_historian%29 Edward Winter]</ref>:
There is another type of double attack in which the targets are threatened in one direction. The attacking piece threatens two units, one behind the other, on the same rank, file or diagonal. This double threat has lacked a good descriptive name. We suggest ‘X-Ray’ attack.

=Attacking through=
There are several [[Tactics|tactical]] motives, where a [[Sliding Pieces|sliding piece]] attacks through any other piece in a [[Direction|ray-direction]]:
{| class="wikitable"
|-
! Motiv
! Blocker
! Target behind Blocker
|-
| [[Battery]]
| own sliding piece
| style="text-align:right;" | any square or piece
|-
| [[Discovered Attack]]
| own piece may remove
| style="text-align:right;" | any opposing piece
|-
| [[Discovered Check]]
| own piece may remove
| style="text-align:right;" | opposing king
|-
| [[Pin]]
| opposing piece
| style="text-align:right;" | opposing valuable piece
|-
| [[Pin#AbsolutePin|Absolute Pin]]
| opposing piece
| style="text-align:right;" | opposing king
|-
| [[Pin#PartialPin|Partial Pin]]
| opposing sliding piece
| style="text-align:right;" | opposing valuable piece
|-
| [[Skewer]]
| opposing valuable piece
| style="text-align:right;" | opposing piece
|-
| [[X-ray]]
| opposing sliding piece
| style="text-align:right;" | own piece
|}

=Single Sliders=
The single sliding piece, a rook, bishop or queen is specified by square index, likely from a [[BitScan|bitscan]] of a piece-wise [[Bitboard Serialization|bitboard serialization]] of a sliding piece bitboard from a [[Bitboard Board-Definition|standard board-definition]].
<span id="ModifyingOccupancy"></span>
==Modifying Occupancy==
Following routines may be used to get all kind of x-ray attacks or defenses through the blockers for one particular slider. The idea is to intersect the sliding attacks with the desired blockers, which are subset of occupied. In a second run, those blockers are removed from the occupancy, to get the x-ray attacks as the symmetric difference of both attacks.
<pre>
U64 xrayRookAttacks(U64 occ, U64 blockers, enumSquare rookSq) {
U64 attacks = rookAttacks(occ, rookSq);
blockers &= attacks;
return attacks ^ rookAttacks(occ ^ blockers, rookSq);
}

U64 xrayBishopAttacks(U64 occ, U64 blockers, enumSquare bishopSq) {
U64 attacks = bishopAttacks(occ, bishopSq);
blockers &= attacks;
return attacks ^ bishopAttacks(occ ^ blockers, bishopSq);
}
</pre>
Alternatively one may use a condition to save the second lookup - one may use disjoint line-attacks rather than piece-attacks. If so, it makes sense to exclude the outer squares from the blockers.
<pre>
U64 xrayFileAttacks(U64 occ, U64 blockers, enumSquare rookSq) {
U64 attacks = fileAttacks(occ, rookSq);
blockers &= attacks & C64(0x00FFFFFFFFFFFF00);
if ( blockers == 0 ) return blockers;
return attacks ^ fileAttacks(occ ^ blockers, rookSq);
}

U64 xrayRankAttacks(U64 occ, U64 blockers, enumSquare rookSq) {
U64 attacks = rankAttacks(occ, rookSq);
blockers &= attacks & C64(0x7E7E7E7E7E7E7E7E);
if ( blockers == 0 ) return blockers;
return attacks ^ rankAttacks(occ ^ blockers, rookSq);
}

U64 xrayDiagonalAttacks(U64 occ, U64 blockers, enumSquare bishopSq) {
U64 attacks = diagonalAttacks(occ, bishopSq);
blockers &= attacks & C64(0x007E7E7E7E7E7E00);
if ( blockers == 0 ) return blockers;
return attacks ^ diagonalAttacks(occ ^ blockers, bishopSq);
}
</pre>
<span id="Xray1"></span>
==X-rays with one Lookup==
Another idea is to consider all kind of blockers in one run, and to traverse intersections of the x-rays attacks with different target sets, to determine the blocking piece inside a loop. In the context of absolute pins, [[Oliver Brausch]] introduced to lookup x-ray attacks through any blocker in his engine [[OliThink]] <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> - similar to any occupied lookup technique to get [[Sliding Piece Attacks#AttacksbyOccupancyLookup|sliding piece attacks]]. Instead of the pre-calculated line-attacks we can also pre-calculate attacks behind the first blocker, including a possible second blocker. [[First Rank Attacks#TheOuterSquares|The outer squares]] are redundant as well. Some sample on a rank:
<pre>
rook 00001000
occupied 01011010
attacks 00010110
x-ray 01100001
</pre>
Since absolute pins and discovered checkers are usually quite rare, it might be worth to spend some additional memory, e.g. 8 KByte for [[Kindergarten Bitboards|kindergarten]] - x-rays. Also the [[The switch Approach|switch approach]] is great to consider all kind of x-ray stuff on a line.

=Multiple Sliders=
If keeping eight disjoint ray-direction attacks from fill-routines like [[Kogge-Stone Algorithm]] one may intersect them with desired blockers - and to perform another fill with that intersection:
<pre>
U64 xrayAttacks(U64 sliders, U64 empty, U64 blockers, int dir8) {
U64 attacks = slidingAttacks (sliders, empty, dir8);
blockers &= attacks; // & notOuterSquares[dir8];
if ( blockers )
return slidingAttacks (blockers, empty, dir8);
return 0;
}
</pre>

==Blockers by Targets==
The other idea is to fill the potential target set, and to intersect it with the opposite ray-direction fill of the sliders and the relevant blockers:
<pre>
U64 betweenSliderAndTarget(U64 sliders, U64 empty, U64 targets, int dir8) {
U64 attacks = slidingAttacks (sliders, empty, dir8);
U64 fromtarget = slidingAttacks (targets, empty, opposite(dir8));
return attacks & fromtarget;
}
</pre>
=See also=
* [[OliThink#SlidingPieceAttacks|Sliding Piece Attacks]] in [[OliThink]]

=Forum Posts=
* [http://www.talkchess.com/forum/viewtopic.php?t=29577 Generating "through" attacks with rotated bitboard] by [[Vlad Stamate]], [[CCC]], August 28, 2009 » [[Rotated Bitboards]]

=External Links=
* [https://en.wikipedia.org/wiki/X-ray_(chess) X-ray (chess) from Wikipedia]
* [[Videos#Defunkt|Defunkt]] - See Through, [https://de.wikipedia.org/wiki/Jazzopen_Stuttgart Jazzopen Stuttgart] 1996, [https://en.wikipedia.org/wiki/3sat 3sat] broadcast, [https://en.wikipedia.org/wiki/YouTube YouTube] Video
: lineup: [https://en.wikipedia.org/wiki/Joseph_Bowie Joseph Bowie], [http://www.allmusic.com/artist/kelvyn-bell-mn0001577170/credits Kelvyn Bell], [http://www.dfmusicinc.com/news/item.asp?ID=15 Larry Bowen], [http://www.discogs.com/artist/299640-Bahnamous-Bowie Bahnamous Bowie], [http://www.discogs.com/artist/363770-Byron-Bowie Byron Bowie], [[Videos#KimClarke|Kim Clarke]], [http://www.allmusic.com/artist/scooter-warner-mn0000645895/credits Scooter Warner], [https://en.wikipedia.org/wiki/Ronny_Drayton Ronny Drayton]
: {{#evu:https://www.youtube.com/watch?v=k-4IsT9TrOA|alignment=left|valignment=top}}

=References=
<references />

'''[[Bitboards|Up one Level]]'''

Navigation menu