public override void AddRules() { base.AddRules(); // *** CASTLING *** // #region Castling if (Castling.Value == "Colossus") { // find the king's start square (must be e1 or f1) GenericPiece WhiteKing = new GenericPiece(0, CastlingType); GenericPiece BlackKing = new GenericPiece(1, CastlingType); bool supported = false; string kingSquare = null; if (StartingPieces["f2"] == WhiteKing) { kingSquare = "f2"; if (StartingPieces["f9"] == BlackKing) { supported = true; } } else if (StartingPieces["e2"] == WhiteKing) { kingSquare = "e2"; if (StartingPieces["e9"] == BlackKing) { supported = true; } } if (!supported) { throw new Exception("Can't enable castling rule because King does not start on a supported square"); } AddFlexibleCastlingRule(); if (kingSquare == "f2") { FlexibleCastlingMove(0, "f2", "g2", "i2", 'K', true); FlexibleCastlingMove(0, "f2", "e2", "b2", 'Q', true); FlexibleCastlingMove(1, "f9", "g9", "i9", 'k', true); FlexibleCastlingMove(1, "f9", "e9", "b9", 'q', true); } else { // if the King starts on e2, use shredder-notation FlexibleCastlingMove(0, "e2", "d2", "b2", 'B', true); FlexibleCastlingMove(0, "e2", "f2", "i2", 'I', true); FlexibleCastlingMove(1, "e9", "d9", "b9", 'b', true); FlexibleCastlingMove(1, "e9", "f9", "i9", 'i', true); } } #endregion }
public override void AddRules() { base.AddRules(); // *** CASTLING *** // #region Castling // Only handle here if this is a castling type we defined if (Castling.Choices.IndexOf(Castling.Value) < Castling.Choices.IndexOf("None")) { #region First rank castling rules if (Castling.Value[0] != '2') { // Adding castling rule is somewhat complicated because there are a number of different forms // of castilng and we have to accomodate the King on either e1 or f1 as well as the fact that // the FEN notation, (typically KQkq), for King-side or Queen-side might be inappropriate, // in which case we use Shredder-FEN notation where the priv char is the file of the rook // find the king's start square (must be e1 or f1) GenericPiece WhiteKing = new GenericPiece(0, CastlingType); GenericPiece BlackKing = new GenericPiece(1, CastlingType); string kingSquare; if (StartingPieces["e1"] == WhiteKing) { kingSquare = "e1"; } else if (StartingPieces["f1"] == WhiteKing) { kingSquare = "f1"; } else { throw new Exception("Can't enable castling rule because King does not start on a supported square"); } // Use Shredder-FEN notation? We will use Shredder-FEN notation unless the Kings start on f1/f8 // and a piece with a notation of Q starts on either e1 or d1 (for consistency with 10x8) // and the castling is with pieces in the corners (e.g., not Close-Rook castling.) bool shredderNotation = true; if (kingSquare == "f1" && StartingPieces["f10"] != null && StartingPieces["f10"] == BlackKing && ((StartingPieces["d1"] != null && StartingPieces["d1"].PieceType.Notation[0] == "Q") || (StartingPieces["e1"] != null && StartingPieces["e1"].PieceType.Notation[0] == "Q"))) { shredderNotation = false; } // STANDARD CASTLING - King slides three squares and corner piece jumps over to adjacent square if (Castling.Value == "Standard") { AddCastlingRule(); if (kingSquare == "f1") { CastlingMove(0, "f1", "i1", "j1", "h1", shredderNotation ? 'J' : 'K'); CastlingMove(0, "f1", "c1", "a1", "d1", shredderNotation ? 'A' : 'Q'); CastlingMove(1, "f10", "i10", "j10", "h10", shredderNotation ? 'j' : 'k'); CastlingMove(1, "f10", "c10", "a10", "d10", shredderNotation ? 'a' : 'q'); } else { CastlingMove(0, "e1", "b1", "a1", "c1", 'A'); CastlingMove(0, "e1", "h1", "j1", "i1", 'J'); CastlingMove(1, "e10", "b10", "a10", "c10", 'a'); CastlingMove(1, "e10", "h10", "j10", "i10", 'j'); } } // LONG CASTLING - King slides three squares to closer corner or four squares to // farther corner and the corner piece jumps over to adjacent square else if (Castling.Value == "Long") { AddCastlingRule(); if (kingSquare == "f1") { CastlingMove(0, "f1", "i1", "j1", "h1", shredderNotation ? 'J' : 'K'); CastlingMove(0, "f1", "b1", "a1", "c1", shredderNotation ? 'A' : 'Q'); CastlingMove(1, "f10", "i10", "j10", "h10", shredderNotation ? 'j' : 'k'); CastlingMove(1, "f10", "b10", "a10", "c10", shredderNotation ? 'a' : 'q'); } else { CastlingMove(0, "e1", "b1", "a1", "c1", 'A'); CastlingMove(0, "e1", "i1", "j1", "h1", 'J'); CastlingMove(1, "e10", "b10", "a10", "c10", 'a'); CastlingMove(1, "e10", "i10", "j10", "h10", 'j'); } } // FLEXIBLE CASTLING - King slides two or more squares (but must stop short of the // corner) and the corner piece jumps over to adjacent square else if (Castling.Value == "Flexible") { AddFlexibleCastlingRule(); if (kingSquare == "f1") { FlexibleCastlingMove(0, "f1", "h1", "j1", shredderNotation ? 'J' : 'K'); FlexibleCastlingMove(0, "f1", "d1", "a1", shredderNotation ? 'A' : 'Q'); FlexibleCastlingMove(1, "f10", "h10", "j10", shredderNotation ? 'j' : 'k'); FlexibleCastlingMove(1, "f10", "e10", "a10", shredderNotation ? 'a' : 'q'); } else { FlexibleCastlingMove(0, "e1", "c1", "a1", 'A'); FlexibleCastlingMove(0, "e1", "g1", "j1", 'J'); FlexibleCastlingMove(1, "e10", "c10", "a10", 'a'); FlexibleCastlingMove(1, "e10", "g10", "j10", 'j'); } } // CLOSE ROOK CASTLING - Castling pieces are on b1/b10 and i1/i10 rather than in the // corners. King slides two squares and castling piece jumps over to adjacent square. else if (Castling.Value == "Close-Rook") { AddCastlingRule(); if (kingSquare == "f1") { CastlingMove(0, "f1", "h1", "i1", "g1", 'I'); CastlingMove(0, "f1", "d1", "b1", "e1", 'B'); CastlingMove(1, "f10", "h10", "i10", "g10", 'i'); CastlingMove(1, "f10", "d10", "b10", "e10", 'b'); } else { CastlingMove(0, "e1", "c1", "b1", "d1", 'B'); CastlingMove(0, "e1", "g1", "i1", "f1", 'I'); CastlingMove(1, "e10", "c10", "b10", "d10", 'b'); CastlingMove(1, "e10", "g10", "i10", "f10", 'i'); } } // CLOSE-ROOK FLEXIBLE - King slides two or more squares to castle with the // piece on the b or i file (which jumps to the other side) else if (Castling.Value == "Close-Rook Flexible") { AddFlexibleCastlingRule(); if (kingSquare == "f1") { FlexibleCastlingMove(0, "f1", "h1", "i1", 'I'); FlexibleCastlingMove(0, "f1", "d1", "b1", 'B'); FlexibleCastlingMove(1, "f10", "h10", "i10", 'i'); FlexibleCastlingMove(1, "f10", "e10", "b10", 'b'); } else { FlexibleCastlingMove(0, "e1", "c1", "b1", 'B'); FlexibleCastlingMove(0, "e1", "g1", "i1", 'I'); FlexibleCastlingMove(1, "e10", "c10", "b10", 'b'); FlexibleCastlingMove(1, "e10", "g10", "i10", 'i'); } } } #endregion #region Second rank castling rules else // *** SECOND-RANK CASTLING TYPES *** // { // These are the eqivalents of the castling types above, but shifted onto the second rank // find the king's start square (must be e2 or f2) GenericPiece WhiteKing = new GenericPiece(0, CastlingType); GenericPiece BlackKing = new GenericPiece(1, CastlingType); string kingSquare; if (StartingPieces["e2"] == WhiteKing) { kingSquare = "e2"; } else if (StartingPieces["f2"] == WhiteKing) { kingSquare = "f2"; } else { throw new Exception("Can't enable castling rule because King does not start on a supported square"); } // Use Shredder-FEN notation? We will use Shredder-FEN notation unless the Kings start on f1/f8 // and a piece with a notation of Q starts on either e1 or d1 (for consistency with 10x8) // and the castling is with pieces in the corners (e.g., not Close-Rook castling.) bool shredderNotation = true; if (kingSquare == "f2" && StartingPieces["f9"] != null && StartingPieces["f9"] == BlackKing && ((StartingPieces["d2"] != null && StartingPieces["d2"].PieceType.Notation[0] == "Q") || (StartingPieces["e2"] != null && StartingPieces["e2"].PieceType.Notation[0] == "Q"))) { shredderNotation = false; } // 2R STANDARD CASTLING - King on second rank slides three squares and corner piece jumps over to adjacent square if (Castling.Value == "2R Standard") { AddCastlingRule(); if (kingSquare == "f2") { CastlingMove(0, "f2", "i2", "j2", "h2", shredderNotation ? 'J' : 'K'); CastlingMove(0, "f2", "c2", "a2", "d2", shredderNotation ? 'A' : 'Q'); CastlingMove(1, "f9", "i9", "j9", "h9", shredderNotation ? 'j' : 'k'); CastlingMove(1, "f9", "c9", "a9", "d9", shredderNotation ? 'a' : 'q'); } else { CastlingMove(0, "e2", "b2", "a2", "c2", 'A'); CastlingMove(0, "e2", "h2", "j2", "i2", 'J'); CastlingMove(1, "e9", "b9", "a9", "c9", 'a'); CastlingMove(1, "e9", "h9", "j9", "i9", 'j'); } } // 2R LONG CASTLING - King on second rank slides two squares to closer corner or three squares to // farther corner and the corner piece jumps over to adjacent square else if (Castling.Value == "2R Long") { AddCastlingRule(); if (kingSquare == "f2") { CastlingMove(0, "f2", "i2", "j2", "h2", shredderNotation ? 'J' : 'K'); CastlingMove(0, "f2", "b2", "a2", "c2", shredderNotation ? 'A' : 'Q'); CastlingMove(1, "f9", "i9", "j9", "h9", shredderNotation ? 'j' : 'k'); CastlingMove(1, "f9", "b9", "a9", "c9", shredderNotation ? 'a' : 'q'); } else { CastlingMove(0, "e2", "b2", "a2", "c2", 'A'); CastlingMove(0, "e2", "i2", "j2", "h2", 'J'); CastlingMove(1, "e9", "b9", "a9", "c9", 'a'); CastlingMove(1, "e9", "i9", "j9", "h9", 'j'); } } // 2R FLEXIBLE CASTLING - King on second rank slides two or more squares (but must stop short of the // corner) and the corner piece jumps over to adjacent square else if (Castling.Value == "2R Flexible") { AddFlexibleCastlingRule(); if (kingSquare == "f2") { FlexibleCastlingMove(0, "f2", "h2", "j2", shredderNotation ? 'J' : 'K'); FlexibleCastlingMove(0, "f2", "d2", "a2", shredderNotation ? 'A' : 'Q'); FlexibleCastlingMove(1, "f9", "h9", "j9", shredderNotation ? 'j' : 'k'); FlexibleCastlingMove(1, "f9", "d9", "a9", shredderNotation ? 'a' : 'q'); } else { FlexibleCastlingMove(0, "e2", "c2", "a2", 'A'); FlexibleCastlingMove(0, "e2", "g2", "j2", 'J'); FlexibleCastlingMove(1, "e9", "c9", "a9", 'a'); FlexibleCastlingMove(1, "e9", "g9", "j9", 'j'); } } // 2R CLOSE ROOK CASTLING - Castling pieces are on b1/b0 and i1/i0 rather than in the // corners. King on second rank slides two squares and castling piece jumps over to adjacent square. else if (Castling.Value == "2R Close-Rook") { AddCastlingRule(); if (kingSquare == "f2") { CastlingMove(0, "f2", "h2", "i2", "g2", 'I'); CastlingMove(0, "f2", "d2", "b2", "e2", 'B'); CastlingMove(1, "f9", "h9", "i9", "g9", 'i'); CastlingMove(1, "f9", "d9", "b9", "e9", 'b'); } else { CastlingMove(0, "e2", "c2", "b2", "d2", 'B'); CastlingMove(0, "e2", "g2", "i2", "f2", 'I'); CastlingMove(1, "e9", "c9", "b9", "d9", 'b'); CastlingMove(1, "e9", "g9", "i9", "f9", 'i'); } } // 2R CLOSE-ROOK FLEXIBLE - King on second rank slides two or more squares to castle with the // piece on the b or i file (which jumps to the other side) else if (Castling.Value == "2R Close-Rook Flexible") { AddFlexibleCastlingRule(); if (kingSquare == "f2") { FlexibleCastlingMove(0, "f2", "h2", "i2", 'I'); FlexibleCastlingMove(0, "f2", "d2", "b2", 'B'); FlexibleCastlingMove(1, "f9", "h9", "i9", 'i'); FlexibleCastlingMove(1, "f9", "e9", "b9", 'b'); } else { FlexibleCastlingMove(0, "e2", "c2", "b2", 'B'); FlexibleCastlingMove(0, "e2", "g2", "i2", 'I'); FlexibleCastlingMove(1, "e9", "c9", "b9", 'b'); FlexibleCastlingMove(1, "e9", "g9", "i9", 'i'); } } } #endregion } #endregion // *** PAWN PROMOTION *** // if (PromotionRule.Value == "Grand") { AddPromoteByReplacementRule(Pawn, loc => loc.Rank == 9 ? Rules.PromotionOption.MustPromote : (loc.Rank == 7 || loc.Rank == 8 ? Rules.PromotionOption.CanPromote : Rules.PromotionOption.CannotPromote)); } }
public override void AddRules() { // if we are using FRC type castling, temporarily set Castling // type to "None" when calling base class because they don't // support this and we will handle later string castlingValue = null; if (Castling.Value == "FRC" || Castling.Value == "Chess480") { castlingValue = Castling.Value; Castling.Value = "None"; } base.AddRules(); // *** CASTLING *** // if (castlingValue != null) { // restore castling settings now that base class has been called Castling.Value = castlingValue; // find the starting squares for the Kings and Rooks GenericPiece WhiteKing = new GenericPiece(0, King); GenericPiece WhiteRook = new GenericPiece(0, Rook); string leftRook = null; string king = null; string rightRook = null; for (int x = 0; x < 8; x++) { string square = Convert.ToChar('a' + x) + "1"; if (StartingPieces[square] == WhiteKing) { king = square; } else if (StartingPieces[square] == WhiteRook) { if (leftRook == null) { leftRook = square; } else { rightRook = square; } } } if (leftRook == null || rightRook == null) { return; } // add castling rules if (Castling.Value == "FRC") { AddCastlingRule(); CastlingMove(0, king, "c1", leftRook, "d1", Char.ToUpper(leftRook[0])); CastlingMove(0, king, "g1", rightRook, "f1", Char.ToUpper(rightRook[0])); leftRook = leftRook[0] + "8"; king = king[0] + "8"; rightRook = rightRook[0] + "8"; CastlingMove(1, king, "c8", leftRook, "d8", leftRook[0]); CastlingMove(1, king, "g8", rightRook, "f8", rightRook[0]); } else if (Castling.Value == "Chess480") { AddCastlingRule(); if (king == "b1") { CastlingMove(0, "b1", "a1", "a1", "b1", 'A'); CastlingMove(1, "b8", "a8", "a8", "b8", 'a'); } else { CastlingMove(0, king, Convert.ToChar(king[0] - 2) + "1", leftRook, Convert.ToChar(king[0] - 1) + "1", Char.ToUpper(leftRook[0])); CastlingMove(1, king[0] + "8", Convert.ToChar(king[0] - 2) + "8", leftRook[0] + "8", Convert.ToChar(king[0] - 1) + "8", leftRook[0]); } if (king == "g1") { CastlingMove(0, "g1", "h1", "h1", "g1", 'H'); CastlingMove(1, "g8", "h8", "h8", "g8", 'h'); } else { CastlingMove(0, king, Convert.ToChar(king[0] + 2) + "1", rightRook, Convert.ToChar(king[0] + 1) + "1", Char.ToUpper(rightRook[0])); CastlingMove(1, king[0] + "8", Convert.ToChar(king[0] + 2) + "8", rightRook[0] + "8", Convert.ToChar(king[0] + 1) + "8", rightRook[0]); } } } }
public override void AddRules() { base.AddRules(); // *** CASTLING *** // #region Castling // Only handle here if this is a castling type we defined if (Castling.Choices.IndexOf(Castling.Value) < Castling.Choices.IndexOf("None")) { #region First rank castling rules if (Castling.Value[0] != '2') { // The Kings must be centered on e1 and e10 GenericPiece WhiteKing = new GenericPiece(0, CastlingType); GenericPiece BlackKing = new GenericPiece(1, CastlingType); if (StartingPieces["e1"] != WhiteKing || StartingPieces["e10"] != BlackKing) { throw new Exception("Can't enable castling rule because King does not start on a supported square"); } // NOTE: we use Shredder-FEN notation exclusively (IAia) because with the king // centered, king-side and queen-side no longer have any meaning. // STANDARD CASTLING - King slides two squares and corner piece jumps over to adjacent square if (Castling.Value == "Standard") { AddCastlingRule(); CastlingMove(0, "e1", "c1", "a1", "d1", 'A'); CastlingMove(0, "e1", "g1", "i1", "f1", 'I'); CastlingMove(1, "e10", "c10", "a10", "d10", 'a'); CastlingMove(1, "e10", "g10", "i10", "f10", 'i'); } // LONG CASTLING - King slides three squares and corner piece jumps over to adjacent square else if (Castling.Value == "Long") { AddCastlingRule(); CastlingMove(0, "e1", "b1", "a1", "c1", 'A'); CastlingMove(0, "e1", "h1", "i1", "g1", 'I'); CastlingMove(1, "e10", "b10", "a10", "c10", 'a'); CastlingMove(1, "e10", "h10", "i10", "g10", 'i'); } // FLEXIBLE CASTLING - King slides two or more squares (but must stop short of the // corner) and the corner piece jumps over to adjacent square else if (Castling.Value == "Flexible") { AddFlexibleCastlingRule(); FlexibleCastlingMove(0, "e1", "c1", "a1", 'A'); FlexibleCastlingMove(0, "e1", "g1", "i1", 'I'); FlexibleCastlingMove(1, "e10", "c10", "a10", 'a'); FlexibleCastlingMove(1, "e10", "g10", "i10", 'i'); } // CLOSE-ROOK CASTLING - Castling pieces are on b1/b10 and h1/h10 rather than in the // corners. King slides two squares and castling piece jumps over to adjacent square. else if (Castling.Value == "Close-Rook") { AddCastlingRule(); CastlingMove(0, "e1", "c1", "b1", "d1", 'B'); CastlingMove(0, "e1", "g1", "h1", "f1", 'H'); CastlingMove(1, "e10", "c10", "b10", "d10", 'b'); CastlingMove(1, "e10", "g10", "h10", "f10", 'h'); } } #endregion #region Second rank castling rules else { // The Kings must be centered on e2 and e9 GenericPiece WhiteKing = new GenericPiece(0, CastlingType); GenericPiece BlackKing = new GenericPiece(1, CastlingType); if (StartingPieces["e2"] != WhiteKing || StartingPieces["e9"] != BlackKing) { throw new Exception("Can't enable castling rule because King does not start on a supported square"); } // 2R STANDARD CASTLING - King slides two squares and corner piece jumps over to adjacent square if (Castling.Value == "2R Standard") { AddCastlingRule(); CastlingMove(0, "e2", "c2", "a2", "d2", 'A'); CastlingMove(0, "e2", "g2", "i2", "f2", 'I'); CastlingMove(1, "e9", "c9", "a9", "d9", 'a'); CastlingMove(1, "e9", "g9", "i9", "f9", 'i'); } // 2R LONG CASTLING - King slides three squares and corner piece jumps over to adjacent square else if (Castling.Value == "2R Long") { AddCastlingRule(); CastlingMove(0, "e2", "b2", "a2", "c2", 'A'); CastlingMove(0, "e2", "h2", "i2", "g2", 'I'); CastlingMove(1, "e9", "b9", "a9", "c9", 'a'); CastlingMove(1, "e9", "h9", "i9", "g9", 'i'); } // 2R FLEXIBLE CASTLING - King slides two or more squares (but must stop short of the // corner) and the corner piece jumps over to adjacent square else if (Castling.Value == "2R Flexible") { AddFlexibleCastlingRule(); FlexibleCastlingMove(0, "e2", "c2", "a2", 'A'); FlexibleCastlingMove(0, "e2", "g2", "i2", 'I'); FlexibleCastlingMove(1, "e9", "c9", "a9", 'a'); FlexibleCastlingMove(1, "e9", "g9", "i9", 'i'); } // 2R CLOSE-ROOK CASTLING - Castling pieces are on b2/b9 and h2/h9 rather than in the // corners. King slides two squares and castling piece jumps over to adjacent square. else if (Castling.Value == "2R Close-Rook") { AddCastlingRule(); CastlingMove(0, "e2", "c2", "b2", "d2", 'B'); CastlingMove(0, "e2", "g2", "h2", "f2", 'H'); CastlingMove(1, "e9", "c9", "b9", "d9", 'b'); CastlingMove(1, "e9", "g9", "h9", "f9", 'h'); } } #endregion } #endregion }
public override void AddRules() { base.AddRules(); // *** CASTLING *** // #region Castling // Only handle here if this is a castling type we defined if (Castling.Choices.IndexOf(Castling.Value) < Castling.Choices.IndexOf("None")) { // find the king's start square, confirm the kings are centered on f1/f8 GenericPiece WhiteKing = new GenericPiece(0, CastlingType); GenericPiece BlackKing = new GenericPiece(1, CastlingType); if (StartingPieces["f1"] != WhiteKing || StartingPieces["f8"] != BlackKing) { throw new Exception("Can't enable castling rule because King does not start on a supported square"); } // STANDARD CASTLING - King slides three squares and corner piece jumps over to adjacent square if (Castling.Value == "Standard") { AddCastlingRule(); CastlingMove(0, "f1", "i1", "k1", "h1", 'K'); CastlingMove(0, "f1", "c1", "a1", "d1", 'A'); CastlingMove(1, "f8", "i8", "k8", "h8", 'k'); CastlingMove(1, "f8", "c8", "a8", "d8", 'a'); } // LONG CASTLING - King slides four squares and the corner piece jumps over to adjacent square else if (Castling.Value == "Long") { AddCastlingRule(); CastlingMove(0, "f1", "j1", "k1", "i1", 'K'); CastlingMove(0, "f1", "b1", "a1", "c1", 'A'); CastlingMove(1, "f8", "j8", "k8", "i8", 'k'); CastlingMove(1, "f8", "b8", "a8", "c8", 'a'); } // FLEXIBLE CASTLING - King slides two or more squares (but must stop short of the // corner) and the corner piece jumps over to adjacent square else if (Castling.Value == "Flexible") { AddFlexibleCastlingRule(); FlexibleCastlingMove(0, "f1", "h1", "k1", 'K'); FlexibleCastlingMove(0, "f1", "d1", "a1", 'A'); FlexibleCastlingMove(1, "f8", "h8", "k8", 'k'); FlexibleCastlingMove(1, "f8", "d8", "a8", 'a'); } // CLOSE-ROOK CASTLING - Castling pieces are on b1/b8 and j1/j8 rather than in the // corners. King slides three squares and castling piece jumps over to adjacent square. else if (Castling.Value == "Close-Rook") { AddCastlingRule(); CastlingMove(0, "f1", "i1", "j1", "h1", 'J'); CastlingMove(0, "f1", "c1", "b1", "d1", 'B'); CastlingMove(1, "f8", "i8", "j8", "h8", 'j'); CastlingMove(1, "f8", "c8", "b8", "d8", 'b'); } // CLOSE-ROOK FLEXIBLE - King slides two or more squares to castle with the piece on // the b or j file which then jumps over to adjacent square else if (Castling.Value == "Flexible") { AddFlexibleCastlingRule(); FlexibleCastlingMove(0, "f1", "h1", "j1", 'J'); FlexibleCastlingMove(0, "f1", "d1", "b1", 'B'); FlexibleCastlingMove(1, "f8", "h8", "j8", 'j'); FlexibleCastlingMove(1, "f8", "d8", "b8", 'b'); } } #endregion }
public override void AddRules() { base.AddRules(); // *** CASTLING *** // #region Castling // Only handle here if this is a castling type we defined if (Castling.Choices.IndexOf(Castling.Value) < Castling.Choices.IndexOf("None")) { // The Kings must start on e1 and e10. Ensure that is the case. GenericPiece WhiteKing = new GenericPiece(0, CastlingType); GenericPiece BlackKing = new GenericPiece(1, CastlingType); if (StartingPieces["e1"] != WhiteKing || StartingPieces["e8"] != BlackKing) { throw new Exception("Can't enable castling rule because King does not start on a supported square"); } // NOTE: We always use Shredder notation for castling privs. With the King // in the center of the board, it no longer makes sense to say King-side // or Queen-side // STANDARD CASTLING - King slides two squares and corner piece jumps over to adjacent square if (Castling.Value == "Standard") { AddCastlingRule(); CastlingMove(0, "e1", "c1", "a1", "d1", 'A'); CastlingMove(0, "e1", "g1", "i1", "f1", 'I'); CastlingMove(1, "e8", "c8", "a8", "d8", 'a'); CastlingMove(1, "e8", "g8", "i8", "f8", 'i'); } // LONG CASTLING - King slides three squares and corner piece jumps over to adjacent square else if (Castling.Value == "Long") { AddCastlingRule(); CastlingMove(0, "e1", "b1", "a1", "c1", 'A'); CastlingMove(0, "e1", "h1", "i1", "g1", 'I'); CastlingMove(1, "e8", "b8", "a8", "c8", 'a'); CastlingMove(1, "e8", "h8", "i8", "g8", 'i'); } // FLEXIBLE CASTLING - King slides two or more squares (but must stop short of the // corner) and the corner piece jumps over to adjacent square else if (Castling.Value == "Flexible") { AddFlexibleCastlingRule(); FlexibleCastlingMove(0, "e1", "c1", "a1", 'A'); FlexibleCastlingMove(0, "e1", "g1", "i1", 'I'); FlexibleCastlingMove(1, "e8", "c8", "a8", 'a'); FlexibleCastlingMove(1, "e8", "g8", "i8", 'i'); } // CLOSE-ROOK CASTLING - Castling pieces are on b1/b8 and h1/h8 rather than in the // corners. King slides two squares and castling piece jumps over to adjacent square. else if (Castling.Value == "Close-Rook") { AddCastlingRule(); CastlingMove(0, "e1", "c1", "b1", "d1", 'B'); CastlingMove(0, "e1", "g1", "h1", "f1", 'H'); CastlingMove(1, "e8", "c8", "b8", "d8", 'b'); CastlingMove(1, "e8", "g8", "h8", "f8", 'h'); } } #endregion }
public override void AddRules() { base.AddRules(); // *** CASTLING *** // #region Castling // Only handle here if this is a castling type we defined if (Castling.Choices.IndexOf(Castling.Value) < Castling.Choices.IndexOf("None")) { // find the king's start square (must be f1, f2, g1, or g2) GenericPiece WhiteKing = new GenericPiece(0, CastlingType); GenericPiece BlackKing = new GenericPiece(1, CastlingType); string whiteKingSquare = null; string blackKingSquare = null; if (Castling.Value[0] != '2') { if (StartingPieces["f1"] == WhiteKing) { whiteKingSquare = "f1"; } else if (StartingPieces["g1"] == WhiteKing) { whiteKingSquare = "g1"; } if (StartingPieces["f12"] == BlackKing) { blackKingSquare = "f12"; } else if (StartingPieces["g12"] == BlackKing) { blackKingSquare = "g12"; } } else { if (StartingPieces["f2"] == WhiteKing) { whiteKingSquare = "f2"; } else if (StartingPieces["g2"] == WhiteKing) { whiteKingSquare = "g2"; } if (StartingPieces["f11"] == BlackKing) { blackKingSquare = "f11"; } else if (StartingPieces["g11"] == BlackKing) { blackKingSquare = "g11"; } } if (whiteKingSquare == null || blackKingSquare == null) { throw new Exception("Can't enable castling rule because King does not start on a supported square"); } // FLEXIBLE CASTLING - King slides two or more squares (but must stop short of the // corner) and the corner piece jumps over to adjacent square if (Castling.Value == "Flexible") { AddFlexibleCastlingRule(); if (whiteKingSquare == "g1") { FlexibleCastlingMove(0, "g1", "i1", "l1", 'L'); FlexibleCastlingMove(0, "g1", "e1", "a1", 'A'); } else if (whiteKingSquare == "f1") { FlexibleCastlingMove(0, "f1", "d1", "a1", 'A'); FlexibleCastlingMove(0, "f1", "h1", "l1", 'L'); } else { throw new Exception("Can't enable castling rule with type 'Flexible' because King does not start on a supported square"); } if (blackKingSquare == "g12") { FlexibleCastlingMove(1, "g12", "i12", "l12", 'l'); FlexibleCastlingMove(1, "g12", "e12", "a12", 'a'); } else if (blackKingSquare == "f12") { FlexibleCastlingMove(1, "f12", "d12", "a12", 'a'); FlexibleCastlingMove(1, "f12", "h12", "l12", 'l'); } else { throw new Exception("Can't enable castling rule with type 'Flexible' because King does not start on a supported square"); } } // 2R FLEXIBLE CASTLING - King slides two or more squares (but must stop short of the // corner) and the edge piece jumps over to adjacent square else if (Castling.Value == "2R Flexible") { AddFlexibleCastlingRule(); if (whiteKingSquare == "g2") { FlexibleCastlingMove(0, "g2", "i2", "l2", 'L'); FlexibleCastlingMove(0, "g2", "e2", "a2", 'A'); } else if (whiteKingSquare == "f2") { FlexibleCastlingMove(0, "f2", "d2", "a2", 'A'); FlexibleCastlingMove(0, "f2", "h2", "l2", 'L'); } else { throw new Exception("Can't enable castling rule with type '2R Flexible' because King does not start on a supported square"); } if (blackKingSquare == "g11") { FlexibleCastlingMove(1, "g11", "i11", "l11", 'l'); FlexibleCastlingMove(1, "g11", "e11", "a11", 'a'); } else if (blackKingSquare == "f11") { FlexibleCastlingMove(1, "f11", "d11", "a11", 'a'); FlexibleCastlingMove(1, "f11", "h11", "l11", 'l'); } else { throw new Exception("Can't enable castling rule with type '2R Flexible' because King does not start on a supported square"); } } // CLOSE-ROOK FLEXIBLE CASTLING - King slides two or more squares (but must stop short of the // b or k file) and the piece on that file jumps over to adjacent square else if (Castling.Value == "Close-Rook Flexible") { AddFlexibleCastlingRule(); if (whiteKingSquare == "g1") { FlexibleCastlingMove(0, "g1", "i1", "k1", 'K'); FlexibleCastlingMove(0, "g1", "e1", "b1", 'B'); } else if (whiteKingSquare == "f1") { FlexibleCastlingMove(0, "f1", "d1", "b1", 'B'); FlexibleCastlingMove(0, "f1", "h1", "k1", 'K'); } else { throw new Exception("Can't enable castling rule with type 'Close-Rook Flexible' because King does not start on a supported square"); } if (blackKingSquare == "g12") { FlexibleCastlingMove(1, "g12", "i12", "k12", 'k'); FlexibleCastlingMove(1, "g12", "e12", "b12", 'b'); } else if (blackKingSquare == "f12") { FlexibleCastlingMove(1, "f12", "d12", "b12", 'b'); FlexibleCastlingMove(1, "f12", "h12", "k12", 'k'); } else { throw new Exception("Can't enable castling rule with type 'Close-Rook Flexible' because King does not start on a supported square"); } } // 2R CLOSE-ROOK FLEXIBLE CASTLING - King on the second rank slides two or more squares (but must stop // short of the b or k file) and the piece on that file jumps over to adjacent square else if (Castling.Value == "2R Close-Rook Flexible") { AddFlexibleCastlingRule(); if (whiteKingSquare == "g2") { FlexibleCastlingMove(0, "g2", "i2", "k2", 'K'); FlexibleCastlingMove(0, "g2", "e2", "b2", 'B'); } else if (whiteKingSquare == "f2") { FlexibleCastlingMove(0, "f2", "d2", "b2", 'B'); FlexibleCastlingMove(0, "f2", "h2", "k2", 'K'); } else { throw new Exception("Can't enable castling rule with type 'Close-Rook Flexible' because King does not start on a supported square"); } if (blackKingSquare == "g11") { FlexibleCastlingMove(1, "g11", "i11", "k11", 'k'); FlexibleCastlingMove(1, "g11", "e11", "b11", 'b'); } else if (blackKingSquare == "f11") { FlexibleCastlingMove(1, "f11", "d11", "b11", 'b'); FlexibleCastlingMove(1, "f11", "h11", "k11", 'k'); } else { throw new Exception("Can't enable castling rule with type 'Close-Rook Flexible' because King does not start on a supported square"); } } // ALL OTHER CASTLING TYPES else { // handle implementation of all other castling options by algorithm string rankPlayer0 = Castling.Value.IndexOf("2R") >= 0 ? "2" : "1"; string rankPlayer1 = Castling.Value.IndexOf("2R") >= 0 ? "11" : "12"; char file0Player0 = Castling.Value.IndexOf("Close-Rook") >= 0 ? 'B' : 'A'; char file1Player0 = Castling.Value.IndexOf("Close-Rook") >= 0 ? 'K' : 'L'; char file0Player1 = Castling.Value.IndexOf("Close-Rook") >= 0 ? 'b' : 'a'; char file1Player1 = Castling.Value.IndexOf("Close-Rook") >= 0 ? 'k' : 'l'; int shortDistance = Convert.ToInt32(Castling.Value.Substring(Castling.Value.Length - 3, 1)); int longDistance = Convert.ToInt32(Castling.Value.Substring(Castling.Value.Length - 1, 1)); AddCastlingRule(); if (whiteKingSquare[0] == 'g') { CastlingMove(0, "g" + rankPlayer0, (char)('g' + shortDistance) + rankPlayer0, file1Player1.ToString() + rankPlayer0, (char)('g' + shortDistance - 1) + rankPlayer0, file1Player0); CastlingMove(0, "g" + rankPlayer0, (char)('g' - longDistance) + rankPlayer0, file0Player1.ToString() + rankPlayer0, (char)('g' - longDistance + 1) + rankPlayer0, file0Player0); } else { CastlingMove(0, "f" + rankPlayer0, (char)('f' + longDistance) + rankPlayer0, file1Player1.ToString() + rankPlayer0, (char)('f' + longDistance - 1) + rankPlayer0, file1Player0); CastlingMove(0, "f" + rankPlayer0, (char)('f' - shortDistance) + rankPlayer0, file0Player1.ToString() + rankPlayer0, (char)('f' - shortDistance + 1) + rankPlayer0, file0Player0); } if (blackKingSquare[0] == 'g') { CastlingMove(1, "g" + rankPlayer1, (char)('g' + shortDistance) + rankPlayer1, file1Player1.ToString() + rankPlayer1, (char)('g' + shortDistance - 1) + rankPlayer1, file1Player1); CastlingMove(1, "g" + rankPlayer1, (char)('g' - longDistance) + rankPlayer1, file0Player1.ToString() + rankPlayer1, (char)('g' - longDistance + 1) + rankPlayer1, file0Player1); } else { CastlingMove(1, "f" + rankPlayer1, (char)('f' + longDistance) + rankPlayer1, file1Player1.ToString() + rankPlayer1, (char)('f' + longDistance - 1) + rankPlayer1, file1Player1); CastlingMove(1, "f" + rankPlayer1, (char)('f' - shortDistance) + rankPlayer1, file0Player1.ToString() + rankPlayer1, (char)('f' - shortDistance + 1) + rankPlayer1, file0Player1); } } } #endregion }
public override void AddRules() { base.AddRules(); // *** CASTLING *** // #region Castling // Only handle here if this is a castling type we defined if (Castling.Choices.IndexOf(Castling.Value) < Castling.Choices.IndexOf("None")) { // Adding castling rule is somewhat complicated because there are a number of different forms // of castilng and we have to accomodate the King on either e1 or f1 as well as the fact that // the FEN notation, (typically KQkq), for King-side or Queen-side might be inappropriate, // in which case we use Shredder-FEN notation where the priv char is the file of the rook // find the king's start square (must be e1 or f1) GenericPiece WhiteKing = new GenericPiece(0, CastlingType); GenericPiece BlackKing = new GenericPiece(1, CastlingType); bool supported = false; string kingSquare = null; if (StartingPieces["e1"] == WhiteKing) { kingSquare = "e1"; if (StartingPieces["e8"] == BlackKing) { supported = true; } } else if (StartingPieces["f1"] == WhiteKing) { kingSquare = "f1"; if (StartingPieces["f8"] == BlackKing) { supported = true; } } if (!supported) { throw new Exception("Can't enable castling rule because King does not start on a supported square"); } // Use Shredder-FEN notation? We will use Shredder-FEN notation unless the Kings start on f1/f8 // and a piece with a notation of Q starts on either e1 or d1 (to accomodate Capablanca and Gothic // which have already been defined to use non-Shredder notation. I would have preferred all Shredder. // And Shredder notation is always used if castling with a piece not in the corners (e.g., Close-Rook.) bool shredderNotation = true; if (kingSquare == "f1" && StartingPieces["f8"] != null && StartingPieces["f8"] == BlackKing && ((StartingPieces["d1"] != null && StartingPieces["d1"].PieceType.Notation[0] == "Q") || (StartingPieces["e1"] != null && StartingPieces["e1"].PieceType.Notation[0] == "Q"))) { shredderNotation = false; } // STANDARD CASTLING - King slides three squares and corner piece jumps over to adjacent square if (Castling.Value == "Standard") { AddCastlingRule(); if (kingSquare == "f1") { CastlingMove(0, "f1", "i1", "j1", "h1", shredderNotation ? 'J' : 'K'); CastlingMove(0, "f1", "c1", "a1", "d1", shredderNotation ? 'A' : 'Q'); CastlingMove(1, "f8", "i8", "j8", "h8", shredderNotation ? 'j' : 'k'); CastlingMove(1, "f8", "c8", "a8", "d8", shredderNotation ? 'a' : 'q'); } else { CastlingMove(0, "e1", "b1", "a1", "c1", 'A'); CastlingMove(0, "e1", "h1", "j1", "g1", 'J'); CastlingMove(1, "e8", "b8", "a8", "c8", 'a'); CastlingMove(1, "e8", "h8", "j8", "g8", 'j'); } } // LONG CASTLING - King slides three squares to closer corner or four squares to // farther corner and the corner piece jumps over to adjacent square else if (Castling.Value == "Long") { AddCastlingRule(); if (kingSquare == "f1") { CastlingMove(0, "f1", "i1", "j1", "h1", shredderNotation ? 'J' : 'K'); CastlingMove(0, "f1", "b1", "a1", "c1", shredderNotation ? 'A' : 'Q'); CastlingMove(1, "f8", "i8", "j8", "h8", shredderNotation ? 'j' : 'k'); CastlingMove(1, "f8", "b8", "a8", "c8", shredderNotation ? 'a' : 'q'); } else { CastlingMove(0, "e1", "b1", "a1", "c1", 'A'); CastlingMove(0, "e1", "i1", "j1", "h1", 'J'); CastlingMove(1, "e8", "b8", "a8", "c8", 'a'); CastlingMove(1, "e8", "i8", "j8", "h8", 'j'); } } // FLEXIBLE CASTLING - King slides two or more squares (but must stop short of the // corner) and the corner piece jumps over to adjacent square else if (Castling.Value == "Flexible") { AddFlexibleCastlingRule(); if (kingSquare == "f1") { FlexibleCastlingMove(0, "f1", "h1", "j1", shredderNotation ? 'J' : 'K'); FlexibleCastlingMove(0, "f1", "d1", "a1", shredderNotation ? 'A' : 'Q'); FlexibleCastlingMove(1, "f8", "h8", "j8", shredderNotation ? 'j' : 'k'); FlexibleCastlingMove(1, "f8", "d8", "a8", shredderNotation ? 'a' : 'q'); } else { FlexibleCastlingMove(0, "e1", "c1", "a1", 'A'); FlexibleCastlingMove(0, "e1", "g1", "j1", 'J'); FlexibleCastlingMove(1, "e8", "c8", "a8", 'a'); FlexibleCastlingMove(1, "e8", "g8", "j8", 'j'); } } // CLOSE ROOK CASTLING - Castling pieces are on b1/b8 and i1/i8 rather than in the // corners. King slides two squares and castling piece jumps over to adjacent square. else if (Castling.Value == "Close-Rook") { AddCastlingRule(); if (kingSquare == "f1") { CastlingMove(0, "f1", "h1", "i1", "g1", 'I'); CastlingMove(0, "f1", "d1", "b1", "e1", 'B'); CastlingMove(1, "f8", "h8", "i8", "g8", 'i'); CastlingMove(1, "f8", "d8", "b8", "e8", 'b'); } else { CastlingMove(0, "e1", "c1", "b1", "d1", 'B'); CastlingMove(0, "e1", "g1", "i1", "f1", 'I'); CastlingMove(1, "e8", "c8", "b8", "d8", 'b'); CastlingMove(1, "e8", "g8", "i8", "f8", 'i'); } } // CLOSE-ROOK FLEXIBLE - King slides two or more squares to castle with // the piece on the b or i file (which jumps to the other side) else if (Castling.Value == "Close-Rook Flexible") { AddFlexibleCastlingRule(); if (kingSquare == "f1") { FlexibleCastlingMove(0, "f1", "h1", "i1", 'I'); FlexibleCastlingMove(0, "f1", "d1", "b1", 'B'); FlexibleCastlingMove(1, "f8", "h8", "i8", 'i'); FlexibleCastlingMove(1, "f8", "d8", "b8", 'b'); } else { FlexibleCastlingMove(0, "e1", "c1", "b1", 'B'); FlexibleCastlingMove(0, "e1", "g1", "i1", 'I'); FlexibleCastlingMove(1, "e8", "c8", "b8", 'b'); FlexibleCastlingMove(1, "e8", "g8", "i8", 'i'); } } } #endregion }
public override void AddRules() { base.AddRules(); // *** CASTLING *** // #region Castling // Only handle here if this is a castling type we defined if (Castling.Choices.IndexOf(Castling.Value) < Castling.Choices.IndexOf("None")) { // find the king's start square (must be f1) GenericPiece WhiteKing = new GenericPiece(0, CastlingType); GenericPiece BlackKing = new GenericPiece(1, CastlingType); if (StartingPieces["f1"] != WhiteKing || StartingPieces["f10"] != BlackKing) { throw new Exception("Can't enable castling rule because King does not start on a supported square"); } // STANDARD CASTLING - King slides three squares and corner piece jumps over to adjacent square if (Castling.Value == "Standard") { AddCastlingRule(); CastlingMove(0, "f1", "i1", "k1", "h1", 'K'); CastlingMove(0, "f1", "c1", "a1", "d1", 'A'); CastlingMove(1, "f10", "i10", "k10", "h10", 'k'); CastlingMove(1, "f10", "c10", "a10", "d10", 'a'); } // LONG CASTLING - King slides four squares and the corner piece jumps over to adjacent square else if (Castling.Value == "Long") { AddCastlingRule(); CastlingMove(0, "f1", "j1", "k1", "i1", 'K'); CastlingMove(0, "f1", "b1", "a1", "c1", 'A'); CastlingMove(1, "f10", "j10", "k10", "i10", 'k'); CastlingMove(1, "f10", "b10", "a10", "c10", 'a'); } // FLEXIBLE Castilng - King starts in center and can slide 2, 3 or 4 squares // toward the castling piece on the corner square which hops to the other side else if (Castling.Value == "Flexible") { AddFlexibleCastlingRule(); FlexibleCastlingMove(0, "f1", "h1", "k1", 'K'); FlexibleCastlingMove(0, "f1", "d1", "a1", 'A'); FlexibleCastlingMove(1, "f10", "h10", "k10", 'k'); FlexibleCastlingMove(1, "f10", "d10", "a10", 'a'); } // CLOSE-ROOK CASTLING - Castling pieces are on b1/b10 and j1/j10 rather than in the // corners. King slides three squares and castling piece jumps over to adjacent square. else if (Castling.Value == "Close-Rook") { AddCastlingRule(); CastlingMove(0, "f1", "i1", "j1", "h1", 'J'); CastlingMove(0, "f1", "c1", "b1", "d1", 'B'); CastlingMove(1, "f10", "i10", "j10", "h10", 'j'); CastlingMove(1, "f10", "c10", "b10", "d10", 'b'); } // WILDEBEEST Castling - the castling rule from Wildebeest Chess. The King slides // one to four spaces toward the rook and the rook jumps over to the adjacent square else if (Castling.Value == "Wildebeest") { AddFlexibleCastlingRule(); FlexibleCastlingMove(0, "f1", "g1", "k1", 'K'); FlexibleCastlingMove(0, "f1", "e1", "a1", 'A'); FlexibleCastlingMove(1, "f10", "g10", "k10", 'k'); FlexibleCastlingMove(1, "f10", "e10", "a10", 'a'); } // CLOSE-ROOK FLEXIBLE - King starts in center and can slide 2 or 3 squares // toward the castling piece on the b or j file which hops to the other side else if (Castling.Value == "Close-Rook Flexible") { AddFlexibleCastlingRule(); FlexibleCastlingMove(0, "f1", "h1", "j1", 'J'); FlexibleCastlingMove(0, "f1", "d1", "b1", 'B'); FlexibleCastlingMove(1, "f10", "h10", "j10", 'j'); FlexibleCastlingMove(1, "f10", "d10", "b10", 'b'); } // 2R STANDARD CASTLING - King slides three squares and edge piece jumps over to adjacent square else if (Castling.Value == "2R Standard") { AddCastlingRule(); CastlingMove(0, "f2", "i2", "k2", "h2", 'K'); CastlingMove(0, "f2", "c2", "a2", "d2", 'A'); CastlingMove(1, "f9", "i9", "k9", "h9", 'k'); CastlingMove(1, "f9", "c9", "a9", "d9", 'a'); } // 2R LONG CASTLING - King slides four squares and the edge piece jumps over to adjacent square else if (Castling.Value == "2R Long") { AddCastlingRule(); CastlingMove(0, "f2", "j2", "k2", "i2", 'K'); CastlingMove(0, "f2", "b2", "a2", "c2", 'A'); CastlingMove(1, "f9", "j9", "k9", "i9", 'k'); CastlingMove(1, "f9", "b9", "a9", "c9", 'a'); } // 2R FLEXIBLE Castilng - King starts in center and can slide 2, 3 or 4 squares // toward the castling piece on the edge square which hops to the other side else if (Castling.Value == "2R Flexible") { AddFlexibleCastlingRule(); FlexibleCastlingMove(0, "f2", "h2", "k2", 'K'); FlexibleCastlingMove(0, "f2", "d2", "a2", 'A'); FlexibleCastlingMove(1, "f9", "h9", "k9", 'k'); FlexibleCastlingMove(1, "f9", "d9", "a9", 'a'); } // 2R CLOSE-ROOK CASTLING - Castling pieces are on b2/b9 and j2/j9 rather than in the // corners. King slides three squares and castling piece jumps over to adjacent square. else if (Castling.Value == "2R Close-Rook") { AddCastlingRule(); CastlingMove(0, "f2", "i2", "j2", "h2", 'J'); CastlingMove(0, "f2", "c2", "b2", "d2", 'B'); CastlingMove(1, "f9", "i9", "j9", "h9", 'j'); CastlingMove(1, "f9", "c9", "b9", "d9", 'b'); } // 2R WILDEBEEST Castling - the castling rule from Wildebeest Chess. The King slides // one to four spaces toward the rook and the rook jumps over to the adjacent square else if (Castling.Value == "2R Wildebeest") { AddFlexibleCastlingRule(); FlexibleCastlingMove(0, "f2", "g2", "k2", 'K'); FlexibleCastlingMove(0, "f2", "e2", "a2", 'A'); FlexibleCastlingMove(1, "f9", "g9", "k9", 'k'); FlexibleCastlingMove(1, "f9", "e9", "a9", 'a'); } // 2R CLOSE-ROOK FLEXIBLE - Castling pieces are on b2/b9 and j2/j9 rather than in the // corners. King slides 2 or 3 squares and castling piece jumps over to adjacent square. else if (Castling.Value == "2R Close-Rook Flexible") { AddFlexibleCastlingRule(); FlexibleCastlingMove(0, "f2", "h2", "j2", 'J'); FlexibleCastlingMove(0, "f2", "d2", "b2", 'B'); FlexibleCastlingMove(1, "f9", "h9", "j9", 'j'); FlexibleCastlingMove(1, "f9", "d9", "b9", 'b'); } } #endregion }
public override void AddRules() { base.AddRules(); // *** CASTLING *** // #region Castling // Only handle here if this is a castling type we defined if (Castling.Choices.IndexOf(Castling.Value) < Castling.Choices.IndexOf("None")) { // Adding castling rule is somewhat complicated because there are a number of different forms // of castilng and we have to accomodate the King on either e1 or f1 as well as the fact that // the FEN notation, (typically KQkq), for King-side or Queen-side might be inappropriate, // in which case we use Shredder-FEN notation where the priv char is the file of the rook // find the king's start square (must be e1 or f1) GenericPiece WhiteKing = new GenericPiece(0, CastlingType); GenericPiece BlackKing = new GenericPiece(1, CastlingType); bool supported = false; string kingSquare = null; if (StartingPieces["e1"] == WhiteKing) { kingSquare = "e1"; if (StartingPieces["e9"] == BlackKing) { supported = true; } } else if (StartingPieces["f1"] == WhiteKing) { kingSquare = "f1"; if (StartingPieces["f9"] == BlackKing) { supported = true; } } if (!supported) { throw new Exception("Can't enable castling rule because King does not start on a supported square"); } // STANDARD CASTLING - King slides three squares and corner piece jumps over to adjacent square if (Castling.Value == "Standard") { AddCastlingRule(); if (kingSquare == "f1") { CastlingMove(0, "f1", "i1", "j1", "h1", 'J'); CastlingMove(0, "f1", "c1", "a1", "d1", 'A'); CastlingMove(1, "f9", "i9", "j9", "h9", 'j'); CastlingMove(1, "f9", "c9", "a9", "d9", 'a'); } else { CastlingMove(0, "e1", "b1", "a1", "c1", 'A'); CastlingMove(0, "e1", "h1", "j1", "g1", 'J'); CastlingMove(1, "e9", "b9", "a9", "c9", 'a'); CastlingMove(1, "e9", "h9", "j9", "g9", 'j'); } } // LONG CASTLING - King slides three squares to closer corner or four squares to // farther corner and the corner piece jumps over to adjacent square else if (Castling.Value == "Long") { AddCastlingRule(); if (kingSquare == "f1") { CastlingMove(0, "f1", "i1", "j1", "h1", 'J'); CastlingMove(0, "f1", "b1", "a1", "c1", 'A'); CastlingMove(1, "f9", "i9", "j9", "h9", 'j'); CastlingMove(1, "f9", "b9", "a9", "c9", 'a'); } else { CastlingMove(0, "e1", "b1", "a1", "c1", 'A'); CastlingMove(0, "e1", "i1", "j1", "h1", 'J'); CastlingMove(1, "e9", "b9", "a9", "c9", 'a'); CastlingMove(1, "e9", "i9", "j9", "h9", 'j'); } } // FLEXIBLE CASTLING - King slides two or more squares (but must stop short of the // corner) and the corner piece jumps over to adjacent square else if (Castling.Value == "Flexible") { AddFlexibleCastlingRule(); if (kingSquare == "f1") { FlexibleCastlingMove(0, "f1", "h1", "j1", 'J'); FlexibleCastlingMove(0, "f1", "d1", "a1", 'A'); FlexibleCastlingMove(1, "f9", "h9", "j9", 'j'); FlexibleCastlingMove(1, "f9", "d9", "a9", 'a'); } else { FlexibleCastlingMove(0, "e1", "c1", "a1", 'A'); FlexibleCastlingMove(0, "e1", "g1", "j1", 'J'); FlexibleCastlingMove(1, "e9", "c9", "a9", 'a'); FlexibleCastlingMove(1, "e9", "g9", "j9", 'j'); } } // CLOSE ROOK CASTLING - Castling pieces are on b1/b9 and i1/i9 rather than in the // corners. King slides two squares and castling piece jumps over to adjacent square. else if (Castling.Value == "Close-Rook") { AddCastlingRule(); if (kingSquare == "f1") { CastlingMove(0, "f1", "h1", "i1", "g1", 'I'); CastlingMove(0, "f1", "d1", "b1", "e1", 'B'); CastlingMove(1, "f9", "h9", "i9", "g9", 'i'); CastlingMove(1, "f9", "d9", "b9", "e9", 'b'); } else { CastlingMove(0, "e1", "c1", "b1", "d1", 'B'); CastlingMove(0, "e1", "g1", "i1", "f1", 'I'); CastlingMove(1, "e9", "c9", "b9", "d9", 'b'); CastlingMove(1, "e9", "g9", "i9", "f9", 'i'); } } // CLOSE-ROOK FLEXIBLE - King slides two or more squares to castle with // the piece on the b or i file (which jumps to the other side) else if (Castling.Value == "Close-Rook Flexible") { AddFlexibleCastlingRule(); if (kingSquare == "f1") { FlexibleCastlingMove(0, "f1", "h1", "i1", 'I'); FlexibleCastlingMove(0, "f1", "d1", "b1", 'B'); FlexibleCastlingMove(1, "f9", "h9", "i9", 'i'); FlexibleCastlingMove(1, "f9", "d9", "b9", 'b'); } else { FlexibleCastlingMove(0, "e1", "c1", "b1", 'B'); FlexibleCastlingMove(0, "e1", "g1", "i1", 'I'); FlexibleCastlingMove(1, "e9", "c9", "b9", 'b'); FlexibleCastlingMove(1, "e9", "g9", "i9", 'i'); } } } #endregion }
public override void AddRules() { base.AddRules(); // *** CASTLING *** // #region Castling // Only handle here if this is a castling type we defined if (Castling.Choices.IndexOf(Castling.Value) < Castling.Choices.IndexOf("None")) { // Adding castling rule is somewhat complicated because there are a number of different forms // of castilng and we have to accomodate the King on either f1 or g1. On 12x8 we always use // shredder notation for castling though. // find the king's start square (must be f1 or g1) GenericPiece WhiteKing = new GenericPiece(0, CastlingType); GenericPiece BlackKing = new GenericPiece(1, CastlingType); string whiteKingSquare = null; string blackKingSquare = null; if (StartingPieces["f1"] == WhiteKing) { whiteKingSquare = "f1"; } else if (StartingPieces["g1"] == WhiteKing) { whiteKingSquare = "g1"; } if (StartingPieces["f8"] == BlackKing) { blackKingSquare = "f8"; } else if (StartingPieces["g8"] == BlackKing) { blackKingSquare = "g8"; } if (whiteKingSquare == null || blackKingSquare == null) { throw new Exception("Can't enable castling rule because King does not start on a supported square"); } // FLEXIBLE CASTLING - King slides two or more squares towards the corner // and the corner piece leaps to the square immediately to the other side if (Castling.Value == "Flexible") { AddFlexibleCastlingRule(); if (whiteKingSquare == "g1") { FlexibleCastlingMove(0, "g1", "i1", "l1", 'L'); FlexibleCastlingMove(0, "g1", "e1", "a1", 'A'); } else { FlexibleCastlingMove(0, "f1", "d1", "a1", 'A'); FlexibleCastlingMove(0, "f1", "h1", "l1", 'L'); } if (blackKingSquare == "g8") { FlexibleCastlingMove(1, "g8", "i8", "l8", 'l'); FlexibleCastlingMove(1, "g8", "e8", "a8", 'a'); } else { FlexibleCastlingMove(1, "f8", "d8", "a8", 'a'); FlexibleCastlingMove(1, "f8", "h8", "l8", 'l'); } } // CLOSE-ROOK FLEXIBLE CASTLING - King slides two or more squares towards the // b or k file and that piece leaps to the square immediately to the other side else if (Castling.Value == "Close-Rook Flexible") { AddFlexibleCastlingRule(); if (whiteKingSquare == "g1") { FlexibleCastlingMove(0, "g1", "i1", "k1", 'K'); FlexibleCastlingMove(0, "g1", "e1", "b1", 'B'); } else { FlexibleCastlingMove(0, "f1", "d1", "b1", 'B'); FlexibleCastlingMove(0, "f1", "h1", "k1", 'K'); } if (blackKingSquare == "g8") { FlexibleCastlingMove(1, "g8", "i8", "k8", 'k'); FlexibleCastlingMove(1, "g8", "e8", "b8", 'b'); } else { FlexibleCastlingMove(1, "f8", "d8", "b8", 'b'); FlexibleCastlingMove(1, "f8", "h8", "k8", 'k'); } } else { // handle implementation of all other castling options by algorithm bool closeRook = Castling.Value.IndexOf("Close-Rook") >= 0; int shortDistance = Convert.ToInt32(Castling.Value.Substring(Castling.Value.Length - 3, 1)); int longDistance = Convert.ToInt32(Castling.Value.Substring(Castling.Value.Length - 1, 1)); AddCastlingRule(); if (!closeRook) { if (whiteKingSquare == "g1") { CastlingMove(0, "g1", (char)('g' + shortDistance) + "1", "l1", (char)('g' + shortDistance - 1) + "1", 'L'); CastlingMove(0, "g1", (char)('g' - longDistance) + "1", "a1", (char)('g' - longDistance + 1) + "1", 'A'); } else { CastlingMove(0, "f1", (char)('f' + longDistance) + "1", "l1", (char)('f' + longDistance - 1) + "1", 'L'); CastlingMove(0, "f1", (char)('f' - shortDistance) + "1", "a1", (char)('f' - shortDistance + 1) + "1", 'A'); } if (blackKingSquare == "g8") { CastlingMove(1, "g8", (char)('g' + shortDistance) + "8", "l8", (char)('g' + shortDistance - 1) + "8", 'l'); CastlingMove(1, "g8", (char)('g' - longDistance) + "8", "a8", (char)('g' - longDistance + 1) + "8", 'a'); } else { CastlingMove(1, "f8", (char)('f' + longDistance) + "8", "l8", (char)('f' + longDistance - 1) + "8", 'l'); CastlingMove(1, "f8", (char)('f' - shortDistance) + "8", "a8", (char)('f' - shortDistance + 1) + "8", 'a'); } } else { { if (whiteKingSquare == "g1") { CastlingMove(0, "g1", (char)('g' + shortDistance) + "1", "k1", (char)('g' + shortDistance - 1) + "1", 'K'); CastlingMove(0, "g1", (char)('g' - longDistance) + "1", "b1", (char)('g' - longDistance + 1) + "1", 'B'); } else { CastlingMove(0, "f1", (char)('f' + longDistance) + "1", "k1", (char)('f' + longDistance - 1) + "1", 'K'); CastlingMove(0, "f1", (char)('f' - shortDistance) + "1", "b1", (char)('f' - shortDistance + 1) + "1", 'B'); } if (blackKingSquare == "g8") { CastlingMove(1, "g8", (char)('g' + shortDistance) + "8", "k8", (char)('g' + shortDistance - 1) + "8", 'k'); CastlingMove(1, "g8", (char)('g' - longDistance) + "8", "b8", (char)('g' - longDistance + 1) + "8", 'b'); } else { CastlingMove(1, "f8", (char)('f' + longDistance) + "8", "k8", (char)('f' + longDistance - 1) + "8", 'k'); CastlingMove(1, "f8", (char)('f' - shortDistance) + "8", "b8", (char)('f' - shortDistance + 1) + "8", 'b'); } } } } } #endregion }
public override void AddRules() { base.AddRules(); // *** CASTLING *** // #region Castling // Only handle here if this is a castling type we defined if (Castling.Choices.IndexOf(Castling.Value) < Castling.Choices.IndexOf("None")) { // We will accomodate the king starting on either d1 or e1. // The FEN privilege notation KQkq will be used if the kings // start on e1/e8 and the d1 piece has a 'Q' notation. // Otherwise, we will use Shredder-FEN notation (HAha) // find the king's start square (must be d1 or e1) GenericPiece WhiteKing = new GenericPiece(0, CastlingType); GenericPiece BlackKing = new GenericPiece(1, CastlingType); string kingSquare; if (StartingPieces["d1"] == WhiteKing) { kingSquare = "d1"; } else if (StartingPieces["e1"] == WhiteKing) { kingSquare = "e1"; } else { throw new Exception("Can't enable castling rule because King does not start on a supported square"); } // Use Shredder-FEN notation? bool shredderNotation = true; if (kingSquare == "e1" && StartingPieces["e8"] != null && StartingPieces["e8"] == BlackKing && StartingPieces["d1"] != null && StartingPieces["d1"].PieceType.Notation[0] == "Q") { shredderNotation = false; } // STANDARD CASTLING - King slides two squares and corner piece jumps over to adjacent square if (Castling.Value == "Standard") { AddCastlingRule(); if (kingSquare == "e1") { CastlingMove(0, "e1", "g1", "h1", "f1", shredderNotation ? 'H' : 'K'); CastlingMove(0, "e1", "c1", "a1", "d1", shredderNotation ? 'A' : 'Q'); CastlingMove(1, "e8", "g8", "h8", "f8", shredderNotation ? 'h' : 'k'); CastlingMove(1, "e8", "c8", "a8", "d8", shredderNotation ? 'a' : 'q'); } else { CastlingMove(0, "d1", "f1", "h1", "e1", 'H'); CastlingMove(0, "d1", "b1", "a1", "c1", 'A'); CastlingMove(1, "d8", "f8", "h8", "e8", 'h'); CastlingMove(1, "d8", "b8", "a8", "c8", 'a'); } } // LONG CASTLING - King slides two squares to closer corner or three squares to // farther corner and the corner piece jumps over to adjacent square else if (Castling.Value == "Long") { AddCastlingRule(); if (kingSquare == "e1") { CastlingMove(0, "e1", "g1", "h1", "f1", shredderNotation ? 'H' : 'K'); CastlingMove(0, "e1", "b1", "a1", "c1", shredderNotation ? 'A' : 'Q'); CastlingMove(1, "e8", "g8", "h8", "f8", shredderNotation ? 'h' : 'k'); CastlingMove(1, "e8", "b8", "a8", "c8", shredderNotation ? 'a' : 'q'); } else { CastlingMove(0, "d1", "g1", "h1", "f1", 'H'); CastlingMove(0, "d1", "b1", "a1", "c1", 'A'); CastlingMove(1, "d8", "g8", "h8", "f8", 'h'); CastlingMove(1, "d8", "b8", "a8", "c8", 'a'); } } // FLEXIBLE CASTLING - King slides two or more squares (but must stop short of the // corner) and the corner piece jumps over to adjacent square else if (Castling.Value == "Flexible") { AddFlexibleCastlingRule(); if (kingSquare == "e1") { FlexibleCastlingMove(0, "e1", "g1", "h1", shredderNotation ? 'H' : 'K'); FlexibleCastlingMove(0, "e1", "c1", "a1", shredderNotation ? 'A' : 'Q'); FlexibleCastlingMove(1, "e8", "g8", "h8", shredderNotation ? 'h' : 'k'); FlexibleCastlingMove(1, "e8", "c8", "a8", shredderNotation ? 'a' : 'q'); } else { FlexibleCastlingMove(0, "d1", "f1", "h1", 'H'); FlexibleCastlingMove(0, "d1", "b1", "a1", 'A'); FlexibleCastlingMove(1, "d8", "f8", "h8", 'h'); FlexibleCastlingMove(1, "d8", "b8", "a8", 'a'); } } } #endregion }
public override void PostInitialize() { base.PostInitialize(); // We will set the values of the properties to what we believe // are reasonable values based on examination of the Game and // its PieceTypes. We will only set these values if they are // still unset so that individual games can tweek the values if // they choose without us overwriting them here. // first, determine the total number of pieces on board at game start int gameStartPieceCount = 0; for (int player = 0; player < game.NumPlayers; player++) { gameStartPieceCount += game.StartingPieceCount[player]; } // *** OPENING THRESHOLDS *** // // The values for OpeningTransitionThreshold and // OpeningCompleteThreshold determine when we start phasing // out the development bonus/penalty and when it is completely // phased out, respectively, based on OpeningProgress. if (OpeningTransitionThreshold == 0) { OpeningTransitionThreshold = gameStartPieceCount / 4 + 1; } if (OpeningCompleteThreshold == 0) { OpeningCompleteThreshold = OpeningTransitionThreshold * 2 - 2; } // *** PAWN STUFF *** // // Determine if we have a standard pawn in this game, and // if so, what's the farthest square it can reach on first move. if (PawnPieceType == -1) { for (int nPieceType = 0; nPieceType < game.NPieceTypes; nPieceType++) { if (game.GetPieceType(nPieceType).IsPawn) { PawnPieceType = game.GetPieceType(nPieceType).TypeNumber; } } } if (PawnPieceType >= 0 && PawnMaxRankFirstMove == 0) { // first, determine the max steps of the pawn's longest move int maxSteps = 0; MoveCapability[] moves; int nMoves = game.GetPieceType(PawnPieceType).GetMoveCapabilities(out moves); for (int x = 0; x < nMoves; x++) { if (moves[x].MaxSteps > maxSteps) { maxSteps = moves[x].MaxSteps; } } // now find the farthest rank on which a pawn begins int maxRank = 0; foreach (KeyValuePair <string, GenericPiece> pair in game.StartingPieces) { GenericPiece piece = pair.Value; if (piece != null && piece.PieceType.TypeNumber == PawnPieceType) { int rank = game.Board.GetRank(game.Board.PlayerSquare( piece.Player, game.NotationToSquare(pair.Key))); if (rank > maxRank) { maxRank = rank; } } } // the max rank a pawn can reach on its first move is // the sum of the rank on which it begins and its max reach. // NOTE: this calculation isn't perfect if the pawn piece is // modified in some very unusual way, or different pawns start on // different ranks. PawnMaxRankFirstMove = maxRank + maxSteps; } if (LeftPawnPenaltyFile == -1) { LeftPawnPenaltyFile = 0; } if (RightPawnPenaltyFile == -1) { RightPawnPenaltyFile = game.Board.NumFiles - 1; } // find this game's castling rule (if it has one) CastlingRule = (CastlingRule)game.FindRule(typeof(CastlingRule), true); // start with default randomness SetVariation(game.Variation); }