Exemplo n.º 1
0
        public void TestFSimulateAllChildrenOnce()
        {
            UltimateBoard b = Games.GetBoard(Games.Draw, 53);

            b.Play((1, 0, 1, 0));
            b.Play((1, 0, 0, 0));
            b.Play((0, 1, 2, 0));
            b.Play((1, 0, 1, 2)); // This board position has four available plays.
            GameTreeNode t = new GameTreeNode((1, 0, 1, 2));

            for (int i = 0; i < 5; i++)
            {
                // The second iteration adds the four children and does a simulation on one
                // of them. The next three should each do a simulation on a different child
                // without adding any grandchildren.
                t.Simulate(new UltimateBoard(b));
            }
            List <(int, int, int, int)> avail = b.GetAvailablePlays();
            StringBuilder results             = new StringBuilder();

            foreach ((int, int, int, int)play in avail)
            {
                GameTreeNode grandchild = null;
                try
                {
                    grandchild = t.GetChild(play).GetChild((1, 0, 0, 2)); // (1, 0, 0, 2) is an available response to each available play.
                    results.Append(grandchild.Play.ToString());
                }
                catch // The above will throw an exception if the grandchild hasn't been added.
                {
                    results.Append("OK;");
                }
            }
            Assert.That(results.ToString(), Is.EqualTo("OK;OK;OK;OK;")); // t should not contain any of the grandchildren.
        }
Exemplo n.º 2
0
        public void TestBAddChildren()
        {
            UltimateBoard b = Games.GetBoard(Games.XWins, 43);
            GameTreeNode  t = new GameTreeNode(Games.XWins[42]);

            t.AddChildren(b);
            List <(int, int, int, int)> avail    = b.GetAvailablePlays();
            List <(int, int, int, int)> children = new List <(int, int, int, int)>();

            foreach ((int, int, int, int)play in avail)
            {
                children.Add(t.GetChild(play).Play); // Get the specified child and retrieve its play
            }
            Assert.That(children, Is.EquivalentTo(avail));
        }
Exemplo n.º 3
0
        public void TestBPlaysAvailableAfterFirst()
        {
            UltimateBoard b = new UltimateBoard();

            b.Play((0, 0, 0, 2));
            List <(int, int, int, int)> avail = new List <(int, int, int, int)>();

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    avail.Add((0, 2, i, j)); // Add all squares on small board (0, 2);
                }
            }
            Assert.That(b.GetAvailablePlays(), Is.EquivalentTo(avail));
        }
Exemplo n.º 4
0
        public void TestAAllPlaysInitiallyAvailable()
        {
            List <(int, int, int, int)> allPlays = new List <(int, int, int, int)>();

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    for (int m = 0; m < 3; m++)
                    {
                        for (int n = 0; n < 3; n++)
                        {
                            allPlays.Add((i, j, m, n)); // Add each square on the board.
                        }
                    }
                }
            }
            UltimateBoard b = new UltimateBoard();

            Assert.That(b.GetAvailablePlays(), Is.EquivalentTo(allPlays));
        }