Exemplo n.º 1
0
        // Simulation Tester Methods
        public void InternalSimulatorSetup(bool LoggingState, InternalSimulator TestSimulator)
        {
            IDT.setStringArgs(TestSimulator.GetCommandNames());
            CC = new CommandCenter[TestSimulator.GetPlayerCount()];
            //int ThreadCount = Environment.ProcessorCount * 2;
            //int currentProcessor = 0;
            Thread[] GenerationThreads = new Thread[CC.Length + 1];
            int      CombinationLevel  = (int)IDT.getItem(3, 0, 0);

            for (int i = 0; i < CC.Length; i++)
            {
                CC[i] = new CommandCenter(IDT, "" + CommandCenterCount, LoggingState, this);
                CommandCenterCount++;
                SubCC(CC[i]);
            }
            BaseL = new CommandCenter(IDT, "" + BaseLineCCCount, "Baseline", LoggingState, this);
            BaseLineCCCount++;
            SubCC(BaseL);

            int[][] CommandSig = TestSimulator.GetCommandSignature();
            IDT.setIntArgs(CommandSig);
            RandomInput = new Randomizer((int)IDT.getItem(3, 0, 0));
            for (int i = 0; i < CC.Length; i++)
            {
                CC[i].GetArrays();
                CC[i].SetBounds(TestSimulator.ReturnRecommendedRange());
                CC[i].CreateClustersFromTemplate1();
            }
            BaseL.GetArrays();
            BaseL.SetBounds(TestSimulator.ReturnRecommendedRange());
            BaseL.CreateClustersFromTemplate1();
            int[][] DataSig = new int[1][];
            DataSig[0] = TestSimulator.GetDataSignature();
            IDT.setIntArgs(DataSig);
            string[] Names = IDT.getStringArgs()[0];
            for (int i = 0; i < CC.Length; i++)
            {
                CC[i].SetClusterNames(Names);
            }

            for (int i = -1; i < CC.Length; i++)
            {
                int temp = i;
                GenerationThreads[temp + 1] = new Thread(() => NodeCreation(temp, CombinationLevel, GenerationThreads[temp + 1]));
                GenerationThreads[temp + 1].Start();
            }

            GC.Collect();
            GC.WaitForPendingFinalizers();
            UILog(this, CC.ToString());
        }
