Пример #1
0
        public void TestRightLineMoveRightFail()
        {
            var chessBoard = new ChessBoard();

            chessBoard.AddNew(new Position(0, 3), ChessBoardHandler.RandomLevel());
            chessBoard.AddNew(new Position(1, 3), ChessBoardHandler.RandomLevel());
            chessBoard.AddNew(new Position(2, 3), ChessBoardHandler.RandomLevel());
            chessBoard.AddNew(new Position(3, 3), ChessBoardHandler.RandomLevel());

            Assert.AreEqual(chessBoard.Move(Direction.Right), false);
        }
Пример #2
0
        public void TestLeftLineMoveLeftFail()
        {
            var chessBoard = new ChessBoard();

            chessBoard.AddNew(new Position(0, 0), ChessBoardHandler.RandomLevel());
            chessBoard.AddNew(new Position(1, 0), ChessBoardHandler.RandomLevel());
            chessBoard.AddNew(new Position(2, 0), ChessBoardHandler.RandomLevel());
            chessBoard.AddNew(new Position(3, 0), ChessBoardHandler.RandomLevel());

            Assert.AreEqual(chessBoard.Move(Direction.Left), false);
        }
Пример #3
0
        public void TestToplLineMoveUpFail()
        {
            var chessBoard = new ChessBoard();

            chessBoard.AddNew(new Position(0, 0), ChessBoardHandler.RandomLevel());
            chessBoard.AddNew(new Position(0, 1), ChessBoardHandler.RandomLevel());
            chessBoard.AddNew(new Position(0, 2), ChessBoardHandler.RandomLevel());
            chessBoard.AddNew(new Position(0, 3), ChessBoardHandler.RandomLevel());

            Assert.AreEqual(chessBoard.Move(Direction.Up), false);
        }
Пример #4
0
        public void TestBottomLineMoveDownFail()
        {
            var chessBoard = new ChessBoard();

            chessBoard.AddNew(new Position(3, 0), ChessBoardHandler.RandomLevel());
            chessBoard.AddNew(new Position(3, 1), ChessBoardHandler.RandomLevel());
            chessBoard.AddNew(new Position(3, 2), ChessBoardHandler.RandomLevel());
            chessBoard.AddNew(new Position(3, 3), ChessBoardHandler.RandomLevel());

            Assert.AreEqual(chessBoard.Move(Direction.Down), false);
        }
Пример #5
0
        public void SingleRandomAddTheSamePlaceTest()
        {
            var chessBoard     = new ChessBoard();
            int randomRow      = RandomGenerator.Next(4);
            int randomCol      = RandomGenerator.Next(4);
            var randomPosition = new Position(randomRow, randomCol);

            chessBoard.AddNew(randomPosition, ChessBoardHandler.RandomLevel());
            chessBoard.AddNew(randomPosition, ChessBoardHandler.RandomLevel());

            Assert.AreEqual(chessBoard.EmptyCount, 15);
        }
Пример #6
0
        public void TransposeLeftTest()
        {
            for (int i = 0; i < 100; ++i)
            {
                var chessBoard = new ChessBoard();
                ChessBoardHandler.AddLeftDiagonal(chessBoard);
                ChessBoardHandler.AddSymmetryToLeftDiagonal(chessBoard);

                Assert.AreEqual(chessBoard, chessBoard.ToTransposeLeft());
                chessBoard.RandomAdd();
                Assert.AreNotEqual(chessBoard, chessBoard.ToTransposeLeft());
            }
        }
Пример #7
0
        public void AddNewTest()
        {
            for (int i = 0; i < 100; ++i)
            {
                var chessBoard  = new ChessBoard();
                int occupyCount = RandomGenerator.Next(16);

                ChessBoardHandler.RandomAddLevelOne(chessBoard, occupyCount);
                var emptyPositions = chessBoard.GetEmptyPositions();

                Assert.AreEqual(emptyPositions.Count, 16 - occupyCount);
                Assert.AreEqual(chessBoard.EmptyCount, 16 - occupyCount);
            }
        }
