예제 #1
0
        public void TestAIState_MergeSortReverseSorted()
        {
            List <AIState> list = new List <AIState>();

            for (int i = 9; i >= 0; i--)
            {
                TestAIState test = new TestAIState("empty");
                test.stateScore = i;
                list.Add(test);
            }

            List <AIState> sortedList = AIState.mergeSort(list);
            bool           sorted     = true;
            double         last       = -1;

            foreach (AIState state in sortedList)
            {
                if (!(state.stateScore.Value >= last))
                {
                    sorted = false;
                    break;
                }
                last = state.stateScore.Value;
            }
            Assert.True(sorted);
        }
예제 #2
0
        public void TestAIState_MergeSortRandom()
        {
            Random         randGen = new Random();
            List <AIState> list    = new List <AIState>();

            for (int i = 0; i < 10; i++)
            {
                TestAIState test = new TestAIState("empty");
                test.stateScore = randGen.NextDouble();
                list.Add(test);
            }

            List <AIState> sortedList = AIState.mergeSort(list);
            bool           sorted     = true;
            double         last       = -1;

            foreach (AIState state in sortedList)
            {
                if (!(state.stateScore.Value >= last))
                {
                    Console.WriteLine("SS: " + state.stateScore.Value + " Last " + last);
                    sorted = false;
                    break;
                }
                last = state.stateScore.Value;
            }
            Assert.True(sorted);
        }
예제 #3
0
        public override List <AIState> generateChildren()
        {
            List <AIState> children = new List <AIState>();

            if (hasChidren)
            {
                for (int i = 0; i < 10; i++)
                {
                    Random  gen   = new Random();
                    AIState child = new TestAIState("empty");
                    child.stateScore = gen.NextDouble();
                    children.Add(child);
                }
            }
            this.children = children;
            return(children);
        }
예제 #4
0
        public void TestAIState_Win()
        {
            AIState head  = new TestAIState("empty");
            AIState tail1 = new TestAIState("empty");

            tail1.parent = head;
            AIState tail2 = new TestAIState("empty");

            tail2.parent = tail1;
            AIState tail3 = new TestAIState("empty");

            tail3.parent = tail2;
            tail3.addWin();
            Assert.True(tail3.wins == 1 && tail3.losses == 0);
            Assert.True(tail2.wins == 0 && tail2.losses == 1);
            Assert.True(tail1.wins == 1 && tail1.losses == 0);
            Assert.True(head.wins == 0 && head.losses == 1);
        }