コード例 #1
0
        public void IsLegalMoveThroughRows_IsTrue_Test_002()
        {
            //Arrange is legal move through rows with capture
            GameController gc = new GameController();

            Location   origin           = gc.GetLocation("A5");
            Location   destination      = gc.GetLocation("A1");
            int        playerIndex      = 1;
            int        otherPlayerIndex = gc.GetOtherPlayerIndex(playerIndex);
            ChessPiece piece            = gc.Players[playerIndex].Pieces
                                          .SingleOrDefault(p => p.CurrentLocation.Coordinate == "A8");
            // Fake previous moves that places pieces in desired location.
            ChessPiece opponentPiece = gc.Players[otherPlayerIndex].Pieces
                                       .SingleOrDefault(p => p.CurrentLocation.Coordinate == "A1");

            piece.CurrentLocation = origin;

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

            // Assert
            Assert.IsTrue(isLegalMoveThroughRows);
        }
コード例 #2
0
        public void IsLegalMoveThroughRows_IsFalse_Test_004()
        {
            // Arrange decremented IsFalse because opponent piece encountered
            GameController gc = new GameController();

            Location   origin           = gc.GetLocation("A5");
            Location   destination      = gc.GetLocation("A1");
            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 = gc.GetLocation("A4");

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

            // Assert
            Assert.IsFalse(isLegalMoveThroughRows);
        }
コード例 #3
0
ファイル: Pawn.cs プロジェクト: margakkrumins/GamesExample
        // 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);
            }
        }
コード例 #4
0
ファイル: Rook.cs プロジェクト: margakkrumins/GamesExample
        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);
            }
        }
コード例 #5
0
        public void IsLegalMoveThroughRows_IsFalse_Test_006()
        {
            // Arrange IsFalse because exceeded limit for subsequent moves of pawn
            GameController gc = new GameController();

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

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

            // Act
            bool isLegalMoveThroughRows =
                MoveAssistant.IsLegalMoveThroughRows(
                    gc.Players[playerIndex], gc.Players[otherPlayerIndex], origin, destination, 1, false);

            // Assert
            Assert.IsFalse(isLegalMoveThroughRows);
        }