Green Technology Blog

May 29, 2008

Growing bitboards from possible moves into sound moves, pawn displaces, and conditional rules.

The BitBoards so far have been astoundingly precise at making moves. But still after the moves have been brought forth they have to be amply formalized. Hold instance, a bishop in the middle of the board. The number of possible moves for the bishop is 13 or thus, but the number of valid moves, unless no spots are hindered, is much less. Further doing well-disposed versus non-well-disposed extension is extremely importan since you can’t move into a well-disposed position, but you can go in the first coming non-well-disposed position (catching). I’ve felt some interesting transformations hither, but in one case I can more full formalize them I’ll get to put up their intricacies.

Yet more thwarting are the pawns. Pawns are equal to of particular feats when in their original file (forth by 2), they are granted catching moves that are unlike from their received movement rules, and they are besides granted the ability to catch en-passant. Making up one’s mind where and how to enforce these additional conditions is very of import. Commend the original forgeting square algorithm I implemented for transfering invalid moves consisted of:

uint myPieces =…; uint notMine = ~myPieces; uint validMoves = bes active & notMine;

This has to be elaborated a bit, since notMine really points to all empty-bellied and enemy squares. What we require at present is a forgeting region for all enemy squares (which we have to salt away in any event, since finally the board switchs sides and enemy and favorable are turned). The valid moves suit something like:


uint nonCapture = pawnNonCapture[x]; uint catch = pawnCapture[x];
uint validNonCapture = (~(myPieces & enemyPieces) & nonCapture);
uint validCapture = capture & enemyPieces;
if ( board.enPassant ) { /* particular case when anterior moves tolerate */ }
uint validMoves = validNonCapture | validCapture;

Yet with all of this charming bit-dislodging we aren’t accounting for visibility off the first rank. After all, if we are choked up forrard 1 and not forrard 2, this might however yield that as a valid move. After all of this work on pawn movements, it might be best hardly to leave alone them to extra incased code because of their intricacies compared to other pieces. What can we do and so to apace bring forth pawn moves? Some ideas are bing adrift about for certain. If I have a BitBoard of all my pawns I can easy do the coming after:

uint validMoves = (curPawns << 8) & (~(myPieces & enemyPieces)); // one sided, but fundamentally bring forward and check.
validMoves |= ((validMoves & 0xFF0000) << 8) & (~(myPieces & enemyPieces)); // all that were capable to go fore 1, go 2

Some of the above information would be pregenerated, but you can envision all of the sick details in action. Captures are a introductory extension of the above. The introductory premise implies 7 or 9 bit wobbling operations on with clearing of the overflow file. What do I mean by overflow file? Well, withdraw the rightmost file, h, and and then assure me how a pawn would aggress off the proper side of the board. If we shift by 9 notwithstanding the pawn in file h, would wrap up about and assail the other side of the board. Uncluttering the pawns in the oveflow ranks is the only way I can remember acquiring rid of this for at present.

uint validCaptures = ((curPawns & clearRank[0]) << 7) & enemyPieces;
validCaptures |= ((curPawns & clearRank[7]) << 9) & enemyPieces;

It is fairly skillful to be capable to look all pawn bes active simultaneously in this manner. I’d even so compute en-passant individually because it has side-effects. The aggressing square is unlike from the square where the enemies piece would be taken away. It is an superfluous piece of information that the board has to pack about to get to certain that it ever dos the appropriate captures.

If you have questions about some of the rules, I in reality discovered the tracing a bit helpful. I have a chess rules book that I incline to go to first for explanation, particularly since I require to insure accuracy in the engine. When I don'’t feel like leafing I’ll check something out here in the FAQ and then put a little comment in the code to go back later and check the official rules http://www.chessvariants.org/d.chess/faq.html. Still if you cognise how to toy chess, these FAQs can be algorist playgrounds, since frequently looked out on newbie questions can sharpen out subtleties, patterns and optimizations you might not other than dream-up.

Relating Posts:
Turning bitboards from potential moves into legal moves, pawn moves, and conditional rules.
Villages micropolitan area nowadays loyalest-farming

Comments

The URI to TrackBack this entry is: http://medonza.blogsome.com/2008/05/29/growing-bitboards-from-possible-moves-into-sound-moves-pawn-displaces-and-conditional-rules/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Sorry, the comment form is closed at this time.






















Get free blog up and running in minutes with Blogsome
Theme designed by Helga Cleve