Ejemplo n.º 1
0
        public void Should_ReturnTrueForCaptureInLastFifty()
        {
            // setup
            IMoveHistory  history = ModelLocator.MoveHistory;
            IPiece        piece1  = _chessPieceFactory.CreatePawn(ChessPosition.A2, ChessColor.White);
            IPlayerAction move1   = ModelLocator.Move;

            move1.StartingPosition = piece1.Location;
            move1.EndingPosition   = ChessPosition.A4;

            IPiece        piece2 = _chessPieceFactory.CreatePawn(ChessPosition.A7, ChessColor.Black);
            IPlayerAction move2  = ModelLocator.Move;

            move2.StartingPosition = piece1.Location;
            move2.EndingPosition   = ChessPosition.A5;

            // execute
            for (var i = 0; i < 50; i++)
            {
                history.Add(piece1, move1);
                history.Add(piece2, move2);
            }

            history.Add(piece1, new Capture {
                StartingPosition = piece1.Location, EndingPosition = ChessPosition.B3
            });

            // validate
            Assert.IsTrue(history.WasPieceCapturedInLastFiftyMoves);
        }
Ejemplo n.º 2
0
        public void Should_AddMoveToMoveNotationHistory()
        {
            // setup
            IMoveHistory  history = ModelLocator.MoveHistory;
            IPiece        piece1  = _chessPieceFactory.CreatePawn(ChessPosition.A2, ChessColor.White);
            IPlayerAction move1   = ModelLocator.Move;

            move1.StartingPosition = piece1.Location;
            move1.EndingPosition   = ChessPosition.A4;

            IPiece        piece2 = _chessPieceFactory.CreatePawn(ChessPosition.A7, ChessColor.Black);
            IPlayerAction move2  = ModelLocator.Move;

            move2.StartingPosition = piece1.Location;
            move2.EndingPosition   = ChessPosition.A5;

            // execute
            history.Add(piece1, move1);
            var notation1 = new string(history.MovesByNotation.First().ToCharArray());

            history.Add(piece2, move2);
            var notation2 = new string(history.MovesByNotation.First().ToCharArray());

            //validate
            Assert.AreNotEqual(notation1, notation2);
            Assert.IsTrue(notation2.StartsWith(notation1));
        }
Ejemplo n.º 3
0
        public void Should_ReturnTrueForPawnMovedInLastFiftyMoves()
        {
            // setup
            IMoveHistory  history = ModelLocator.MoveHistory;
            IPiece        piece1  = _chessPieceFactory.CreatePawn(ChessPosition.A2, ChessColor.White);
            IPlayerAction move1   = ModelLocator.Move;

            move1.StartingPosition = piece1.Location;
            move1.EndingPosition   = ChessPosition.A4;

            // execute
            history.Add(piece1, move1);

            // verify
            Assert.IsTrue(history.WasPawnMovedInLastFiftyMoves);
        }
Ejemplo n.º 4
0
        public void Should_AddPieceToMoves()
        {
            // setup
            IMoveHistory  history = ModelLocator.MoveHistory;
            IPiece        piece   = _chessPieceFactory.CreatePawn(ChessPosition.A2, ChessColor.White);
            IPlayerAction move    = ModelLocator.Move;

            move.StartingPosition = piece.Location;
            move.EndingPosition   = ChessPosition.A4;

            // execute
            history.Add(piece, move);

            // validate
            IPiece        p = history.Moves.First().piece;
            IPlayerAction m = history.Moves.First().movable;

            Assert.AreEqual(1, history.Count);
            Assert.IsTrue(p is IPawn);
            Assert.IsTrue(m.StartingPosition == move.StartingPosition);
            Assert.IsTrue(m.EndingPosition == move.EndingPosition);
        }