Пример #8
0
        public void TestLineMoveUpMergeOnce()
        {
            for (int col = 0; col < 4; ++col)
            {
                var chessBoard = new ChessBoard();
                int level      = ChessBoardHandler.RandomLevel();
                var rows       = RandomGenerator.GetDistinctInts(2, 4);

                chessBoard.AddNew(new Position(rows[0], col), level);
                chessBoard.AddNew(new Position(rows[1], col), level);

                Assert.AreEqual(chessBoard.Move(Direction.Up), true);
                Assert.AreEqual(chessBoard.EmptyCount, 15);
            }
        }
Пример #9
0
        public void TestLineMoveRightMergeOnce()
        {
            for (int row = 0; row < 4; ++row)
            {
                var chessBoard = new ChessBoard();
                int level      = ChessBoardHandler.RandomLevel();
                var cols       = RandomGenerator.GetDistinctInts(2, 4);

                chessBoard.AddNew(new Position(row, cols[0]), level);
                chessBoard.AddNew(new Position(row, cols[1]), level);

                Assert.AreEqual(chessBoard.Move(Direction.Right), true);
                Assert.AreEqual(chessBoard.EmptyCount, 15);
            }
        }
Пример #10
0
 public void TransposeRightTest()
 {
     for (int i = 0; i < 100; ++i)
     {
         var chessBoard = new ChessBoard();
         ChessBoardHandler.AddRightDiagonal(chessBoard);
         chessBoard.AddNew(new Position(0, 0), 10);
         chessBoard.AddNew(new Position(3, 3), 10);
         Assert.AreEqual(chessBoard, chessBoard.ToTransposeRight());
         chessBoard.RandomAdd();
         Assert.AreNotEqual(chessBoard, chessBoard.ToTransposeRight());
         Assert.AreEqual(Evaluator.EvalForMove(chessBoard), Evaluator.EvalForMove(chessBoard.ToTransposeRight()), 0.01);
         Assert.AreEqual(Evaluator.EvalForAdd(chessBoard), Evaluator.EvalForAdd(chessBoard.ToTransposeRight()), 0.01);
     }
 }
Пример #11
0
        public void TestMoveRightOneDistinctLineFail()
        {
            for (int row = 0; row < 4; ++row)
            {
                var chessBoard = new ChessBoard();
                var levels     = ChessBoardHandler.GetRandomDistinctLevels(4);

                chessBoard.AddNew(new Position(row, 0), levels[0]);
                chessBoard.AddNew(new Position(row, 1), levels[1]);
                chessBoard.AddNew(new Position(row, 2), levels[2]);
                chessBoard.AddNew(new Position(row, 3), levels[3]);

                Assert.AreEqual(chessBoard.Move(Direction.Right), false);
            }
        }
Пример #12
0
        public void TestLineMoveDownSuccess()
        {
            for (int col = 0; col < 4; ++col)
            {
                var chessBoard = new ChessBoard();
                var levels     = ChessBoardHandler.GetRandomDistinctLevels(2);
                var rows       = RandomGenerator.GetDistinctInts(2, 0, 3);

                chessBoard.AddNew(new Position(rows[0], col), levels[0]);
                chessBoard.AddNew(new Position(rows[1], col), levels[1]);

                Assert.AreEqual(chessBoard.Move(Direction.Down), true);
                Assert.AreEqual(chessBoard.EmptyCount, 14);
            }
        }
Пример #13
0
        public void TestDistinctLineMoveDownFail()
        {
            for (int col = 0; col < 4; ++col)
            {
                var chessBoard = new ChessBoard();
                var levels     = ChessBoardHandler.GetRandomDistinctLevels(4);

                chessBoard.AddNew(new Position(0, col), levels[0]);
                chessBoard.AddNew(new Position(1, col), levels[1]);
                chessBoard.AddNew(new Position(2, col), levels[2]);
                chessBoard.AddNew(new Position(3, col), levels[3]);

                Assert.AreEqual(chessBoard.Move(Direction.Down), false);
            }
        }
Пример #14
0
        public void TestLineMoveRightSuccess()
        {
            for (int row = 0; row < 4; ++row)
            {
                var chessBoard = new ChessBoard();
                var levels     = ChessBoardHandler.GetRandomDistinctLevels(2);
                var cols       = RandomGenerator.GetDistinctInts(2, 0, 3);

                chessBoard.AddNew(new Position(row, cols[0]), levels[0]);
                chessBoard.AddNew(new Position(row, cols[1]), levels[1]);

                Assert.AreEqual(chessBoard.Move(Direction.Right), true);
                Assert.AreEqual(chessBoard.EmptyCount, 14);
            }
        }
Пример #15
0
        public void RandomAddNewSetEmptyTest()
        {
            var addEmptyBoard  = new ChessBoard();
            var emptyPositions = addEmptyBoard.GetEmptyPositions();
            int occupyCount    = RandomGenerator.Next(emptyPositions.Count);

            for (int i = 0; i < occupyCount; ++i)
            {
                addEmptyBoard.AddNew(emptyPositions[i], ChessBoardHandler.RandomLevel());
                addEmptyBoard.SetEmpty(emptyPositions[i]);
            }
            var emptyBoard = new ChessBoard();

            Assert.AreEqual(addEmptyBoard.EmptyCount, 16);
            Assert.AreEqual(addEmptyBoard, emptyBoard);
        }
Пример #16
0
        public void TestLineMoveRightMergeTwice()
        {
            for (int row = 0; row < 4; ++row)
            {
                var chessBoard = new ChessBoard();
                var levels     = ChessBoardHandler.GetRandomDistinctLevels(2);

                chessBoard.AddNew(new Position(row, 0), levels[0]);
                chessBoard.AddNew(new Position(row, 1), levels[0]);
                chessBoard.AddNew(new Position(row, 2), levels[1]);
                chessBoard.AddNew(new Position(row, 3), levels[1]);

                Assert.AreEqual(chessBoard.Move(Direction.Right), true);
                Assert.AreEqual(chessBoard.EmptyCount, 14);
            }
        }
Пример #17
0
        public void TestLineMoveLeftMergeTwice()
        {
            for (int i = 0; i < 4; ++i)
            {
                var chessBoard = new ChessBoard();
                var levels     = ChessBoardHandler.GetRandomDistinctLevels(2);

                chessBoard.AddNew(new Position(i, 0), levels[0]);
                chessBoard.AddNew(new Position(i, 1), levels[0]);
                chessBoard.AddNew(new Position(i, 2), levels[1]);
                chessBoard.AddNew(new Position(i, 3), levels[1]);

                Assert.AreEqual(chessBoard.Move(Direction.Left), true);
                Assert.AreEqual(chessBoard.EmptyCount, 14);
            }
        }
Пример #18
0
        public void TestLineMoveUpMergeTwice()
        {
            for (int col = 0; col < 4; ++col)
            {
                var chessBoard = new ChessBoard();
                var levels     = ChessBoardHandler.GetRandomDistinctLevels(2);

                chessBoard.AddNew(new Position(0, col), levels[0]);
                chessBoard.AddNew(new Position(1, col), levels[0]);
                chessBoard.AddNew(new Position(2, col), levels[1]);
                chessBoard.AddNew(new Position(3, col), levels[1]);

                Assert.AreEqual(chessBoard.Move(Direction.Up), true);
                Assert.AreEqual(chessBoard.EmptyCount, 14);
            }
        }
Пример #19
0
        public void TestDistinctCount()
        {
            var chessBoard = new ChessBoard();
            var levels     = ChessBoardHandler.GetRandomCountDistinctLevels();
            int levelIndex = 0;

            for (int row = 0; row < 4; ++row)
            {
                for (int col = 0; col < 4; ++col)
                {
                    if (levelIndex == levels.Length)
                    {
                        break;
                    }
                    chessBoard.AddNew(new Position(row, col), levels[levelIndex]);
                    ++levelIndex;
                }
            }
            Assert.AreEqual(chessBoard.DistinctCount, levels.Length);
        }