예제 #1
0
        public void GetThreatsFuzzTest()
        {
            Random random = new Random(0);

            const int gameLimit = 200;

            for (int game = 1; game < gameLimit; game++)
            {
                Grid_Accessor grid = new Grid_Accessor(new PrivateObject(new Grid(7, 6, 0)));

                // Play a full random, game, and verify threats after each move.
                for (int i = 0; i < 7 * 6 && grid.IsGameOver() == -1; i++)
                {
                    ValidateThreats(grid, 0);
                    ValidateThreats(grid, 1);

                    int move;
                    do
                    {
                        move = random.Next(grid.Width);
                    } while (!grid.IsValidMove(move));

                    int player = i & 1;
                    grid.Move(move, player);
                }
            }
        }
예제 #2
0
 public void IsNewColumnNeededAtLeftTest1()
 {
     Grid_Accessor target = new Grid_Accessor(); // TODO: Initialize to an appropriate value
     target.LoadPattern("- X -\nX - X\n- X -");
     bool expected = false; // TODO: Initialize to an appropriate value
     bool actual;
     actual = target.IsNewColumnNeededAtLeft();
     Assert.AreEqual(expected, actual);
 }
예제 #3
0
        public void GetThreatsFindsSimpleHorizontalThreat()
        {
            Grid_Accessor grid = new Grid_Accessor(new PrivateObject(new Grid(7, 6, 0)));

            grid.Move(1, 0);
            grid.Move(1, 1);
            grid.Move(2, 0);
            grid.Move(2, 1);
            grid.Move(3, 0);
            grid.Move(3, 1);

            ValidateThreats(grid, 0);
            ValidateThreats(grid, 1);
        }
예제 #4
0
        public void GetNeighboursCountTest()
        {
            bool[,] testVals = {{true, true, true, false, false, false},
                               {true, true, true, false, false, true},
                               {true, true, true, false, false, false}};

            Grid_Accessor target = new Grid_Accessor(testVals); // TODO: Initialize to an appropriate value

            Assert.AreEqual(3, target.GetNeighboursCount(0, 0));
            Assert.AreEqual(5, target.GetNeighboursCount(0, 1));
            Assert.AreEqual(3, target.GetNeighboursCount(0, 2));
            Assert.AreEqual(5, target.GetNeighboursCount(1, 0));
            Assert.AreEqual(8, target.GetNeighboursCount(1, 1));
            Assert.AreEqual(5, target.GetNeighboursCount(1, 2));
            Assert.AreEqual(2, target.GetNeighboursCount(3, 0));
            Assert.AreEqual(1, target.GetNeighboursCount(5, 0));
        }
예제 #5
0
        private void ValidateThreats(Grid_Accessor grid, int player)
        {
            ulong threats = grid.GetThreats(player);

            for (int i = 0; i < (grid.Height + 1) * grid.Width; i++)
            {
                ulong mask = 1UL << i;
                bool isThreat = (threats & mask) == mask;
                bool isInBuffer = ((i + 1) % (grid.Height + 1)) == 0;

                if (isThreat)
                {
                    Assert.AreEqual(0UL, grid.playerPositions[0] & mask,
                        "Player cannot have a threat in a nonempty location");
                    Assert.AreEqual(0UL, grid.playerPositions[1] & mask,
                        "Player cannot have a threat in a nonempty location");

                    Assert.IsTrue(!isInBuffer,
                        "Cannot have a threat in the column buffer");
                }

                if (!isInBuffer)
                {
                    ulong originalPosition = grid.playerPositions[player];
                    grid.playerPositions[player] |= mask & ~grid.playerPositions[1 - player];
                    Assert.AreEqual(isThreat, grid.IsGameOver(player));
                    grid.playerPositions[player] = originalPosition;
                }
            }

            Assert.AreEqual(0UL, threats >> ((grid.Height + 1) * grid.Width),
                "Threats must be on the board");
        }
예제 #6
0
        public void GetThreatsReturns0OnEmptyBoard()
        {
            Grid_Accessor grid = new Grid_Accessor(new PrivateObject(new Grid(7, 6, 0)));

            ValidateThreats(grid, 0);
            ValidateThreats(grid, 1);
        }
예제 #7
0
        public void GetThreatsIgnoresBlockedHorizontalThreats()
        {
            Grid_Accessor grid = new Grid_Accessor(new PrivateObject(new Grid(7, 6, 0)));

            grid.Move(1, 0);
            grid.Move(1, 1);
            grid.Move(2, 0);
            grid.Move(2, 1);
            grid.Move(3, 0);
            grid.Move(3, 1);
            grid.Move(6, 0);
            grid.Move(0, 1);
            grid.Move(0, 0);

            ValidateThreats(grid, 0);
            ValidateThreats(grid, 1);
        }
예제 #8
0
        public void GetThreatsIgnoresBlockedByEdge()
        {
            Grid_Accessor grid = new Grid_Accessor(new PrivateObject(new Grid(7, 6, 0)));

            grid.Move(6, 0);
            grid.Move(6, 1);
            grid.Move(5, 0);
            grid.Move(5, 1);
            grid.Move(4, 0);
            grid.Move(4, 1);

            ValidateThreats(grid, 0);
            ValidateThreats(grid, 1);
        }
예제 #9
0
 public void IsNewColumnNeededAtRightTest()
 {
     Grid_Accessor target = new Grid_Accessor(); // TODO: Initialize to an appropriate value
     target.LoadPattern("X X X\nX X X\nX X X");
     bool expected = true; // TODO: Initialize to an appropriate value
     bool actual;
     actual = target.IsNewColumnNeededAtRight();
     Assert.AreEqual(expected, actual);
 }
예제 #10
0
        static void GetNewGrid(out int width, out int height, out Grid_Accessor target, out bool[,] cellsCopy)
        {
            Random random = new Random();
            width = random.Next(2, 100);
            height = random.Next(2, 100);
            target = new Grid_Accessor(width, height);
            for (int i = 0; i < width; ++i)
            {
                for (int j = 0; j < height; ++j)
                {
                    target.Cells[j, i] = ((random.Next(0, 2)) == 1);
                }
            }

            cellsCopy = new bool[height, width];
            Array.Copy(target.Cells, cellsCopy, target.Cells.Length);
        }