public MovePly branchPromotion() { var promoPly = new MovePly(c, movedIndex, square, move); promoPly.setCaptureIndex(capturedIndex); promoPly.setPromotion(); return promoPly; }
// Returns a list of all possible plies public List<Ply> children(Bits[] position, int c) { var plies = new List<Ply> (); // Calculate all squares not occupied by pieces of colour c Bits notCPieces = (Bits)((~colourPieces (position, c)) & ((1 << files*columns) - 1)); // Calculate all squares occupied by pieces of colour (c ^ 1) Bits enemyPieces = colourPieces (position, (c ^ 1)); // Loop through each piece type for (int p = 0; p < l; ++p) { // Extract each individual piece foreach (Bits square in B.allOnes(position[p + c * l])) { // Check its moves var singleMoves = moves (square, p, c, notCPieces); // For each move create a ply foreach (Bits move in singleMoves) { var ply = new MovePly (c, p, square, move); if (B.Overlaps(move, enemyPieces)) ply.setCaptureIndex (capture (position, move, c)); // Add ply without promotion plies.Add (ply); // Check for promotion and branch if it is possible if (p < pieces.Length && pieces [p].ptype != Type.None) if (B.Overlaps (promoMask [c], square) || B.Overlaps (promoMask [c], move)) { plies.Add (ply.branchPromotion ()); } } } } // Get the players hand information Bits hand = position [2 * l + c]; // If it is not empty calculate empty squares if (hand != 0) { Bits all = (Bits)(notCPieces ^ (enemyPieces)); // Loop through all piece types foreach (var pieceMask in handMask) { // Check if the player has this piece if (B.Overlaps(hand, pieceMask.Value)) // Calculate all positions where it can be dropped foreach (Bits square in B.allOnes(all)) { // Add a drop ply for each possible drop plies.Add (new DropPly (c, pieceMask.Key, square)); } } } // Return all possible plies return plies; }