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


C# ChessGame.WouldBeInCheckAfter方法代码示例

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


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


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