本文整理汇总了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;
}