Exemplo n.º 2
0
        public void BaseLineTest(InternalSimulator TestSim)
        {
            BaseLineResults = new int[CC.Length][];
            for (int i = 0; i < BaseLineResults.Length; i++)
            {
                BaseLineResults[i] = new int[3];
            }
            int TurnCount     = TestSim.GetPlayerCount();
            int DecisionCount = RandomInput.ReturnDecisionCount();
            int Player1       = 1;

            int[] BaseLPlayers = new int[0];

            for (int j = 0; j < CC.Length; j++)
            {
                CC[j].SetDecisionMode(0);
                for (int i = 0; i < DecisionCount; i++)
                {
                    for (int o = 0; o < 3; o++)
                    {
                        int AITurnCount = 0;

                        StartRound(j, Player1); // Player 1 is CC
                        StartRound(-1, 2);      // Player 2 is Baseline
                        StartRound(TestSim, 2);

                        BaseLPlayers = new int[TurnCount - 1];

                        for (int q = 1; q <= TurnCount - 1; q++)
                        {
                            // The first index is 0, but the first player is 2
                            BaseLPlayers[q - 1] = q + 1;
                        }
                        while (TestSim.Turn() == 2 && !TestSim.Finished())
                        {
                            TestSim.SetCommand(RandomInput.CreateDecisionFromInt(i));
                            CCLog(this, new CommandCArgs(new int[] { TestSim.ReturnChosenCommand(), 2 }));
                        }

                        BaseL.SetDecisionMode(o);

                        int count = 0;

                        while (!TestSim.Finished())
                        {
                            SingleCCTurn(TestSim, j, Player1);
                            AITurnCount++;

                            for (int l = 0; l < BaseLPlayers.Length; l++)
                            {
                                int temp = BaseLPlayers[l];
                                SingleCCTurn(TestSim, -1, temp);
                            }
                            if (count >= DecisionCount)
                            {
                                break;
                            }
                            count++;
                        }
                        int Result = TestSim.GetUnweightedResult(Player1);

                        if (Result == 1)
                        {
                            BaseLineResults[j][0]++;
                        }
                        else if (Result == 0)
                        {
                            BaseLineResults[j][1]++;
                        }
                        if (Result == -1)
                        {
                            BaseLineResults[j][2]++;
                        }
                        EndRound(TestSim, Player1, j);
                        EndRound(TestSim, BaseLPlayers[0], -1);
                    }
                }
                StartRound(j, Player1); // Player 1 is CC
                StartRound(-1, 2);      // Player 2 is Baseline
                StartRound(TestSim, 1);

                int AITurnCount2 = 0;

                int count2 = 0;
                BaseL.SetDecisionMode(0);

                BaseLPlayers = new int[TurnCount - 1];

                for (int q = 1; q <= TurnCount - 1; q++)
                {
                    // The first index is 0, but the first player is 2
                    BaseLPlayers[q - 1] = q + 1;
                }
                int[] PlayedMoves1 = new int[9];

                while (!TestSim.Finished())
                {
                    SingleCCTurn(TestSim, j, Player1);
                    AITurnCount2++;
                    if (TestSim.Finished())
                    {
                        break;
                    }

                    for (int l = 0; l < BaseLPlayers.Length; l++)
                    {
                        int temp = BaseLPlayers[l];
                        SingleCCTurn(TestSim, -1, temp);
                    }
                    if (count2 >= DecisionCount)
                    {
                        break;
                    }
                    count2++;
                }

                int Result2 = TestSim.GetUnweightedResult(Player1);

                if (Result2 == 1)
                {
                    BaseLineResults[j][0]++;
                }
                else if (Result2 == 0)
                {
                    BaseLineResults[j][1]++;
                }
                if (Result2 == -1)
                {
                    BaseLineResults[j][2]++;
                }
                EndRound(TestSim, Player1, j);
                EndRound(TestSim, BaseLPlayers[0], -1);
            }
        }
Exemplo n.º 3
0
        public void AiVRandom(InternalSimulator TestSim, int RunCount)
        {
            if (CC != null)
            {
                for (int j = 0; j < CC.Length; j++)
                {
                    for (int i = 0; i < RunCount; i++)
                    {
                        if (PlayMode == 0)
                        {
                            CC[j].SetDecisionMode(RandomInput.ReturnRandomIntInRange(0, 3));
                        }

                        TestSim.Start();

                        int Turn1 = TestSim.Turn();
                        StartRound(j, Turn1);

                        while (!TestSim.Finished())
                        {
                            SingleCCTurn(TestSim, j, Turn1);
                            RandomizerTurn(TestSim);
                        }
                        if ((i + 1) % 50 == 0)
                        {
                            UILog(this, "" + (i + 1));
                        }
                        EndRound(TestSim, Turn1, j);
                    }
                    for (int i = 0; i < RunCount; i++)
                    {
                        if (PlayMode == 0)
                        {
                            CC[j].SetDecisionMode(RandomInput.ReturnRandomIntInRange(0, 3));
                        }
                        TestSim.Start();

                        int Turn1 = TestSim.Turn();
                        int Turn2 = TestSim.GetPlayerCount() - Turn1;

                        if (Turn2 == 0)
                        {
                            Turn2++;
                        }
                        StartRound(j, Turn2);

                        while (!TestSim.Finished())
                        {
                            RandomizerTurn(TestSim);
                            SingleCCTurn(TestSim, j, Turn2);
                        }
                        if ((i + 1) % 50 == 0)
                        {
                            UILog(this, "" + (i + 1));
                        }
                        EndRound(TestSim, Turn2, j);
                    }
                    UILog(this, "CC[" + j + "] finished.");
                }
            }
        }