/// <summary> /// 从当前的位置移动到新位置。 /// 而后,判断该位置中是否有棋子,并根据判断结果更新两个Position集合(可移动"位置"集合,可杀棋"位置"集合)。 /// 并返回是否可以继续移动的判断。 /// </summary> /// <param name="situation">当前局面</param> /// <param name="tgtPos">目标位置</param> /// <param name="moveInPs">可移动"位置"集合</param> /// <param name="capturePs">可杀棋"位置"集合</param> /// <param name="enableToMoved">该棋格为空时,是否可以移入,一般是指“兵”,“兵”的斜向的两个棋格对于“兵”来讲能吃子不能移入。</param> /// <returns>移动到新位置后是否可以继续移动(当目标棋格中无棋子)</returns> public static bool Shift( Enums.GameSide side, ISituation situation, Position tgtPos, Positions moveInPs, Positions capturePs, bool enableToMoved) { if (tgtPos == Position.Empty) { return(false); } char pieceChar; if (situation.TryGetPiece(tgtPos.Dot, out pieceChar)) { if (char.IsLower(pieceChar) && side == Enums.GameSide.White) { capturePs.Add(tgtPos); } if (char.IsUpper(pieceChar) && side == Enums.GameSide.Black) { capturePs.Add(tgtPos); } return(false); } else { if (enableToMoved) { moveInPs.Add(tgtPos); return(true); } else { return(false); } } }
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 } }