Пример #1
0
        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);
        }
Пример #2
0
        public static bool CustomMoveGenerationHandler(PieceType pieceType, Piece piece, MoveList moveList, bool capturesOnly)
        {
            MoveCapability[] moves;
            int nMoves = pieceType.GetMoveCapabilities(out moves);

            for (int nMove = 0; nMove < nMoves; nMove++)
            {
                MoveCapability move       = moves[nMove];
                int            step       = 1;
                int            nextSquare = piece.Board.NextSquare(piece.Player, move.NDirection, piece.Square);
                while (nextSquare >= 0 && step <= move.MaxSteps)
                {
                    Piece pieceOnSquare = piece.Board[nextSquare];
                    if (pieceOnSquare != null)
                    {
                        if (step >= move.MinSteps && move.CanCapture && pieceOnSquare.Player != piece.Player)
                        {
                            moveList.AddCapture(piece.Square, nextSquare);
                        }
                        else if (step >= move.MinSteps && pieceOnSquare.Player == piece.Player && piece.PieceType != pieceOnSquare.PieceType)
                        {
                            //	self-capture move allowing relocation of friendly piece
                            int currentSquare = piece.Square;
                            while (currentSquare != nextSquare)
                            {
                                moveList.BeginMoveAdd(MoveType.MoveRelay, piece.Square, nextSquare, currentSquare);
                                moveList.AddPickup(piece.Square);
                                moveList.AddPickup(nextSquare);
                                moveList.AddDrop(piece, nextSquare);
                                moveList.AddDrop(pieceOnSquare, currentSquare);
                                moveList.EndMoveAdd(piece.PieceType.GetMidgamePST(nextSquare) - piece.PieceType.GetMidgamePST(piece.Square) +
                                                    pieceOnSquare.PieceType.GetMidgamePST(currentSquare) - pieceOnSquare.PieceType.GetMidgamePST(nextSquare));
                                currentSquare = piece.Board.NextSquare(piece.Player, move.NDirection, currentSquare);
                            }
                        }
                        nextSquare = -1;
                    }
                    else
                    {
                        if (step >= move.MinSteps && !move.MustCapture && !capturesOnly)
                        {
                            moveList.AddMove(piece.Square, nextSquare);
                        }
                        nextSquare = piece.Board.NextSquare(piece.Player, move.NDirection, nextSquare);
                        step++;
                    }
                }
            }
            return(false);
        }
Пример #3
0
        // *** HELPER FUNCTIONS *** //

        #region addMove
        protected void addMove(MoveList list, int fromSquare, int toSquare, bool capturesOnly)
        {
            if (toSquare >= 0 && toSquare < Board.NumSquares)
            {
                Piece pieceOnDestinationSquare = Board[toSquare];
                if (pieceOnDestinationSquare == null)
                {
                    if (!capturesOnly)
                    {
                        list.AddMove(fromSquare, toSquare);
                    }
                }
                else if (pieceOnDestinationSquare.Player != Game.CurrentSide)
                {
                    list.AddCapture(fromSquare, toSquare);
                }
            }
        }
Пример #4
0
        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);
        }
Пример #5
0
        public static bool CustomMoveGenerationHandler(PieceType pieceType, Piece piece, MoveList moveList, bool capturesOnly)
        {
            MoveCapability[] moves;
            int nMoves = pieceType.GetMoveCapabilities(out moves);

            for (int nMove = 0; nMove < nMoves; nMove++)
            {
                MoveCapability move       = moves[nMove];
                int            step       = 1;
                int            nextSquare = piece.Board.NextSquare(piece.Player, move.NDirection, piece.Square);
                while (nextSquare >= 0 && step <= move.MaxSteps)
                {
                    Piece pieceOnSquare = piece.Board[nextSquare];
                    if (pieceOnSquare != null)
                    {
                        if (step >= move.MinSteps && move.CanCapture && pieceOnSquare.Player != piece.Player)
                        {
                            moveList.AddCapture(piece.Square, nextSquare);
                            for (int x = 0; x < 8; x++)
                            {
                                int targetSquare = piece.Board.NextSquare(x, nextSquare);
                                if (targetSquare >= 0 && piece.Board[targetSquare] != null && piece.Board[targetSquare].Player != piece.Player)
                                {
                                    moveList.BeginMoveAdd(MoveType.ExtraCapture, piece.Square, nextSquare, targetSquare);
                                    moveList.AddPickup(piece.Square);
                                    moveList.AddPickup(nextSquare);
                                    moveList.AddPickup(targetSquare);
                                    moveList.AddDrop(piece, nextSquare);
                                    moveList.EndMoveAdd(4000 + piece.Board[nextSquare].PieceType.MidgameValue + piece.Board[targetSquare].PieceType.MidgameValue);
                                }
                            }
                        }
                        nextSquare = -1;
                    }
                    else
                    {
                        if (step >= move.MinSteps && !move.MustCapture)
                        {
                            if (!capturesOnly)
                            {
                                moveList.AddMove(piece.Square, nextSquare);
                            }
                            for (int x = 0; x < 8; x++)
                            {
                                int targetSquare = piece.Board.NextSquare(x, nextSquare);
                                if (targetSquare >= 0 && piece.Board[targetSquare] != null && piece.Board[targetSquare].Player != piece.Player)
                                {
                                    moveList.BeginMoveAdd(MoveType.ExtraCapture, piece.Square, nextSquare, targetSquare);
                                    moveList.AddPickup(piece.Square);
                                    moveList.AddPickup(targetSquare);
                                    moveList.AddDrop(piece, nextSquare);
                                    moveList.EndMoveAdd(3000 + piece.Board[targetSquare].PieceType.MidgameValue);
                                }
                            }
                        }
                        nextSquare = piece.Board.NextSquare(piece.Player, move.NDirection, nextSquare);
                        step++;
                    }
                }
            }

            return(false);
        }
