示例#1
0
        //	Generate moves for this piece assuming it is of the given
        //	type (which it usually is.)  This function is useful for polymorphic
        //	piece types that can move as other types of pieces.
        public void GenerateMoves(PieceType pieceType, MoveList list, bool capturesOnly)
        {
            //	if the piece type has a custom move generator, run that first.
            //	it will determine if we proceed to standard generation
            if (pieceType.CustomMoveGenerator != null)
            {
                if (!pieceType.CustomMoveGenerator(pieceType, this, list, capturesOnly))
                {
                    //	custom generator returned false, so we don't
                    //	proceed to standard move generation
                    return;
                }
            }

            MoveCapability[] moves;
            int nMoves = pieceType.GetMoveCapabilities(out moves);

            for (int nMove = 0; nMove < nMoves; nMove++)
            {
                if (moves[nMove].ConditionalBySquare == null || moves[nMove].ConditionalBySquare[Player][Square])
                {
                    GenerateMovesForCapability(pieceType.SimpleMoveGeneration, ref moves[nMove], list, capturesOnly);
                }
            }
        }
示例#2
0
        public void MakingMove(MoveList movelist, MoveInfo moveinfo)
        {
            MoveInfo newmove = moveinfo;

            movelist.CopyMoveToGameHistory(pickups, drops, moveinfo);
            newmove.PickupCursor = pickups.Count;
            newmove.DropCursor   = drops.Count;
            moves.Add(newmove);
        }
示例#3
0
		public virtual void GenerateSpecialMoves( MoveList list, bool capturesOnly, int ply )
		{ }
示例#4
0
		public virtual MoveEventResponse MoveBeingGenerated( MoveList moves, int from, int to, MoveType type )
		{ return MoveEventResponse.NotHandled; }
示例#5
0
        public void GenerateMovesForCapability(bool simpleMoveGeneration, ref MoveCapability move, MoveList list, bool capturesOnly)
        {
            if (simpleMoveGeneration)
            {
                #region Handle simple move generation
                int step       = 1;
                int nextSquare = Game.Board.NextSquare(Player, move.NDirection, Square);
                while (nextSquare >= 0 && step <= move.MaxSteps)
                {
                    Piece pieceOnSquare = Board[nextSquare];
                    if (pieceOnSquare != null)
                    {
                        if (step >= move.MinSteps && move.CanCapture && pieceOnSquare.Player != Player)
                        {
                            list.AddCapture(Square, nextSquare);
                        }
                        nextSquare = -1;
                    }
                    else
                    {
                        if (step >= move.MinSteps && !move.MustCapture && !capturesOnly)
                        {
                            list.AddMove(Square, nextSquare);
                        }
                        nextSquare = Game.Board.NextSquare(Player, move.NDirection, nextSquare);
                        step++;
                    }
                }
                #endregion
            }
            else
            {
                #region Handle pieces with the more complex moves
                int  step         = 1;
                bool passedScreen = false;
                int  nextSquare   = Game.Board.NextSquare(Player, move.NDirection, Square);
                while (nextSquare >= 0 && step <= move.MaxSteps)
                {
                    Piece pieceOnSquare = Board[nextSquare];

                    #region Handle pieces with move paths
                    if (move.PathInfo != null)
                    {
                        if (pieceOnSquare == null && capturesOnly)
                        {
                            //	don't bother trying to generate this non-capture
                            return;
                        }

                        if (pieceOnSquare != null && pieceOnSquare.Player == Player)
                        {
                            //	can't capture own piece
                            return;
                        }

                        //	ensure this move is supported
                        if (step > 1 || move.SpecialAttacks != 0 || move.PathInfo.AllowMultiCapture == true)
                        {
                            throw new Exception("Piece type " + PieceType.Name + " has an unsupported movement capability");
                        }
                        //	iterate through the paths to see if one is available
                        foreach (List <int> path in move.PathInfo.PathNDirections)
                        {
                            int pathSquare = Square;
                            //	iterate through each step in this path to see if it is clear
                            bool pathIsClear = true;
                            foreach (int nDirection in path)
                            {
                                pathSquare = Game.Board.NextSquare(Player, nDirection, pathSquare);
                                if (pathSquare < 0 || (Board[pathSquare] != null && Board[pathSquare] != pieceOnSquare))
                                {
                                    //	this path is obstructed
                                    pathIsClear = false;
                                    break;
                                }
                            }
                            if (pathIsClear)
                            {
                                if (pieceOnSquare != null && move.CanCapture)
                                {
                                    list.AddCapture(Square, nextSquare);
                                }
                                else if (pieceOnSquare == null)
                                {
                                    list.AddMove(Square, nextSquare);
                                }
                                //	we can return now; no need to try other paths
                                return;
                            }
                        }
                        //	if we are here, all paths are blocked
                        return;
                    }
                    #endregion

                    if (pieceOnSquare != null)
                    {
                        if (step >= move.MinSteps && pieceOnSquare.Player != Player &&
                            (move.CanCapture ||
                             ((move.SpecialAttacks & SpecialAttacks.CannonCapture) != 0 && passedScreen)))
                        {
                            if (move.SpecialAttacks != SpecialAttacks.RifleCapture)
                            {
                                list.AddCapture(Square, nextSquare);
                            }
                            else
                            {
                                list.AddRifleCapture(Square, nextSquare);
                            }
                        }
                        if ((move.SpecialAttacks & SpecialAttacks.CannonCapture) != 0 && !passedScreen)
                        {
                            passedScreen = true;
                            nextSquare   = Game.Board.NextSquare(Player, move.NDirection, nextSquare);
                        }
                        else
                        {
                            nextSquare = -1;
                        }
                    }
                    else
                    {
                        if (step >= move.MinSteps && !move.MustCapture && !capturesOnly && !passedScreen)
                        {
                            list.AddMove(Square, nextSquare);
                        }
                        nextSquare = Game.Board.NextSquare(Player, move.NDirection, nextSquare);
                        step++;
                    }
                }
                #endregion
            }
        }
示例#6
0
 //	Generate moves for this piece and add to specified MoveList
 public void GenerateMoves(MoveList list, bool capturesOnly)
 {
     GenerateMoves(PieceType, list, capturesOnly);
 }