Esempio n. 1
0
        public void IsLegalMoveAcrossColumns_IsTrue_Test_002()
        {
            // Arrange across columns with capture
            GameController gc = new GameController();

            Location   origin           = gc.GetLocation("A5");
            Location   destination      = gc.GetLocation("H5");
            int        playerIndex      = 1;
            int        otherPlayerIndex = gc.GetOtherPlayerIndex(playerIndex);
            ChessPiece piece            = gc.Players[playerIndex].Pieces
                                          .SingleOrDefault(p => p.CurrentLocation.Coordinate == "A8");
            ChessPiece opponentPiece = gc.Players[otherPlayerIndex].Pieces
                                       .SingleOrDefault(p => p.CurrentLocation.Coordinate == "A1");

            // Fake previous moves that places pieces in desired locations.
            piece.CurrentLocation         = origin;
            opponentPiece.CurrentLocation = destination;

            // Act
            bool isLegalMoveAcrossColumns =
                MoveAssistant.IsLegalMoveAcrossColumns(
                    gc.Players[playerIndex], gc.Players[otherPlayerIndex], origin, destination);

            // Assert
            Assert.IsTrue(isLegalMoveAcrossColumns);
        }
Esempio n. 2
0
        public void IsLegalMoveAcrossColumns_IsFalse_Test_002()
        {
            // Arrange IsFalse because own piece encountered
            GameController gc = new GameController();

            Location   origin           = gc.GetLocation("A5");
            Location   destination      = gc.GetLocation("H5");
            int        playerIndex      = 1;
            int        otherPlayerIndex = gc.GetOtherPlayerIndex(playerIndex);
            ChessPiece piece            = gc.Players[playerIndex].Pieces
                                          .SingleOrDefault(p => p.CurrentLocation.Coordinate == "A8");
            ChessPiece secondPiece = gc.Players[playerIndex].Pieces
                                     .SingleOrDefault(p => p.CurrentLocation.Coordinate == "H8");

            // Fake previous moves that places pieces in desired locations.
            piece.CurrentLocation       = origin;
            secondPiece.CurrentLocation = gc.GetLocation("B5");

            // Act
            bool isLegalMoveAcrossColumns =
                MoveAssistant.IsLegalMoveAcrossColumns(
                    gc.Players[playerIndex], gc.Players[otherPlayerIndex], origin, destination);

            // Assert
            Assert.IsFalse(isLegalMoveAcrossColumns);
        }
Esempio n. 3
0
        public override bool DidMove(
            Player player, Player opponent, Location origin, Location destination)
        {
            bool isLegalMoveThroughRows =
                MoveAssistant.IsLegalMoveThroughRows(player, opponent, origin, destination);

            bool isLegalMoveAcrossColumns =
                MoveAssistant.IsLegalMoveAcrossColumns(player, opponent, origin, destination);

            // ToDo: Handle special case of Castling

            // If legal through rows or across columns, return True
            if (isLegalMoveThroughRows || isLegalMoveAcrossColumns)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }