Example #1
0
        public void GetValidMoves_KnightInCornerOfBoardAndBoardIsClean_Returns2ValidMoves(int x, int y)
        {
            var knight     = new Knight(new Point(x, y));
            var cleanBoard = CleanBoardGenerator.CreateCleanBoardOfSize(Constants.BoardSize);

            var validMoves = knight.GetValidMoves(cleanBoard);

            Assert.That(validMoves.Count, Is.EqualTo(2));
        }
Example #2
0
        public void CreateCleanBoardOfSize_GivenSize_ReturnsBoardOfGivenSize()
        {
            var board      = CleanBoardGenerator.CreateCleanBoardOfSize(Constants.BoardSize);
            var rowOfFalse = new[] { false, false, false, false, false, false, false, false };

            foreach (var row in board)
            {
                Assert.That(row, Is.EqualTo(rowOfFalse));
            }
        }
Example #3
0
        public void GetValidMoves_KnightInMiddleOfBoardAndBoardIsClean_Returns8ValidMoves()
        {
            var knight     = CreateKnightInMiddleOfBoard();
            var cleanBoard = CleanBoardGenerator.CreateCleanBoardOfSize(Constants.BoardSize);

            var validMoves = knight.GetValidMoves(cleanBoard);

            Assert.Multiple(() =>
            {
                Assert.That(validMoves.Count, Is.EqualTo(8));
                CollectionAssert.Contains(validMoves, new Move(knight.CurrentPosition.X + 2, knight.CurrentPosition.Y + 1));
                CollectionAssert.Contains(validMoves, new Move(knight.CurrentPosition.X + 2, knight.CurrentPosition.Y - 1));
                CollectionAssert.Contains(validMoves, new Move(knight.CurrentPosition.X - 2, knight.CurrentPosition.Y + 1));
                CollectionAssert.Contains(validMoves, new Move(knight.CurrentPosition.X - 2, knight.CurrentPosition.Y - 1));
                CollectionAssert.Contains(validMoves, new Move(knight.CurrentPosition.X + 1, knight.CurrentPosition.Y + 2));
                CollectionAssert.Contains(validMoves, new Move(knight.CurrentPosition.X + 1, knight.CurrentPosition.Y - 2));
                CollectionAssert.Contains(validMoves, new Move(knight.CurrentPosition.X - 1, knight.CurrentPosition.Y + 2));
                CollectionAssert.Contains(validMoves, new Move(knight.CurrentPosition.X - 1, knight.CurrentPosition.Y - 2));
            });
        }
        public void FindBestMove_BoardIsCleanAndThereAre2ValidMoves_ReturnsMoveAfterWhichKnightCanMakeTheLeastNumberOfMoves()
        {
            var evaluationFunction = new EvaluationFunction();
            var cleanBoard         = CleanBoardGenerator.CreateCleanBoardOfSize(Constants.BoardSize);
            var actualBestMove     = new Move()
            {
                X = 0, Y = 0
            };
            // После хода в клетку (0, 0) у коня есть только 1 возможный ход, а после хода в клетку (4, 3) - 7
            var validMoves = new List <Move>
            {
                actualBestMove,
                new Move()
                {
                    X = 4, Y = 3
                }
            };

            var result = evaluationFunction.FindBestMove(cleanBoard, validMoves);

            Assert.That(result, Is.EqualTo(actualBestMove));
        }