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