Beispiel #1
0
        public override void SetEnablePositions(ISituation situation, out Positions enableMovein, out Positions enableCapture)
        {
            enableCapture = new Positions();
            enableMovein  = new Positions();

            Position aPos = this.Position.ShiftWestNorth();
            Position bPos = this.Position.ShiftEastNorth();
            Position cPos = this.Position.ShiftWestSouth();
            Position dPos = this.Position.ShiftEastSouth();

            if (aPos != Position.Empty)
            {
                Position.Shift(this.GameSide, situation, aPos.ShiftNorth(), enableMovein, enableCapture);
                Position.Shift(this.GameSide, situation, aPos.ShiftWest(), enableMovein, enableCapture);
            }
            if (bPos != Position.Empty)
            {
                Position.Shift(this.GameSide, situation, bPos.ShiftNorth(), enableMovein, enableCapture);
                Position.Shift(this.GameSide, situation, bPos.ShiftEast(), enableMovein, enableCapture);
            }
            if (cPos != Position.Empty)
            {
                Position.Shift(this.GameSide, situation, cPos.ShiftWest(), enableMovein, enableCapture);
                Position.Shift(this.GameSide, situation, cPos.ShiftSouth(), enableMovein, enableCapture);
            }
            if (dPos != Position.Empty)
            {
                Position.Shift(this.GameSide, situation, dPos.ShiftEast(), enableMovein, enableCapture);
                Position.Shift(this.GameSide, situation, dPos.ShiftSouth(), enableMovein, enableCapture);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 车的基本路线(即横平竖直)
        /// </summary>
        internal static void RookShift(
            Enums.GameSide side, ISituation situation, Position position,
            Positions moveInPs, Positions capturePs)
        {
            bool     canContine = true;
            Position tgtPos     = Position.Empty;

            canContine = true;
            tgtPos     = position;
            while (canContine)
            {
                tgtPos     = tgtPos.ShiftEast();
                canContine = Position.Shift(side, situation, tgtPos, moveInPs, capturePs);
            }

            canContine = true;
            tgtPos     = position;
            while (canContine)
            {
                tgtPos     = tgtPos.ShiftSouth();
                canContine = Position.Shift(side, situation, tgtPos, moveInPs, capturePs);
            }

            canContine = true;
            tgtPos     = position;
            while (canContine)
            {
                tgtPos     = tgtPos.ShiftWest();
                canContine = Position.Shift(side, situation, tgtPos, moveInPs, capturePs);
            }

            canContine = true;
            tgtPos     = position;
            while (canContine)
            {
                tgtPos     = tgtPos.ShiftNorth();
                canContine = Position.Shift(side, situation, tgtPos, moveInPs, capturePs);
            }
        }
        /// <summary>
        /// 车的基本路线(即横平竖直)
        /// </summary>
        internal static void RookShift(
            Enums.GameSide side, ISituation situation, Position position,
            Positions moveInPs, Positions capturePs)
        {
            bool canContine = true;
            Position tgtPos = Position.Empty;

            canContine = true;
            tgtPos = position;
            while (canContine)
            {
                tgtPos = tgtPos.ShiftEast();
                canContine = Position.Shift(side, situation, tgtPos, moveInPs, capturePs);
            }

            canContine = true;
            tgtPos = position;
            while (canContine)
            {
                tgtPos = tgtPos.ShiftSouth();
                canContine = Position.Shift(side, situation, tgtPos, moveInPs, capturePs);
            }

            canContine = true;
            tgtPos = position;
            while (canContine)
            {
                tgtPos = tgtPos.ShiftWest();
                canContine = Position.Shift(side, situation, tgtPos, moveInPs, capturePs);
            }

            canContine = true;
            tgtPos = position;
            while (canContine)
            {
                tgtPos = tgtPos.ShiftNorth();
                canContine = Position.Shift(side, situation, tgtPos, moveInPs, capturePs);
            }
        }
        public override void SetEnablePositions(ISituation situation, out Positions enableMovein, out Positions enableCapture)
        {
            enableMovein  = new Positions();
            enableCapture = new Positions();

            if (this.GameSide == Enums.GameSide.White)
            {
                #region 白兵
                if (this.Position.Y < 1)
                {
                    return;                     //白兵怎么也不可能在第一行上
                }
                Position tmpPos = Position.Empty;
                //向北
                tmpPos = this.Position.ShiftNorth();
                if (tmpPos == Position.Empty)
                {
                    return;
                }
                if (!situation.ContainsPiece(tmpPos.Dot))
                {
                    enableMovein.Add(tmpPos);
                }
                //再向北(仅当在兵从未动过时)
                if (this.Position.Y == 1)
                {
                    tmpPos = tmpPos.ShiftNorth();
                    if (!situation.ContainsPiece(tmpPos.Dot))
                    {
                        enableMovein.Add(tmpPos);
                    }
                }
                //吃过路兵的判断
                if (this.Position.Y == 4)
                {
                    #region 过路兵
                    //西北
                    tmpPos = this.Position.ShiftWest();
                    if (tmpPos != null)
                    {
                        Piece pawn;
                        Game  game = (Game)situation;
                        if (game.TryGetPiece(tmpPos.Dot, out pawn))
                        {
                            if (pawn is PiecePawn)
                            {
                                if (((PiecePawn)pawn).EnableEnPassanted)
                                {
                                    enableMovein.Add(this.Position.ShiftWestNorth());
                                    enableCapture.Add(tmpPos);
                                }
                            }
                        }
                    }
                    //东北
                    tmpPos = this.Position.ShiftEast();
                    if (tmpPos != null)
                    {
                        Piece pawn;
                        Game  game = (Game)situation;
                        if (game.TryGetPiece(tmpPos.Dot, out pawn))
                        {
                            if (pawn is PiecePawn)
                            {
                                if (((PiecePawn)pawn).EnableEnPassanted)
                                {
                                    enableMovein.Add(this.Position.ShiftEastNorth());
                                    enableCapture.Add(tmpPos);
                                }
                            }
                        }
                    }
                    #endregion
                }
                //剑指西北
                Position.Shift(this.GameSide, situation, this.Position.ShiftWestNorth(), enableMovein, enableCapture, false);
                //剑指东北
                Position.Shift(this.GameSide, situation, this.Position.ShiftEastNorth(), enableMovein, enableCapture, false);
                #endregion
            }
            else
            {
                #region 黑兵
                if (this.Position.Y > 6)
                {
                    return;
                }
                Position tmpPos = Position.Empty;
                //向南
                tmpPos = this.Position.ShiftSouth();
                if (tmpPos == Position.Empty)
                {
                    return;
                }
                if (!situation.ContainsPiece(tmpPos.Dot))
                {
                    enableMovein.Add(tmpPos);
                }
                //再向南(仅当在兵从未动过时)
                if (this.Position.Y == 6)
                {
                    tmpPos = tmpPos.ShiftSouth();
                    if (!situation.ContainsPiece(tmpPos.Dot))
                    {
                        enableMovein.Add(tmpPos);
                    }
                }
                //吃过路兵的判断
                if (this.Position.Y == 3)
                {
                    #region 过路兵
                    //西南
                    tmpPos = this.Position.ShiftWest();
                    if (tmpPos != null)
                    {
                        Piece pawn;
                        Game  game = (Game)situation;
                        if (game.TryGetPiece(tmpPos.Dot, out pawn))
                        {
                            if (pawn is PiecePawn)
                            {
                                if (((PiecePawn)pawn).EnableEnPassanted)
                                {
                                    enableMovein.Add(this.Position.ShiftWestSouth());
                                    enableCapture.Add(tmpPos);
                                }
                            }
                        }
                    }
                    //东南
                    tmpPos = this.Position.ShiftEast();
                    if (tmpPos != null)
                    {
                        Piece pawn;
                        Game  game = (Game)situation;
                        if (game.TryGetPiece(tmpPos.Dot, out pawn))
                        {
                            if (pawn is PiecePawn)
                            {
                                if (((PiecePawn)pawn).EnableEnPassanted)
                                {
                                    enableMovein.Add(this.Position.ShiftEastSouth());
                                    enableCapture.Add(tmpPos);
                                }
                            }
                        }
                    }
                    #endregion
                }
                //剑指西南
                Position.Shift(this.GameSide, situation, this.Position.ShiftWestSouth(), enableMovein, enableCapture, false);
                //剑指东南
                Position.Shift(this.GameSide, situation, this.Position.ShiftEastSouth(), enableMovein, enableCapture, false);
                #endregion
            }
        }