示例#1
0
    //判断城堡当前是否有单位存在 false没有 true有
    public bool JudgeCastleHaveUnit(CastleType castleType)
    {
        if (castleType == CastleType.ThePlayerCastle)
        {
            if (castlePlayer.itemBrick.rolePlayer == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
        else if (castleType == CastleType.TheEnemyCastle)
        {
            if (castleEnemy.itemBrick.rolePlayer == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }

        return(false);
    }
示例#2
0
 private static bool CastlingNoPiecesInBetween(King king, Board board, CastleType type)
 {
     foreach (var square in king.GetCastleInBetweenPositions(type))
     {
         if (board.IsAnyPieceInSquare(square))
         {
             return(false);
         }
     }
     return(true);
 }
示例#3
0
        private static bool CastlePiecesHaveNotBeenMoved(King king, Board board, CastleType castleType)
        {
            if (king.HasBeenMoved)
            {
                return(false);
            }

            var rookSquare = board[king.GetCastleRookStartingSquare(castleType)];

            return(rookSquare.Piece != null &&
                   !rookSquare.Piece.HasBeenMoved);
        }
示例#4
0
文件: Castle.cs 项目: Fabernaz/Chess
 public Castle(King king, Rook rook, Board board, CastleType type)
     : base(true,
            king,
            null,
            board[king.GetCastleStartingPosition()],
            board[king.GetCastleEndingPosition(type)],
            null)
 {
     _type  = type;
     _board = board;
     _rook  = rook;
     _rookStartingPosition = board[King.GetCastleRookStartingSquare(type)];
     _rookEndingPosition   = board[King.GetCastleRookEndingPosition(type)];
 }
示例#5
0
文件: King.cs 项目: Fabernaz/Chess
        internal SquareCoordinate GetCastleEndingPosition(CastleType type)
        {
            switch (type)
            {
            case CastleType.KingSide:
                return(new SquareCoordinate(Color.FirstRank, 7));

            case CastleType.QueenSide:
                return(new SquareCoordinate(Color.FirstRank, 3));

            default:
                throw new NotImplementedException();
            }
        }
示例#6
0
文件: King.cs 项目: hcesar/Chess
        private bool CanCastle(CastleType castleType)
        {
            var castle = this.Board.GetCastleAvailabity(this.Player);

            if (!castle.HasFlag(castleType))
                return false;

            if (this.Board.IsInCheck())
                return false;

            var testSquare = castleType.GetRookSquare(this.Player);
            for (int i = 0; i < castleType.GetRookDistance(); i++)
            {
                testSquare = testSquare.Move(castleType.GetRookMoveDirection()).Value;
                if (this.Board[testSquare] != null || this.Board.IsUnderAttack(testSquare, this.Player.Opponent()))
                    return false;
            }

            return true;
        }
示例#7
0
文件: King.cs 项目: Fabernaz/Chess
        internal IEnumerable <SquareCoordinate> GetCastleInBetweenPositions(CastleType type)
        {
            switch (type)
            {
            case CastleType.KingSide:
                yield return(new SquareCoordinate(Color.FirstRank, 6));

                yield return(new SquareCoordinate(Color.FirstRank, 7));

                break;

            case CastleType.QueenSide:
                yield return(new SquareCoordinate(Color.FirstRank, 4));

                yield return(new SquareCoordinate(Color.FirstRank, 3));

                break;

            default:
                throw new NotImplementedException();
            }
        }
示例#8
0
        public static object ConvertType(CastleType type, object value)
        {
            switch (type)
            {
            case CastleType.UniqueIdentifier:
            case CastleType.Text:
                return(value.ToString());

            case CastleType.Integer:
                return(int.Parse(value.ToString()));

            case CastleType.Float:
                return(float.Parse(value.ToString()));

            case CastleType.Boolean:
                return(bool.Parse(value.ToString()));

            case CastleType.Flags:
                return(uint.Parse(value.ToString()));

            case CastleType.Enum:
                return(int.Parse(value.ToString()));

            case CastleType.Image:
                return(value.ToString());

            case CastleType.Color:
                return(uint.Parse(value.ToString()));

            case CastleType.Ref:
                CastleRef refObj = value as CastleRef;
                if (refObj == null)
                {
                    return(null);
                }
                return(refObj.Referencedstring);
            }
            return(null);
        }
示例#9
0
文件: King.cs 项目: Fabernaz/Chess
        internal ISet <SquareCoordinate> GetCastlingSquares(CastleType type)
        {
            switch (type)
            {
            case CastleType.KingSide:
                return(new HashSet <SquareCoordinate>
                {
                    new SquareCoordinate(Color.FirstRank, 5),
                    new SquareCoordinate(Color.FirstRank, 6),
                    new SquareCoordinate(Color.FirstRank, 7)
                });

            case CastleType.QueenSide:
                return(new HashSet <SquareCoordinate>
                {
                    new SquareCoordinate(Color.FirstRank, 5),
                    new SquareCoordinate(Color.FirstRank, 4),
                    new SquareCoordinate(Color.FirstRank, 3)
                });

            default:
                throw new NotImplementedException();
            }
        }
示例#10
0
        private static bool CastlingSquaresAreNotControlledByOpponent(King king, Board board, CastleType castleType)
        {
            foreach (var square in king.GetCastlingSquares(castleType))
            {
                if (board.IsInOpponentControl(board[square], king.Color))
                {
                    return(false);
                }
            }

            return(true);
        }
示例#11
0
 public CastleMove(Player actorPlayer, CastleType castleType)
 {
     ActorPlayer_ = actorPlayer;
     CastleType_  = castleType;
 }
示例#12
0
文件: King.cs 项目: hcesar/Chess
 public KingCastleMove(Piece piece, Square target, CastleType castle)
     : base(piece, target)
 {
     this.Castle = castle;
 }
示例#13
0
 internal static bool CanCastle(King king, Board board, CastleType castleType)
 {
     return(CastlePiecesHaveNotBeenMoved(king, board, castleType) &&
            CastlingNoPiecesInBetween(king, board, castleType) &&
            CastlingSquaresAreNotControlledByOpponent(king, board, castleType));
 }
            public bool castle(ChessSide side, ColorType color,
					    CastleType castle)
            {
                if (!side.King.CanCastle)
                  {
                      debug (Catalog.GetString("Cant castle (") + side.King);
                      return false;
                  }

                if (side.King.File !=
                    ChessBoardConstants.FILE_E)
                  {
                      debug (Catalog.GetString("King not available ") +
                         side.King);
                      return false;
                  }

                int file;
                if (castle == CastleType.LONG_CASTLE)
                  {
                      file = ChessBoardConstants.FILE_A;
                  }
                else
                  {
                      file = ChessBoardConstants.FILE_H;
                  }

                int rank;
                if (color == ColorType.WHITE)
                    rank = 0;
                else
                    rank = 7;

                if (positions[rank, file] == null)
                  {
                      debug (Catalog.GetString("Rook not available"));
                      return false;
                  }

                int i1, i2;
                if (castle == CastleType.LONG_CASTLE)
                  {
                      i1 = ChessBoardConstants.FILE_B;
                      i2 = ChessBoardConstants.FILE_E;
                  }
                else
                  {
                      i1 = ChessBoardConstants.FILE_F;
                      i2 = ChessBoardConstants.FILE_H;
                  }

                for (int i = i1; i < i2; i++)
                  {
                      if (positions[rank, i] != null)
                        {	// some pieces blocking.. cannot castle
                            return false;
                        }
                  }

                IList attackers = new ArrayList ();
                ChessPiece.
                    getAttackers ((color ==
                               ColorType.
                               WHITE ? whites :
                               blacks),
                              (color ==
                               ColorType.
                               WHITE ? blacks :
                               whites), rank,
                              ChessBoardConstants.
                              FILE_E, positions, null,
                              attackers);
                // check if king is under attack.
                // cannot castle in that case
                if (attackers.Count > 0)
                  {
                      return false;
                  }

                if (castle == CastleType.LONG_CASTLE)
                    i1 = ChessBoardConstants.FILE_C;
                for (int i = i1; i < i2; i++)
                  {
                      attackers.Clear ();
                      ChessPiece.
                          getAttackers ((color ==
                                 ColorType.
                                 WHITE ?
                                 whites :
                                 blacks),
                                (color ==
                                 ColorType.
                                 WHITE ?
                                 blacks :
                                 whites),
                                rank, i,
                                positions,
                                null,
                                attackers);
                      if (attackers.Count > 0)
                        {	// king will be under attack in this case
                            return false;
                        }
                  }

                if (castle == CastleType.SHORT_CASTLE)
                  {
                      setPiece (side.King, rank,
                            ChessBoardConstants.
                            FILE_G);
                      setPiece (positions
                            [rank,
                             ChessBoardConstants.
                             FILE_H], rank,
                            ChessBoardConstants.
                            FILE_F);
                      removePiece (rank,
                               ChessBoardConstants.
                               FILE_E);
                      removePiece (rank,
                               ChessBoardConstants.
                               FILE_H);

                      lastMoveInfo.movedPiece = side.King;
                      lastMoveInfo.SetInfo (rank,
                                ChessBoardConstants.
                                FILE_E, rank,
                                ChessBoardConstants.
                                FILE_G, true);
                  }
                else
                  {
                      setPiece (side.King, rank,
                            ChessBoardConstants.
                            FILE_C);
                      setPiece (positions
                            [rank,
                             ChessBoardConstants.
                             FILE_A], rank,
                            ChessBoardConstants.
                            FILE_D);
                      removePiece (rank,
                               ChessBoardConstants.
                               FILE_E);
                      removePiece (rank,
                               ChessBoardConstants.
                               FILE_A);

                      lastMoveInfo.movedPiece = side.King;
                      lastMoveInfo.SetInfo (rank,
                                ChessBoardConstants.
                                FILE_E, rank,
                                ChessBoardConstants.
                                FILE_C, true);
                  }

                FlipTurn ();
                return true;
            }
示例#15
0
文件: FEN.cs 项目: hcesar/Chess
 private void SetCastleAvailability(string text)
 {
     CastleType black = (CastleType)0;
     CastleType white = (CastleType)0;
     foreach (char c in text)
     {
         switch (c)
         {
             case 'K': white = white | CastleType.KingSide; break;
             case 'Q': white = white | CastleType.QueenSide; break;
             case 'k': black = black | CastleType.KingSide; break;
             case 'q': black = black | CastleType.QueenSide; break;
         }
     }
     this.BlackCastleAvailability = black;
     this.WhiteCastleAvailability = white;
 }
示例#16
0
文件: FEN.cs 项目: hcesar/Chess
        private static string GetNotation(CastleType castleType, PlayerColor color)
        {
            string notation = "";
            switch (castleType)
            {
                case CastleType.KingSide: notation = "k"; break;
                case CastleType.QueenSide: notation = "q"; break;
                case CastleType.QueenOrKingSide: notation = "kq"; break;
            }

            return color == PlayerColor.White ? notation.ToUpper() : notation.ToLower();
        }
示例#17
0
        private Move GetCastleMove(Board board, King king, CastleType castleType)
        {
            var rook = board[king.GetCastleRookStartingSquare(castleType)].Piece as Rook;

            return(new Castle(king, rook, board, castleType));
        }