Esempio n. 1
0
 public void AiMove()
 {
     if (SimulatorID == 1)
     {
         PrintCommand(CC.InternalAITurn(CurrentSim));
         if (turn % 2 == 0)
         {
             turn++;
         }
         else
         {
             turn--;
         }
         if (CurrentSim.Finished())
         {
             PrintResults(CurrentSim.GetUnweightedResult(1));
         }
         Running = false;
     }
     else if (SimulatorID == 2)
     {
         UltTTT.PrintCommand(CC.InternalAITurn(CurrentSim));
         if (CurrentSim.Finished())
         {
             UltTTT.PrintResults(CurrentSim.GetUnweightedResult(1));
         }
     }
     long[] Temp = CC.GetDecisionTime(0);
     for (int i = 0; i < Temp.Length; i++)
     {
         //OtherLogBox.AppendText("" + Temp[i] + Environment.NewLine);
     }
 }
 public void SingleCCTurn(InternalSimulator TestSim, int cc, int Player)
 {
     if (cc == -1)
     {
         while (TestSim.Turn() == Player && !TestSim.Finished())
         {
             IDT.setObjectArgs(TestSim.GetData(Player));
             IDT.SetState(true);
             BaseL.GetArrays();
             BaseL.ForceNodeClustersToGetData();
             BaseL.NodeCalculations();
             TestSim.SetCommand(BaseL.GetAllDecisions());
             IDT.SetState(false);
             currentCommandNumber = TestSim.ReturnChosenCommand();
             CCLog(this, new CommandCArgs(new int[] { currentCommandNumber, Player }));
         }
     }
     else
     {
         while (TestSim.Turn() == Player && !TestSim.Finished())
         {
         }
         IDT.setObjectArgs(TestSim.GetData(Player));
         IDT.SetState(true);
         CC[cc].GetArrays();
         CC[cc].ForceNodeClustersToGetData();
         CC[cc].NodeCalculations();
         TestSim.SetCommand(CC[cc].GetAllDecisions());
         IDT.SetState(false);
         currentCommandNumber = TestSim.ReturnChosenCommand();
         CCLog(this, new CommandCArgs(new int[] { currentCommandNumber, Player }));
         if (PlayMode == 0)
         {
             CC[cc].LogCluster(currentCommandNumber);
         }
     }
 }
 public void RandomizerTurn(InternalSimulator TestSim)
 {
     if (!TestSim.Finished())
     {
         object[] temp  = RandomInput.GetRandomDecision();
         int      temp2 = ((int)((object[])temp[0])[0]);
         TestSim.SetCommand(temp);
         int i = RandomInput.ReturnDecisionCount();
         int j = 0;
         while (TestSim.ReturnChosenCommand() != temp2)
         {
             temp  = RandomInput.GetRandomDecision();
             temp2 = ((int)((object[])temp[0])[0]);
             TestSim.SetCommand(temp);
             j++;
             if (i == j)
             {
                 break;
             }
         }
     }
 }
        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);
            }
        }
        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.");
                }
            }
        }
 public int InternalAITurn(InternalSimulator TestSim)
 {
     if (CC != null)
     {
         if (!TestSim.Finished())
         {
             if (PlayerMode == 1)
             {
                 // The human is always player 1, the AI take up the remaining players
                 int Move = 0;
                 for (int i = 0; i < CC.Length; i++)
                 {
                     if (TestSim.Turn() == i + 2)
                     {
                         Move = i;
                     }
                 }
                 while (TestSim.Turn() == Move + 2 && !TestSim.Finished())
                 {
                     IDT.setObjectArgs(TestSim.GetData(Move + 2));
                     IDT.SetState(true);
                     CC[Move].GetArrays();
                     CC[Move].ForceNodeClustersToGetData();
                     CC[Move].NodeCalculations();
                     //CC[Move].LegacyNodeCalculations();
                     TestSim.SetCommand(CC[Move].GetAllDecisions());
                     IDT.SetState(false);
                     currentCommandNumber = TestSim.ReturnChosenCommand();
                     CCLog(this, new CommandCArgs(new int[] { currentCommandNumber, Move + 2 }));
                     if (PlayMode == 0)
                     {
                         CC[Move].LogCluster(currentCommandNumber);
                     }
                 }
             }
             else if (PlayerMode == 2)
             {
                 int Move = 0;
                 for (int i = 0; i < CC.Length; i++)
                 {
                     if (TestSim.Turn() == i + 1)
                     {
                         Move = i;
                     }
                 }
                 while (TestSim.Turn() == Move + 1 && !TestSim.Finished())
                 {
                     IDT.setObjectArgs(TestSim.GetData(Move + 1));
                     IDT.SetState(true);
                     CC[Move].GetArrays();
                     CC[Move].ForceNodeClustersToGetData();
                     CC[Move].NodeCalculations();
                     TestSim.SetCommand(CC[Move].GetAllDecisions());
                     IDT.SetState(false);
                     currentCommandNumber = TestSim.ReturnChosenCommand();
                     CCLog(this, new CommandCArgs(new int[] { currentCommandNumber, Move + 1 }));
                     if (PlayMode == 0)
                     {
                         CC[Move].LogCluster(currentCommandNumber);
                     }
                 }
             }
             else if (PlayerMode == 3)
             {
                 int Move = 0;
                 for (int i = 0; i < CC.Length; i++)
                 {
                     if (TestSim.Turn() == i + 2)
                     {
                         Move = i;
                     }
                 }
                 while (TestSim.Turn() == Move + 2 && !TestSim.Finished())
                 {
                     IDT.setObjectArgs(TestSim.GetData(Move + 2));
                     IDT.SetState(true);
                     CC[Move].GetArrays();
                     CC[Move].ForceNodeClustersToGetData();
                     CC[Move].NodeCalculations();
                     TestSim.SetCommand(CC[Move].GetAllDecisions());
                     IDT.SetState(false);
                     currentCommandNumber = TestSim.ReturnChosenCommand();
                     CCLog(this, new CommandCArgs(new int[] { currentCommandNumber, Move }));
                     if (PlayMode == 0)
                     {
                         CC[Move].LogCluster(currentCommandNumber);
                     }
                 }
             }
             return(currentCommandNumber);
         }
         else
         {
             return(-1);
         }
     }
     else
     {
         return(-1);
     }
 }