public void IsLegalMoveDiagonally_IsFalse_Test_001() { // Arrange diagonal move where occupied by own GameController gc = new GameController(); Location origin = gc.GetLocation("A7"); Location destination = gc.GetLocation("B6"); int playerIndex = 1; int otherPlayerIndex = gc.GetOtherPlayerIndex(playerIndex); ChessPiece piece = gc.Players[playerIndex].Pieces .SingleOrDefault(p => p.CurrentLocation.Coordinate == "A7"); ChessPiece otherPiece = gc.Players[playerIndex].Pieces .SingleOrDefault(p => p.CurrentLocation.Coordinate == "B7"); // Fake previous moved that places pieces in desired locations. piece.CurrentLocation = origin; otherPiece.CurrentLocation = destination; // Act bool isLegalMoveDiagonally = MoveAssistant.IsLegalMoveDiagonally( gc.Players[playerIndex], gc.Players[otherPlayerIndex], origin, destination, 1, false); Assert.IsFalse(isLegalMoveDiagonally); }
public override bool DidMove( Player player, Player opponent, Location origin, Location destination) { bool isLegalMoveDiagonally = MoveAssistant.IsLegalMoveDiagonally( player, opponent, origin, destination, 7, false); return(isLegalMoveDiagonally); }
// ToDo: Handle promotion of pawns public override bool DidMove( Player player, Player opponent, Location origin, Location destination) { // Can move up to 2 rows toward opponent on 1st move bool isInitialMove = false; var piece = player.Pieces.Find(p => p.CurrentLocation == origin); if (piece.PreviousLocation == null) { isInitialMove = true; } int limit = 1; if (isInitialMove) { limit = 2; } bool isLegalMoveThroughRows = MoveAssistant.IsLegalMoveThroughRows(player, opponent, origin, destination, limit, false); // If is capture, can move 1 square diagonally toward opponent // ToDo: Handle case of en passant capture!!! bool isCapture = MoveAssistant.IsCapture(opponent, destination); bool isLegalMoveDiagonally = false; if (isCapture) { isLegalMoveDiagonally = MoveAssistant.IsLegalMoveDiagonally(player, opponent, origin, destination, 1, false); } // If legal through rows or diagonally, return True if (isLegalMoveThroughRows || isLegalMoveDiagonally) { return(true); } else { return(false); } }