Changes

Jump to: navigation, search

Pawn Pushes (Bitboards)

3,775 bytes added, 09:21, 8 May 2018
Created page with "'''Home * Board Representation * Bitboards * Pawn Pattern and Properties * Pawn Pushes''' FILE:Chimpanzee1d4.jpg|border|right|thumb|link=http://al..."
'''[[Main Page|Home]] * [[Board Representation]] * [[Bitboards]] * [[Pawn Pattern and Properties]] * Pawn Pushes'''

[[FILE:Chimpanzee1d4.jpg|border|right|thumb|link=http://alchessmist.blogspot.de/2008/12/animal-cognition-theory-of-mind-and.html|[https://en.wikipedia.org/wiki/Chimpanzee Chimpanzee] pushing 1. d4 <ref>[http://alchessmist.blogspot.com/2008/12/animal-cognition-theory-of-mind-and.html Animal Cognition - "Theory Of Mind" and "Chimp Chess"] from [http://alchessmist.blogspot.com/ ALCHEssMIST]</ref> <ref>[http://www.worth1000.com/entries/396884/ Chimpanzee - Worth1000 Contests] by [http://www.worth1000.com/artists/minouz minouz]</ref> ]]

<span id="PawnPushSetwise"></span>Bitboards allow to determine [[Pawn Push|pawn push]] target squares, or equivalently their [[Stop Square|stop squares]] set-wise, while pawn pushes of a single pawn are the domain of [[Mailbox|mailbox]]-approaches. To generate the single-step targets for all pawns requires vertical shift by one [[Ranks|rank]] and [[General Setwise Operations#Intersection|intersection]] with the set of empty squares. The resulting set might be shifted one more time for the double pushes by further intersection with empty squares on the fourth (white) or fifth (black) double push target ranks. Since double pushing triggers determination of [[En passant|en passant]] target square, it makes sense to [[Bitboard Serialization|serialize]] both sets separately for different [[Encoding Moves|move encoding]].
<span id="SpecializedPush"></span>
=Push per Side=
Keeping different but most efficient code for both white and black pawns. The code snippets rely on [[General Setwise Operations#ShiftingBitboards|shifting bitboards]], specially by [[General Setwise Operations#OneStepOnly|one step only]].
<pre>
U64 wSinglePushTargets(U64 wpawns, U64 empty) {
return nortOne(wpawns) & empty;
}

U64 wDblPushTargets(U64 wpawns, U64 empty) {
const U64 rank4 = C64(0x00000000FF000000);
U64 singlePushs = wSinglePushTargets(wpawns, empty);
return nortOne(singlePushs) & empty & rank4;
}

U64 bSinglePushTargets(U64 bpawns, U64 empty) {
return soutOne(bpawns) & empty;
}

U64 bDoublePushTargets(U64 bpawns, U64 empty) {
const U64 rank5 = C64(0x000000FF00000000);
U64 singlePushs = bSinglePushTargets(bpawns, empty);
return soutOne(singlePushs) & empty & rank5;
}
</pre>
=Pawns able to Push=
To get the set of source squares of pawns able to push is about intersection of pawns with the shifted empty squares in opposite [[Direction|direction]]:
<pre>
U64 wPawnsAble2Push(U64 wpawns, U64 empty) {
return soutOne(empty) & wpawns;
}

U64 wPawnsAble2DblPush(U64 wpawns, U64 empty) {
const U64 rank4 = C64(0x00000000FF000000);
U64 emptyRank3 = soutOne(empty & rank4) & empty;
return wPawnsAble2Push(wpawns, emptyRank3);
}
</pre>
and similar for black.
<span id="GeneralizedPush"></span>
=Generalized Push=
One may rely on the [[General Setwise Operations#GeneralizedShift|generalized shift]] for one [[Color|color]] parametrized pawn push routine. Since pawns don't occur on the first or eighth rank, one may either safe the wrap-ands ...
<pre>
enum { white, black };

U64 singlePushTargets(U64 pawns, U64 empty, int color) {
return rotateLeft( pawns, 8 - (color << 4) ) & empty;;
}
</pre>
... or make the "white" north-shift unconditionally but to conditionally shift back south two ranks by color*16:
<pre>
U64 singlePushTargets(U64 pawns, U64 empty, int color) {
return ( (pawns << 8) >> (color << 4) ) & empty;
}
</pre>

=Forum Posts=
* [http://www.talkchess.com/forum/viewtopic.php?t=47710 How to Shift Left (by) a Negative Number??] by [[Steve Maughan]], [[CCC]], April 05, 2013

=References=
<references />

'''[[Pawn Pattern and Properties|Up one Level]]'''

Navigation menu