当前位置: 首页>>代码示例>>C#>>正文


C# ChessGame.IsInCheck方法代码示例

本文整理汇总了C#中ChessGame.IsInCheck方法的典型用法代码示例。如果您正苦于以下问题:C# ChessGame.IsInCheck方法的具体用法?C# ChessGame.IsInCheck怎么用?C# ChessGame.IsInCheck使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ChessGame的用法示例。


在下文中一共展示了ChessGame.IsInCheck方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CanCastle

 protected virtual bool CanCastle(Position origin, Position destination, ChessGame game)
 {
     if (!HasCastlingAbility) return false;
     if (Owner == Player.White)
     {
         if (origin.File != File.E || origin.Rank != 1)
             return false;
         if (game.IsInCheck(Player.White))
             return false;
         if (destination.File == File.C)
         {
             if (!game.CanWhiteCastleQueenSide || game.GetPieceAt(File.D, 1) != null
                 || game.GetPieceAt(File.C, 1) != null
                 || game.GetPieceAt(File.B, 1) != null
                 || game.WouldBeInCheckAfter(new Move(new Position(File.E, 1), new Position(File.D, 1), Player.White), Player.White)
                 || game.WouldBeInCheckAfter(new Move(new Position(File.E, 1), new Position(File.C, 1), Player.White), Player.White))
                 return false;
         }
         else
         {
             if (!game.CanWhiteCastleKingSide || game.GetPieceAt(File.F, 1) != null
                 || game.GetPieceAt(File.G, 1) != null
                 || game.WouldBeInCheckAfter(new Move(new Position(File.E, 1), new Position(File.F, 1), Player.White), Player.White)
                 || game.WouldBeInCheckAfter(new Move(new Position(File.E, 1), new Position(File.G, 1), Player.White), Player.White))
                 return false;
         }
     }
     else
     {
         if (origin.File != File.E || origin.Rank != 8)
             return false;
         if (game.IsInCheck(Player.Black))
             return false;
         if (destination.File == File.C)
         {
             if (!game.CanBlackCastleQueenSide || game.GetPieceAt(File.D, 8) != null
                 || game.GetPieceAt(File.C, 8) != null
                 || game.GetPieceAt(File.B, 8) != null
                 || game.WouldBeInCheckAfter(new Move(new Position(File.E, 8), new Position(File.D, 8), Player.Black), Player.Black)
                 || game.WouldBeInCheckAfter(new Move(new Position(File.E, 8), new Position(File.C, 8), Player.Black), Player.Black))
                 return false;
         }
         else
         {
             if (!game.CanBlackCastleKingSide || game.GetPieceAt(File.F, 8) != null
                 || game.GetPieceAt(File.G, 8) != null
                 || game.WouldBeInCheckAfter(new Move(new Position(File.E, 8), new Position(File.F, 8), Player.Black), Player.Black)
                 || game.WouldBeInCheckAfter(new Move(new Position(File.E, 8), new Position(File.G, 8), Player.Black), Player.Black))
                 return false;
         }
     }
     return true;
 }
开发者ID:ProgramFOX,项目名称:Chess.NET,代码行数:53,代码来源:King.cs

示例2: TestIsBlackNotInCheck_PawnsCanOnlyCheckDiagonally

        public static void TestIsBlackNotInCheck_PawnsCanOnlyCheckDiagonally()
        {
            Piece[][] board = new Piece[8][]
            {
                new[] { o, o, o, o, o, o, o, o },
                new[] { o, o, o, o, o, o, o, o },
                new[] { o, o, o, o, kb, o, o, o },
                new[] { o, o, o, o, pw, o, o, o },
                new[] { o, o, o, o, o, o, o, o },
                new[] { o, o, o, o, o, o, o, o },
                new[] { o, o, o, o, o, o, o, o },
                new[] { kw, o, o, o, o, o, o, o }
            };
            ChessGame cb = new ChessGame(board, Player.Black);

            Assert.False(cb.IsInCheck(Player.Black));
        }
开发者ID:ProgramFOX,项目名称:Chess.NET,代码行数:17,代码来源:ChessGameTests.cs

示例3: TestIsBlackNotInCheck

        public static void TestIsBlackNotInCheck()
        {
            Piece[][] board = new Piece[8][]
            {
                new[] { o, o, o, nb, o, o, o, o },
                new[] { o, kb, o, o, o, o, o, o },
                new[] { o, o, o, o, o, o, o, o },
                new[] { kw, o, o, o, o, o, o, o },
                new[] { o, o, o, o, o, o, o, pb },
                new[] { o, o, o, o, o, o, o, o },
                new[] { o, o, o, o, o, o, o, o },
                new[] { o, o, o, o, o, o, o, o }
            };
            ChessGame cb = new ChessGame(board, Player.Black);

            Assert.False(cb.IsInCheck(Player.Black));
        }