Пример #6
0
        public static bool CustomMoveGenerationHandler(PieceType pieceType, Piece piece, MoveList moveList, bool capturesOnly)
        {
            OdinsRuneChess game = (OdinsRuneChess)piece.Game;

            //	determine what pieces are adjacent
            bool foundValkyrie = false;
            bool foundForestOx = false;
            bool foundRook     = false;
            bool foundBishop   = false;
            bool foundPawn     = false;

            for (int x = 0; x < 8; x++)
            {
                int square = piece.Board.NextSquare(x, piece.Square);
                if (square >= 0 && piece.Board[square] != null && piece.Board[square].Player == piece.Player)
                {
                    PieceType adjacentPieceType = piece.Board[square].PieceType;
                    if (adjacentPieceType == game.Valkyrie)
                    {
                        foundValkyrie = true;
                    }
                    else if (adjacentPieceType == game.ForestOx)
                    {
                        foundForestOx = true;
                    }
                    else if (adjacentPieceType == game.Rook)
                    {
                        foundRook = true;
                    }
                    else if (adjacentPieceType == game.Bishop)
                    {
                        foundBishop = true;
                    }
                    else if (adjacentPieceType == game.Pawn)
                    {
                        foundPawn = true;
                    }
                }
            }

            //	generate moves of appropriate types
            if (foundValkyrie)
            {
                piece.GenerateMoves(game.Valkyrie, moveList, capturesOnly);
            }
            else
            {
                //	don't generate rook or bishop if we have found valkyrie
                //	because all their moves would be redundant
                if (foundRook)
                {
                    piece.GenerateMoves(game.Rook, moveList, capturesOnly);
                }
                if (foundBishop)
                {
                    piece.GenerateMoves(game.Bishop, moveList, capturesOnly);
                }
            }
            if (foundForestOx)
            {
                piece.GenerateMoves(game.ForestOx, moveList, capturesOnly);
            }
            if (foundPawn)
            {
                if (!foundBishop && !foundValkyrie)
                {
                    piece.GenerateMoves(game.Pawn, moveList, capturesOnly);
                }
                else
                {
                    //	This gets tricky; we can't just generate all pawn moves
                    //	because we'd generate duplicative moves.  So we need to
                    //	manually generate just the one unique pawn move (the
                    //	multi-path move.)

                    //	First, check to make sure that this move wasn't
                    //	already generated by a straight Valkyrie move
                    if (!foundValkyrie ||
                        (game.Board.NextSquare(PredefinedDirections.N + piece.Player, piece.Square) >= 0 &&
                         game.Board[game.Board.NextSquare(PredefinedDirections.N + piece.Player, piece.Square)] != null))
                    {
                        //	Is the square two ahead both on the board and a square
                        //	we can move to?
                        int targetSquare = game.Board.NextSquare(PredefinedDirections.N + piece.Player, piece.Square);
                        if (targetSquare >= 0)
                        {
                            targetSquare = game.Board.NextSquare(PredefinedDirections.N + piece.Player, targetSquare);
                        }
                        if (targetSquare >= 0 &&
                            ((game.Board[targetSquare] == null && !capturesOnly) ||
                             (game.Board[targetSquare] != null && game.Board[targetSquare].Player != piece.Player)))
                        {
                            //	This is a square we can move to, but first we
                            //	must establish that there's a clear path
                            if ((game.Board.NextSquare(PredefinedDirections.NE + piece.Player, piece.Square) >= 0 &&
                                 game.Board[game.Board.NextSquare(PredefinedDirections.NE + piece.Player, piece.Square)] == null) ||
                                (game.Board.NextSquare(PredefinedDirections.NW + piece.Player, piece.Square) >= 0 &&
                                 game.Board[game.Board.NextSquare(PredefinedDirections.NW + piece.Player, piece.Square)] == null))
                            {
                                //	Ok, we're clear to generate the move/capture
                                if (game.Board[targetSquare] == null)
                                {
                                    moveList.AddMove(piece.Square, targetSquare);
                                }
                                else
                                {
                                    moveList.AddCapture(piece.Square, targetSquare);
                                }
                            }
                        }
                    }
                }
            }

            return(false);
        }