public void EatOpponent(int sourceRow, int sourceColumn, bool isBlack, int destinationRow, int destinationColumn, bool result)
        {
            var pawn = new Pawn
            {
                Row     = 2,
                Column  = 2,
                IsBlack = !isBlack
            };

            Formation.Pieces.Add(pawn);

            var king = new King
            {
                Row     = sourceRow,
                Column  = sourceColumn,
                IsBlack = isBlack
            };
            var targetField = new Field(destinationRow, destinationColumn);

            Assert.That(king.CanMove(targetField), Is.EqualTo(result));
            Assert.That(Formation.Pieces.Contains(pawn));

            king.TryConsumeAtTargetField(targetField);

            Assert.That(Formation.Pieces.Contains(pawn), Is.False);
            Assert.That(king.Column, Is.EqualTo(targetField.Column));
            Assert.That(king.Row, Is.EqualTo(targetField.Row));
        }
        public void IsMovementValid(int sourceRow, int sourceColumn, bool isBlack, int destinationRow, int destinationColumn, bool result)
        {
            var king = new King
            {
                Row     = sourceRow,
                Column  = sourceColumn,
                IsBlack = isBlack
            };
            var targetField = new Field(destinationRow, destinationColumn);

            Assert.That(king.CanMove(targetField), Is.EqualTo(result));
        }
Esempio n. 3
0
        public void King_CanMove_TheSamePosition_ShouldReturnFalse()
        {
            // arrange
            Models.Position.Position startingPosition    = new Models.Position.Position(0, 0);
            Models.Position.Position destinationPosition = new Models.Position.Position(0, 0);
            var king = new King(startingPosition, TeamColor.Black);

            // act
            bool result = king.CanMove(destinationPosition);

            // assert
            Assert.False(result);
        }
Esempio n. 4
0
        public void King_CanMove_DiagonalMoveValid_ShouldReturnTrue()
        {
            // arrange
            Models.Position.Position startingPosition = new Models.Position.Position(0, 0);
            var king = new King(startingPosition, TeamColor.Black);

            Models.Position.Position destinationPosition = new Models.Position.Position(1, 1);

            // act
            bool result = king.CanMove(destinationPosition);

            // assert
            Assert.True(result);
        }
        public void IsSomethingInTheWay(int sourceRow, int sourceColumn, bool isBlack, int destinationRow, int destinationColumn, bool result)
        {
            var pawn = new Pawn
            {
                Row     = 2,
                Column  = 2,
                IsBlack = isBlack
            };

            Formation.Pieces.Add(pawn);

            var king = new King
            {
                Row     = sourceRow,
                Column  = sourceColumn,
                IsBlack = isBlack
            };
            var targetField = new Field(destinationRow, destinationColumn);

            Assert.That(king.CanMove(targetField, Formation.Pieces), Is.EqualTo(result));
        }
        //Rochade Test
        public void DoRochade(List <ChessPieceViewModel> otherPieces, bool result)
        {
            otherPieces.ForEach(Formation.Pieces.Add);

            var rook = new Rook
            {
                Row       = 0,
                Column    = 7,
                IsBlack   = false,
                FirstMove = true
            };

            var king = new King
            {
                Row       = 0,
                Column    = 4,
                IsBlack   = false,
                FirstMove = true
            };

            Formation.Pieces.Add(rook);
            Formation.Pieces.Add(king);

            var targetField = new Field(0, 6);

            Assert.That(king.CanMove(targetField), Is.EqualTo(result));
            Assert.That(king.NoChess(targetField), Is.EqualTo(result));
            if (result)
            {
                king.TryMove(targetField, Formation.Pieces);
                Assert.That(king.Column, Is.EqualTo(6));
                Assert.That(rook.Column, Is.EqualTo(5));
            }
            else
            {
                Assert.That(king.Column, Is.EqualTo(4));
                Assert.That(rook.Column, Is.EqualTo(7));
            }
        }