开发者ID:ProgramFOX,项目名称:Chess.NET,代码行数:17,代码来源:ChessGameTests.cs

示例4: TestIsBlackInCheck_OnRank8

        public static void TestIsBlackInCheck_OnRank8()
        {
            Piece[][] board = new Piece[8][]
            {
                new[] { o, o, o, o, kb, o, o, o },
                new[] { o, o, o, pw, o, o, o, o },
                new[] { o, o, o, o, o, o, o, o },
                new[] { o, o, o, o, o, o, o, o },
                new[] { o, o, o, o, o, o, o, o },
                new[] { o, o, o, o, o, o, o, o },
                new[] { o, o, o, o, o, o, o, o },
                new[] { kw, o, o, o, o, o, o, o }
            };
            ChessGame cb = new ChessGame(board, Player.Black);

            Assert.True(cb.IsInCheck(Player.Black));
        }
开发者ID:ProgramFOX,项目名称:Chess.NET,代码行数:17,代码来源:ChessGameTests.cs

示例5: TestIsBlackInCheck

        public static void TestIsBlackInCheck()
        {
            Piece[][] board = new Piece[8][]
            {
                new[] { o, o, o, nw, o, o, o, o },
                new[] { o, kb, o, o, o, o, o, o },
                new[] { o, o, o, o, o, o, o, o },
                new[] { kw, o, o, o, o, o, o, o },
                new[] { o, o, o, o, o, o, o, pb },
                new[] { o, o, o, o, o, o, o, o },
                new[] { o, o, o, o, o, o, o, o },
                new[] { o, o, o, o, o, o, o, o }
            };
            ChessGame cb = new ChessGame(board, Player.Black);

            Assert.True(cb.IsInCheck(Player.Black));

            cb.ApplyMove(new Move(new Position(File.B, 7), new Position(File.A, 7), Player.Black), true);

            Assert.False(cb.IsInCheck(Player.Black));
        }
开发者ID:ProgramFOX,项目名称:Chess.NET,代码行数:21,代码来源:ChessGameTests.cs

示例6: TestIsWhiteNotInCheck

        public static void TestIsWhiteNotInCheck()
        {
            Piece[][] board = new Piece[8][]
            {
                new[] { kw, o, o, o, o, o, o, o },
                new[] { o, o, o, o, o, o, o, qb },
                new[] { pw, o, o, pb, o, o, o, o },
                new[] { o, o, o, o, o, o, o, o },
                new[] { o, o, o, o, o, o, o, o },
                new[] { o, o, o, o, o, o, o, o },
                new[] { o, o, o, o, kb, o, o, o },
                new[] { o, o, o, o, o, o, o, o }
            };
            ChessGame cb = new ChessGame(board, Player.White);

            Assert.False(cb.IsInCheck(Player.White));
        }
开发者ID:ProgramFOX,项目名称:Chess.NET,代码行数:17,代码来源:ChessGameTests.cs

示例7: TestIsWhiteInCheck_OnRank1

        public static void TestIsWhiteInCheck_OnRank1()
        {
            Piece[][] board = new Piece[8][]
            {
                new[] { o, o, o, o, o, o, o, o },
                new[] { o, o, o, o, o, o, o, o },
                new[] { o, o, o, o, o, o, o, o },
                new[] { o, o, o, o, o, o, o, o },
                new[] { o, o, o, o, o, o, o, o },
                new[] { o, o, o, o, o, o, o, o },
                new[] { o, o, o, o, o, o, pb, o },
                new[] { kb, o, o, o, o, o, o, kw }
            };
            ChessGame cb = new ChessGame(board, Player.White);

            Assert.True(cb.IsInCheck(Player.White));
        }
开发者ID:ProgramFOX,项目名称:Chess.NET,代码行数:17,代码来源:ChessGameTests.cs

示例8: TestIsWhiteInCheck

        public static void TestIsWhiteInCheck()
        {
            Piece[][] board = new Piece[8][]
            {
                new[] { o, o, o, o, o, o, o, o },
                new[] { kw, o, o, o, o, o, o, qb },
                new[] { pw, o, o, pb, o, o, o, o },
                new[] { o, o, o, o, o, o, o, o },
                new[] { o, o, o, o, o, o, o, o },
                new[] { o, o, o, o, o, o, o, o },
                new[] { o, o, o, o, o, o, o, o },
                new[] { kb, o, o, o, o, o, o, o }
            };
            ChessGame cb = new ChessGame(board, Player.White);

            Assert.True(cb.IsInCheck(Player.White));

            cb.ApplyMove(new Move(new Position(File.A, 7), new Position(File.A, 8), Player.White), true);
            Assert.False(cb.IsInCheck(Player.White));
        }
开发者ID:ProgramFOX,项目名称:Chess.NET,代码行数:20,代码来源:ChessGameTests.cs


注:本文中的ChessGame.IsInCheck方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。