public override MoveEventResponse MoveBeingGenerated(MoveList moves, int from, int to, MoveType type) { Piece movingPiece = Board[from]; if (movingPiece.TypeNumber == promotingTypeNumber) { Location loc = Board.SquareToLocation(Board.PlayerSquare(movingPiece.Player, to)); PromotionOption option = condition(loc); if (option != PromotionOption.CannotPromote) { // enemy piece being captured (if any) Piece capturedEnemyPiece = Board[to]; // if promotion is optional, add move without promotion if (option == PromotionOption.CanPromote) { if (capturedEnemyPiece == null) { moves.AddMove(from, to, true); } else { moves.AddCapture(from, to, true); } } List <int> pieceTypesFound = new List <int>(); List <Piece> capturedPieces = Game.GetCapturedPieceList(movingPiece.Player); foreach (Piece capturedFriendlyPiece in capturedPieces) { if (capturedFriendlyPiece.TypeNumber != movingPiece.TypeNumber && !pieceTypesFound.Contains(capturedFriendlyPiece.TypeNumber)) { if (capturedEnemyPiece == null) { moves.BeginMoveAdd(MoveType.MoveReplace, from, to, capturedFriendlyPiece.TypeNumber); moves.AddPickup(from); moves.AddDrop(capturedFriendlyPiece, to); moves.EndMoveAdd(5000 + capturedFriendlyPiece.PieceType.MidgameValue); } else { moves.BeginMoveAdd(MoveType.CaptureReplace, from, to, capturedFriendlyPiece.TypeNumber); moves.AddPickup(from); moves.AddPickup(to); moves.AddDrop(capturedFriendlyPiece, to); moves.EndMoveAdd(5000 + capturedFriendlyPiece.PieceType.MidgameValue + capturedEnemyPiece.PieceType.MidgameValue); } pieceTypesFound.Add(capturedFriendlyPiece.TypeNumber); } } return(MoveEventResponse.Handled); } } return(MoveEventResponse.NotHandled); }
public override MoveEventResponse MoveBeingGenerated(MoveList moves, int from, int to, MoveType type) { Piece movingPiece = Board[from]; foreach (PromotionCapability promotion in promotionCapabilities) { if (movingPiece.TypeNumber == promotion.PromotingTypeNumber) { Location toLocation = Board.SquareToLocation(Board.PlayerSquare(movingPiece.Player, to)); PromotionOption option = promotion.FromAndToConditionDelegate != null ? promotion.FromAndToConditionDelegate(Board.SquareToLocation(Board.PlayerSquare(movingPiece.Player, from)), toLocation) : promotion.ConditionDelegate(toLocation); if (option != PromotionOption.CannotPromote) { for (int x = 0; x < Game.MAX_PIECE_TYPES; x++) { typesUsed[x] = false; } // enemy piece being captured (if any) Piece capturedPiece = Board[to]; // if promotion is optional, add move without promotion if (option == PromotionOption.CanPromote) { if (capturedPiece == null) { moves.AddMove(from, to, true); } else { moves.AddCapture(from, to, true); } } // handle traditional promotion if (promotion.PromotionTypes != null) { if (capturedPiece == null) { foreach (PieceType promoteTo in promotion.PromotionTypes) { moves.BeginMoveAdd(MoveType.MoveWithPromotion, from, to); moves.AddPickup(from); moves.AddDrop(movingPiece, to, promoteTo); moves.EndMoveAdd(5000 + promoteTo.MidgameValue); typesUsed[promoteTo.TypeNumber] = true; } } else { foreach (PieceType promoteTo in promotion.PromotionTypes) { moves.BeginMoveAdd(MoveType.CaptureWithPromotion, from, to); moves.AddPickup(from); moves.AddPickup(to); moves.AddDrop(movingPiece, to, promoteTo); moves.EndMoveAdd(5000 + promoteTo.MidgameValue + capturedPiece.PieceType.MidgameValue); typesUsed[promoteTo.TypeNumber] = true; } } } // handle promotion by replacement if (promotion.ReplacementPromotionTypes != null) { List <Piece> capturedPieces = Game.GetCapturedPieceList(movingPiece.Player); foreach (Piece capturedFriendlyPiece in capturedPieces) { if (capturedFriendlyPiece.TypeNumber != movingPiece.TypeNumber && !typesUsed[capturedFriendlyPiece.TypeNumber] && promotion.ReplacementPromotionTypes.Contains(capturedFriendlyPiece.PieceType)) { if (capturedPiece == null) { moves.BeginMoveAdd(MoveType.MoveReplace, from, to, capturedFriendlyPiece.TypeNumber); moves.AddPickup(from); moves.AddDrop(capturedFriendlyPiece, to); moves.EndMoveAdd(5000 + capturedFriendlyPiece.PieceType.MidgameValue); } else { moves.BeginMoveAdd(MoveType.CaptureReplace, from, to, capturedFriendlyPiece.TypeNumber); moves.AddPickup(from); moves.AddPickup(to); moves.AddDrop(capturedFriendlyPiece, to); moves.EndMoveAdd(5000 + capturedFriendlyPiece.PieceType.MidgameValue + capturedPiece.PieceType.MidgameValue); } typesUsed[capturedFriendlyPiece.TypeNumber] = true; } } } return(MoveEventResponse.Handled); } } } return(MoveEventResponse.NotHandled); }