예제 #1
0
    public void Tick(TeamsConfig teamsConfig)
    {
        //Debug.Log("EvaluationManager.Tick()!");

        TickEvaluations(teamsConfig);
        TickExhibition(teamsConfig);
    }
예제 #2
0
    public void ExhibitionNextGenome(TeamsConfig teamsConfig)
    {
        EvaluationTicket exhibitionTicket = exhibitionTicketList[exhibitionTicketCurrentIndex];
        int currentFocusPop = exhibitionTicket.focusPopIndex;

        // AGENT 0
        int currentGenomeIndex0 = exhibitionTicket.agentGenomesList[0].index;

        currentGenomeIndex0++;
        if (currentGenomeIndex0 >= (teamsConfig.playersList[0].agentGenomeList.Count))
        {
            currentGenomeIndex0 = 0;
        }
        exhibitionTicket.agentGenomesList[0] = teamsConfig.playersList[0].agentGenomeList[currentGenomeIndex0];

        // AGENT 1
        int currentGenomeIndex1 = exhibitionTicket.agentGenomesList[1].index;

        currentGenomeIndex1++;
        if (currentGenomeIndex1 >= (teamsConfig.playersList[1].agentGenomeList.Count))
        {
            currentGenomeIndex1 = 0;
        }
        exhibitionTicket.agentGenomesList[1] = teamsConfig.playersList[1].agentGenomeList[currentGenomeIndex1];

        ResetExhibitionInstance(teamsConfig);
    }
예제 #3
0
    public void Initialize(TeamsConfig teamsConfig, TournamentInfo tournamentInfo)
    {
        Debug.Log("TournamentManager Initialize");
        currentTournamentInfo = tournamentInfo;

        // Load Competitors,
        // Create Match Schedule
        // Process Tournament Info:
        tournamentInfo.PrepareTournament(teamsConfig.playersList[0].agentGenomeList[0]);

        gameManager.prestige -= tournamentInfo.entranceFee;

        // Set up Exhibition Instance:
        if (tournamentInstance == null)
        {
            GameObject tournamentInstanceGO = new GameObject("TournamentInstance");
            tournamentInstance = tournamentInstanceGO.AddComponent <EvaluationInstance>();
            tournamentInstance.transform.position = new Vector3(0f, 0f, 0f);
            tournamentInstance.visible            = true;
            tournamentInstance.isExhibition       = true;
        }
        else
        {
            tournamentInstance.gameObject.SetActive(true);
        }
    }
예제 #4
0
 public void TickExhibition(TeamsConfig teamsConfig)
 {
     if (exhibitionInstance.currentEvalTicket == null)
     {
         // first-time setup:
         ResetExhibitionInstance(teamsConfig);
     }
     else
     {
         if (exhibitionInstance.currentEvalTicket.status == EvaluationTicket.EvaluationStatus.Pending)
         {
         }
         else if (exhibitionInstance.currentEvalTicket.status == EvaluationTicket.EvaluationStatus.InProgress)
         {
             exhibitionInstance.Tick();
         }
         else if (exhibitionInstance.currentEvalTicket.status == EvaluationTicket.EvaluationStatus.PendingComplete)
         {
             ExhibitionNextGenome(teamsConfig);
             exhibitionInstance.ClearInstance();
         }
         else    // Complete
         {
             exhibitionInstance.ClearInstance();
         }
     }
 }
예제 #5
0
    public void SetUpInstance(EvaluationTicket evalTicket, TeamsConfig teamsConfig)
    {
        this.teamsConfig  = teamsConfig;
        this.maxTimeSteps = evalTicket.maxTimeSteps;

        currentEvalTicket = evalTicket;

        BruteForceInit();

        currentEvalTicket.status = EvaluationTicket.EvaluationStatus.InProgress;
    }
예제 #6
0
    public void ResetExhibitionTicket(TeamsConfig teamsConfig)
    {
        // Set Genomes:
        int numPlayers = teamsConfig.playersList.Count;

        for (int i = 0; i < numPlayers; i++)
        {
            exhibitionTicketList[0].agentGenomesList[i] = teamsConfig.playersList[i].representativeGenomeList[0];
        }
        exhibitionTicketList[0].environmentGenome = teamsConfig.environmentPopulation.representativeGenomeList[0];
        //exhibitionTicketList[0].environmentGenome.ClearEnvironmentPrefab();
    }
예제 #7
0
    public void LoadTraining(string filePath)
    {
        Debug.Log("LoadTraining: " + filePath);

        // Read the json from the file into a string
        string dataAsJson = File.ReadAllText(filePath);
        // Pass the json to JsonUtility, and tell it to create a GameData object from it
        TeamsConfig loadedData = JsonUtility.FromJson <TeamsConfig>(dataAsJson);

        teamsConfig = loadedData;
        LoadTrainingMode();
    }
예제 #8
0
    public void InitializeExhibitionTickets(TeamsConfig teamsConfig)
    {
        int numPlayers = teamsConfig.playersList.Count;

        List <AgentGenome> agentGenomesList = new List <AgentGenome>();

        for (int i = 0; i < numPlayers; i++)
        {
            agentGenomesList.Add(teamsConfig.playersList[i].representativeGenomeList[0]);
        }
        EvaluationTicket evalTicket = new EvaluationTicket(teamsConfig.environmentPopulation.representativeGenomeList[0], agentGenomesList, 0, maxTimeStepsDefault);

        exhibitionTicketList.Add(evalTicket);
    }
예제 #9
0
    public void ResetForNewGeneration(TeamsConfig teamsConfig)
    {
        for (int i = 0; i < evaluationInstancesList.Count; i++)
        {
            evaluationInstancesList[i].ClearInstance();
        }
        ClearEvaluationTickets();
        CreateDefaultEvaluationTickets(teamsConfig);

        allEvalsComplete = false;
        ResetExhibitionTicket(teamsConfig);
        ResetExhibitionInstance(teamsConfig);
        EnableInstances();
        exhibitionTicketCurrentIndex = 0;
    }
예제 #10
0
    // First-time Initialization -- triggered through gameManager & GUI
    public void NewTrainingMode(Challenge.Type challengeType)
    {
        this.challengeType = challengeType;
        // Initialize
        int numPlayers = 1;

        switch (this.challengeType)
        {
        case Challenge.Type.Test:
            Debug.Log("Switch: Test");
            numPlayers = 1;
            break;

        case Challenge.Type.Racing:
            Debug.Log("Switch: Racing");
            numPlayers = 1;
            break;

        case Challenge.Type.Combat:
            Debug.Log("Switch: Combat");
            numPlayers = 2;
            break;

        default:
            Debug.Log("Switch: Default");
            break;
        }
        // environment is evolvable, 1 player:
        teamsConfig = new TeamsConfig(numPlayers, this.challengeType, 1, 1);

        playingCurGen = 0;

        evaluationManager = new EvaluationManager();
        // Need to make sure all populations have their representatives set up before calling this:
        // Right now this is done through the teamsConfig Constructor
        evaluationManager.InitializeNewTraining(teamsConfig, challengeType); // should I just roll this into the Constructor?

        isTraining = true;
        //cameraEnabled = true;

        gameManager.uiManager.panelTraining.moduleViewUI.SetPendingGenomesFromData(this);
    }
예제 #11
0
    public void NewTrainingMode()
    {
        // Initialize
        int numPlayers = 2;

        // environment is evolvable, 1 player:
        teamsConfig = new TeamsConfig(numPlayers, 1, 1);

        playingCurGen = 0;

        evaluationManager = new EvaluationManager();
        // Need to make sure all populations have their representatives set up before calling this:
        // Right now this is done through the teamsConfig Constructor
        evaluationManager.InitializeNewTraining(teamsConfig); // should I just roll this into the Constructor?

        isTraining = true;
        //cameraEnabled = true;

        //gameManager.uiManager.panelTraining.moduleViewUI.SetPendingGenomesFromData(this);
    }
예제 #12
0
    public void InitializeNewTraining(TeamsConfig teamsConfig)
    {
        // Set up eval tickets:
        evaluationTicketList = new List <EvaluationTicket>();
        exhibitionTicketList = new List <EvaluationTicket>();
        //evaluationTicketQueue = new Queue<EvaluationTicket>();

        // Set up Exhibition Instance:
        GameObject exhibitionInstanceGO = new GameObject("ExhibitionInstance");

        exhibitionInstance = exhibitionInstanceGO.AddComponent <EvaluationInstance>();
        exhibitionInstance.transform.position = new Vector3(0f, 0f, 0f);
        exhibitionInstance.visible            = true;
        exhibitionInstance.isExhibition       = true;

        CreateEvaluationInstances();

        CreateDefaultEvaluationTickets(teamsConfig); // creates combinatorics for each Population's representatives
        InitializeExhibitionTickets(teamsConfig);

        Debug.Log("EvalManager Initialized!");
    }
예제 #13
0
    public void CreateDefaultEvaluationTickets(TeamsConfig teamsConfig)
    {
        allEvalsComplete = false;

        // TEMPORARY!!! BRUTE FORCE SOLUTION -- MAX 4 Players!!!:
        int numPlayers = teamsConfig.playersList.Count;

        if (numPlayers > 4)
        {
            Debug.Assert(true, "More than 4 Players not currently supported! NumPlayers: " + numPlayers.ToString());
        }
        else
        {
            // Environment First:
            for (int e = 0; e < teamsConfig.environmentPopulation.environmentGenomeList.Count; e++)
            {
                // 1+ Player:
                for (int i = 0; i < teamsConfig.playersList[0].representativeGenomeList.Count; i++)
                {
                    if (numPlayers > 1)
                    {
                        // 2+ Players:
                        for (int j = 0; j < teamsConfig.playersList[1].representativeGenomeList.Count; j++)
                        {
                            if (numPlayers > 2)
                            {
                                // 3+ Players:
                                for (int k = 0; k < teamsConfig.playersList[2].representativeGenomeList.Count; k++)
                                {
                                    if (numPlayers > 3)
                                    {
                                        // 4 Players
                                        for (int m = 0; m < teamsConfig.playersList[3].representativeGenomeList.Count; m++)
                                        {
                                            // 4 Players
                                            //string text = "envIndex: *" + e.ToString() + "*, agentIndices: [" + teamsConfig.playersList[0].representativeGenomeList[i].index.ToString() + "," + teamsConfig.playersList[1].representativeGenomeList[j].index.ToString() + "," + teamsConfig.playersList[2].representativeGenomeList[k].index.ToString() + "," + teamsConfig.playersList[3].representativeGenomeList[m].index.ToString() + "]";
                                            //Debug.Log(text);
                                            //int[] indices = new int[5];
                                            //indices[0] = e;
                                            //indices[1] = i; // teamsConfig.playersList[0].representativeGenomeList[i].index;
                                            //indices[2] = j; // teamsConfig.playersList[1].representativeGenomeList[j].index;
                                            //indices[3] = k; // teamsConfig.playersList[2].representativeGenomeList[k].index;
                                            //indices[4] = m; // teamsConfig.playersList[3].representativeGenomeList[m].index;
                                            List <AgentGenome> agentGenomesList = new List <AgentGenome>();
                                            agentGenomesList.Add(teamsConfig.playersList[0].representativeGenomeList[i]);
                                            agentGenomesList.Add(teamsConfig.playersList[1].representativeGenomeList[j]);
                                            agentGenomesList.Add(teamsConfig.playersList[2].representativeGenomeList[k]);
                                            agentGenomesList.Add(teamsConfig.playersList[3].representativeGenomeList[m]);
                                            EvaluationTicket evalTicket = new EvaluationTicket(teamsConfig.environmentPopulation.environmentGenomeList[e], agentGenomesList, 0, maxTimeStepsDefault);
                                            evaluationTicketList.Add(evalTicket);
                                        }
                                    }
                                    else   // 3 Players
                                           //string text = "envIndex: *" + e.ToString() + "*, agentIndices: [" + teamsConfig.playersList[0].representativeGenomeList[i].index.ToString() + "," + teamsConfig.playersList[1].representativeGenomeList[j].index.ToString() + "," + teamsConfig.playersList[2].representativeGenomeList[k].index.ToString() + "]";
                                           //Debug.Log(text);
                                           //int[] indices = new int[4];
                                           //indices[0] = e;
                                           //indices[1] = i; // teamsConfig.playersList[0].representativeGenomeList[i].index;
                                           //indices[2] = j; // teamsConfig.playersList[1].representativeGenomeList[j].index;
                                           //indices[3] = k; // teamsConfig.playersList[2].representativeGenomeList[k].index;
                                           //EvaluationTicket evalTicket = new EvaluationTicket(indices, 0, maxTimeStepsDefault);

                                    {
                                        List <AgentGenome> agentGenomesList = new List <AgentGenome>();
                                        agentGenomesList.Add(teamsConfig.playersList[0].representativeGenomeList[i]);
                                        agentGenomesList.Add(teamsConfig.playersList[1].representativeGenomeList[j]);
                                        agentGenomesList.Add(teamsConfig.playersList[2].representativeGenomeList[k]);
                                        EvaluationTicket evalTicket = new EvaluationTicket(teamsConfig.environmentPopulation.environmentGenomeList[e], agentGenomesList, 0, maxTimeStepsDefault);
                                        evaluationTicketList.Add(evalTicket);
                                    }
                                }
                            }
                            else    // 2 Players:
                            //string text = "envIndex: *" + e.ToString() + "*, agentIndices: [" + teamsConfig.playersList[0].representativeGenomeList[i].index.ToString() + "," + teamsConfig.playersList[1].representativeGenomeList[j].index.ToString() + "]";
                            //Debug.Log(text);
                            //int[] indices = new int[3];
                            //indices[0] = e;
                            //indices[1] = i; // teamsConfig.playersList[0].representativeGenomeList[i].index;
                            //indices[2] = j; // teamsConfig.playersList[1].representativeGenomeList[j].index;
                            //EvaluationTicket evalTicket = new EvaluationTicket(indices, 0, maxTimeStepsDefault);

                            {
                                List <AgentGenome> agentGenomesList = new List <AgentGenome>();
                                agentGenomesList.Add(teamsConfig.playersList[0].representativeGenomeList[i]);
                                agentGenomesList.Add(teamsConfig.playersList[1].representativeGenomeList[j]);
                                EvaluationTicket evalTicket = new EvaluationTicket(teamsConfig.environmentPopulation.environmentGenomeList[e], agentGenomesList, 0, maxTimeStepsDefault);
                                evaluationTicketList.Add(evalTicket);
                            }
                        }
                    }
                    else   // 1 Player:
                           //string text = "envIndex: *" + e.ToString() + "*, agentIndex: [" + teamsConfig.playersList[0].representativeGenomeList[i].index.ToString() + "]";
                           //Debug.Log(text);
                           //int[] indices = new int[2];
                           //indices[0] = e;
                           //indices[1] = i; // teamsConfig.playersList[0].representativeGenomeList[i].index;
                           //EvaluationTicket evalTicket = new EvaluationTicket(indices, 0, maxTimeStepsDefault);

                    {
                        List <AgentGenome> agentGenomesList = new List <AgentGenome>();
                        agentGenomesList.Add(teamsConfig.playersList[0].representativeGenomeList[i]);
                        //Debug.Log(e.ToString() + ", " + teamsConfig.environmentPopulation.environmentGenomeList[e].index.ToString());
                        EvaluationTicket evalTicket = new EvaluationTicket(teamsConfig.environmentPopulation.environmentGenomeList[e], agentGenomesList, 0, maxTimeStepsDefault);
                        evaluationTicketList.Add(evalTicket);
                    }
                }
            }
            if (numPlayers > 0)
            {
                // Player 1:
                for (int i = 0; i < teamsConfig.playersList[0].agentGenomeList.Count; i++)
                {
                    for (int e = 0; e < teamsConfig.environmentPopulation.representativeGenomeList.Count; e++)
                    {
                        if (numPlayers > 1)
                        {
                            for (int j = 0; j < teamsConfig.playersList[1].representativeGenomeList.Count; j++)
                            {
                                if (numPlayers > 2)
                                {
                                    for (int k = 0; k < teamsConfig.playersList[2].representativeGenomeList.Count; k++)
                                    {
                                        if (numPlayers > 3)
                                        {
                                            // 4 Players:
                                            for (int m = 0; m < teamsConfig.playersList[3].representativeGenomeList.Count; m++)
                                            {
                                                //string text = "envIndex: " + teamsConfig.environmentPopulation.representativeGenomeList[e].index.ToString() + ", agentIndex: [*" + i.ToString() + "*," + teamsConfig.playersList[1].representativeGenomeList[j].index.ToString() + "," + teamsConfig.playersList[2].representativeGenomeList[k].index.ToString() + "," + teamsConfig.playersList[3].representativeGenomeList[m].index.ToString() + "]";
                                                //Debug.Log(text);
                                                //int[] indices = new int[5];
                                                //indices[0] = e; // teamsConfig.environmentPopulation.representativeGenomeList[e].index;
                                                //indices[1] = i;
                                                //indices[2] = j; //teamsConfig.playersList[1].representativeGenomeList[j].index;
                                                //indices[3] = k; // teamsConfig.playersList[2].representativeGenomeList[k].index;
                                                //indices[4] = m; // teamsConfig.playersList[3].representativeGenomeList[m].index;
                                                //EvaluationTicket evalTicket = new EvaluationTicket(indices, 1, maxTimeStepsDefault);

                                                List <AgentGenome> agentGenomesList = new List <AgentGenome>();
                                                agentGenomesList.Add(teamsConfig.playersList[0].agentGenomeList[i]);
                                                agentGenomesList.Add(teamsConfig.playersList[1].representativeGenomeList[j]);
                                                agentGenomesList.Add(teamsConfig.playersList[2].representativeGenomeList[k]);
                                                agentGenomesList.Add(teamsConfig.playersList[3].representativeGenomeList[m]);
                                                EvaluationTicket evalTicket = new EvaluationTicket(teamsConfig.environmentPopulation.representativeGenomeList[e], agentGenomesList, 1, maxTimeStepsDefault);
                                                //EvaluationTicket evalTicket = new EvaluationTicket(teamsConfig.environmentPopulation.environmentGenomeList[j], agentGenomesList, 1, maxTimeStepsDefault);
                                                evaluationTicketList.Add(evalTicket);
                                            }
                                        }
                                        else
                                        {
                                            // 3 Players:
                                            //string text = "envIndex: " + teamsConfig.environmentPopulation.representativeGenomeList[e].index.ToString() + ", agentIndex: [*" + i.ToString() + "*," + teamsConfig.playersList[1].representativeGenomeList[j].index.ToString() + "," + teamsConfig.playersList[2].representativeGenomeList[k].index.ToString() + "]";
                                            //Debug.Log(text);
                                            //int[] indices = new int[4];
                                            //indices[0] = e; // teamsConfig.environmentPopulation.representativeGenomeList[e].index;
                                            //indices[1] = i;
                                            //indices[2] = j; // teamsConfig.playersList[1].representativeGenomeList[j].index;
                                            //indices[3] = k; // teamsConfig.playersList[2].representativeGenomeList[k].index;
                                            //EvaluationTicket evalTicket = new EvaluationTicket(indices, 1, maxTimeStepsDefault);

                                            List <AgentGenome> agentGenomesList = new List <AgentGenome>();
                                            agentGenomesList.Add(teamsConfig.playersList[0].agentGenomeList[i]);
                                            agentGenomesList.Add(teamsConfig.playersList[1].representativeGenomeList[j]);
                                            agentGenomesList.Add(teamsConfig.playersList[2].representativeGenomeList[k]);
                                            EvaluationTicket evalTicket = new EvaluationTicket(teamsConfig.environmentPopulation.representativeGenomeList[e], agentGenomesList, 1, maxTimeStepsDefault);
                                            evaluationTicketList.Add(evalTicket);
                                        }
                                    }
                                }
                                else
                                {
                                    // 2 Players:
                                    //string text = "envIndex: " + teamsConfig.environmentPopulation.representativeGenomeList[e].index.ToString() + ", agentIndex: [*" + i.ToString() + "*," + teamsConfig.playersList[1].representativeGenomeList[j].index.ToString() + "]";
                                    //Debug.Log(text);
                                    //int[] indices = new int[3];
                                    //indices[0] = e; // teamsConfig.environmentPopulation.representativeGenomeList[e].index;
                                    //indices[1] = i;
                                    //indices[2] = j; // teamsConfig.playersList[1].representativeGenomeList[j].index;
                                    //EvaluationTicket evalTicket = new EvaluationTicket(indices, 1, maxTimeStepsDefault);

                                    List <AgentGenome> agentGenomesList = new List <AgentGenome>();
                                    agentGenomesList.Add(teamsConfig.playersList[0].agentGenomeList[i]);
                                    agentGenomesList.Add(teamsConfig.playersList[1].representativeGenomeList[j]);
                                    //EvaluationTicket evalTicket = new EvaluationTicket(teamsConfig.environmentPopulation.representativeGenomeList[e], agentGenomesList, 1, maxTimeStepsDefault);
                                    EvaluationTicket evalTicket = new EvaluationTicket(teamsConfig.environmentPopulation.environmentGenomeList[j], agentGenomesList, 1, maxTimeStepsDefault);
                                    evaluationTicketList.Add(evalTicket);
                                }
                            }
                        }
                        else
                        {
                            // 1 Player:
                            //string text = "envIndex: " + teamsConfig.environmentPopulation.representativeGenomeList[e].index.ToString() + ", agentIndex: [*" + i.ToString() + "*]";
                            //Debug.Log(text);
                            //int[] indices = new int[2];
                            //indices[0] = e; // teamsConfig.environmentPopulation.representativeGenomeList[e].index;
                            //indices[1] = i;
                            //EvaluationTicket evalTicket = new EvaluationTicket(indices, 1, maxTimeStepsDefault);

                            List <AgentGenome> agentGenomesList = new List <AgentGenome>();
                            agentGenomesList.Add(teamsConfig.playersList[0].agentGenomeList[i]);
                            EvaluationTicket evalTicket = new EvaluationTicket(teamsConfig.environmentPopulation.representativeGenomeList[e], agentGenomesList, 1, maxTimeStepsDefault);
                            evaluationTicketList.Add(evalTicket);
                        }
                    }
                }

                if (numPlayers > 1)
                {
                    // more than 1 player -- do player 2:
                    // 2 Players:
                    for (int j = 0; j < teamsConfig.playersList[1].agentGenomeList.Count; j++)   // Player 2 focus
                    {
                        for (int e = 0; e < teamsConfig.environmentPopulation.representativeGenomeList.Count; e++)
                        {
                            for (int i = 0; i < teamsConfig.playersList[0].representativeGenomeList.Count; i++)
                            {
                                if (numPlayers > 2)
                                {
                                    for (int k = 0; k < teamsConfig.playersList[2].representativeGenomeList.Count; k++)
                                    {
                                        if (numPlayers > 3)
                                        {
                                            // 4 Players:
                                            for (int m = 0; m < teamsConfig.playersList[3].representativeGenomeList.Count; m++)
                                            {
                                                //string text = "envIndex: " + teamsConfig.environmentPopulation.representativeGenomeList[e].index.ToString() + ", agentIndex: [" + teamsConfig.playersList[0].representativeGenomeList[i].index.ToString() + ",*" + j.ToString() + "*," + teamsConfig.playersList[2].representativeGenomeList[k].index.ToString() + "," + teamsConfig.playersList[3].representativeGenomeList[m].index.ToString() + "]";
                                                //Debug.Log(text);
                                                //int[] indices = new int[5];
                                                //indices[0] = e; // teamsConfig.environmentPopulation.representativeGenomeList[e].index;
                                                //indices[1] = i; // teamsConfig.playersList[0].representativeGenomeList[i].index;
                                                //indices[2] = j;
                                                //indices[3] = k; // teamsConfig.playersList[2].representativeGenomeList[k].index;
                                                //indices[4] = m; // teamsConfig.playersList[3].representativeGenomeList[m].index;
                                                //EvaluationTicket evalTicket = new EvaluationTicket(indices, 2, maxTimeStepsDefault);

                                                List <AgentGenome> agentGenomesList = new List <AgentGenome>();
                                                agentGenomesList.Add(teamsConfig.playersList[0].representativeGenomeList[i]);
                                                agentGenomesList.Add(teamsConfig.playersList[1].agentGenomeList[j]);
                                                agentGenomesList.Add(teamsConfig.playersList[2].representativeGenomeList[k]);
                                                agentGenomesList.Add(teamsConfig.playersList[3].representativeGenomeList[m]);
                                                EvaluationTicket evalTicket = new EvaluationTicket(teamsConfig.environmentPopulation.representativeGenomeList[e], agentGenomesList, 2, maxTimeStepsDefault);
                                                evaluationTicketList.Add(evalTicket);
                                            }
                                        }
                                        else
                                        {
                                            // 3 Players:
                                            //string text = "envIndex: " + teamsConfig.environmentPopulation.representativeGenomeList[e].index.ToString() + ", agentIndex: [" + teamsConfig.playersList[0].representativeGenomeList[i].index.ToString() + ",*" + j.ToString() + "*," + teamsConfig.playersList[2].representativeGenomeList[k].index.ToString() + "]";
                                            //Debug.Log(text);
                                            //int[] indices = new int[4];
                                            //indices[0] = e; // teamsConfig.environmentPopulation.representativeGenomeList[e].index;
                                            //indices[1] = i; // teamsConfig.playersList[0].representativeGenomeList[i].index;
                                            //indices[2] = j;
                                            //indices[3] = k; // teamsConfig.playersList[2].representativeGenomeList[k].index;
                                            //EvaluationTicket evalTicket = new EvaluationTicket(indices, 2, maxTimeStepsDefault);

                                            List <AgentGenome> agentGenomesList = new List <AgentGenome>();
                                            agentGenomesList.Add(teamsConfig.playersList[0].representativeGenomeList[i]);
                                            agentGenomesList.Add(teamsConfig.playersList[1].agentGenomeList[j]);
                                            agentGenomesList.Add(teamsConfig.playersList[2].representativeGenomeList[k]);
                                            EvaluationTicket evalTicket = new EvaluationTicket(teamsConfig.environmentPopulation.representativeGenomeList[e], agentGenomesList, 2, maxTimeStepsDefault);
                                            evaluationTicketList.Add(evalTicket);
                                        }
                                    }
                                }
                                else
                                {
                                    // 2 Players:
                                    //string text = "envIndex: " + teamsConfig.environmentPopulation.representativeGenomeList[e].index.ToString() + ", agentIndex: [" + teamsConfig.playersList[0].representativeGenomeList[i].index.ToString() + ",*" + j.ToString() + "*]";
                                    //Debug.Log(text);
                                    //int[] indices = new int[3];
                                    //indices[0] = e; // teamsConfig.environmentPopulation.representativeGenomeList[e].index;
                                    //indices[1] = i; // teamsConfig.playersList[0].representativeGenomeList[i].index;
                                    //indices[2] = j;
                                    //EvaluationTicket evalTicket = new EvaluationTicket(indices, 2, maxTimeStepsDefault);

                                    List <AgentGenome> agentGenomesList = new List <AgentGenome>();
                                    agentGenomesList.Add(teamsConfig.playersList[0].representativeGenomeList[i]);
                                    agentGenomesList.Add(teamsConfig.playersList[1].agentGenomeList[j]);
                                    //EvaluationTicket evalTicket = new EvaluationTicket(teamsConfig.environmentPopulation.representativeGenomeList[e], agentGenomesList, 2, maxTimeStepsDefault);
                                    EvaluationTicket evalTicket = new EvaluationTicket(teamsConfig.environmentPopulation.environmentGenomeList[i], agentGenomesList, 2, maxTimeStepsDefault);
                                    evaluationTicketList.Add(evalTicket);
                                }
                            }
                        }
                    }
                    if (numPlayers > 2)
                    {
                        // more than 2 players: do player 3:
                        // 3 Players:
                        for (int k = 0; k < teamsConfig.playersList[2].agentGenomeList.Count; k++)   // Player 2 focus
                        {
                            for (int e = 0; e < teamsConfig.environmentPopulation.representativeGenomeList.Count; e++)
                            {
                                for (int i = 0; i < teamsConfig.playersList[0].representativeGenomeList.Count; i++)
                                {
                                    for (int j = 0; j < teamsConfig.playersList[1].representativeGenomeList.Count; j++)
                                    {
                                        if (numPlayers > 3)
                                        {
                                            // 4 Players:
                                            for (int m = 0; m < teamsConfig.playersList[3].representativeGenomeList.Count; m++)
                                            {
                                                //string text = "envIndex: " + teamsConfig.environmentPopulation.representativeGenomeList[e].index.ToString() + ", agentIndex: [" + teamsConfig.playersList[0].representativeGenomeList[i].index.ToString() + "," + teamsConfig.playersList[1].representativeGenomeList[j].index.ToString() + ",*" + k.ToString() + "*," + teamsConfig.playersList[3].representativeGenomeList[m].index.ToString() + "]";
                                                //Debug.Log(text);
                                                //int[] indices = new int[5];
                                                //indices[0] = e; // teamsConfig.environmentPopulation.representativeGenomeList[e].index;
                                                //indices[1] = i; // teamsConfig.playersList[0].representativeGenomeList[i].index;
                                                //indices[2] = j; // teamsConfig.playersList[1].representativeGenomeList[j].index;
                                                //indices[3] = k;
                                                //indices[4] = m; // teamsConfig.playersList[3].representativeGenomeList[m].index;
                                                //EvaluationTicket evalTicket = new EvaluationTicket(indices, 3, maxTimeStepsDefault);

                                                List <AgentGenome> agentGenomesList = new List <AgentGenome>();
                                                agentGenomesList.Add(teamsConfig.playersList[0].representativeGenomeList[i]);
                                                agentGenomesList.Add(teamsConfig.playersList[1].representativeGenomeList[j]);
                                                agentGenomesList.Add(teamsConfig.playersList[2].agentGenomeList[k]);
                                                agentGenomesList.Add(teamsConfig.playersList[3].representativeGenomeList[m]);
                                                EvaluationTicket evalTicket = new EvaluationTicket(teamsConfig.environmentPopulation.representativeGenomeList[e], agentGenomesList, 3, maxTimeStepsDefault);
                                                evaluationTicketList.Add(evalTicket);
                                            }
                                        }
                                        else
                                        {
                                            // 3 Players:
                                            //string text = "envIndex: " + teamsConfig.environmentPopulation.representativeGenomeList[e].index.ToString() + ", agentIndex: [" + teamsConfig.playersList[0].representativeGenomeList[i].index.ToString() + "," + teamsConfig.playersList[1].representativeGenomeList[j].index.ToString() + ",*" + k.ToString() + "*]";
                                            //Debug.Log(text);
                                            //int[] indices = new int[4];
                                            //indices[0] = e; // teamsConfig.environmentPopulation.representativeGenomeList[e].index;
                                            //indices[1] = i; // teamsConfig.playersList[0].representativeGenomeList[i].index;
                                            //indices[2] = j; // teamsConfig.playersList[1].representativeGenomeList[j].index;
                                            //indices[3] = k;
                                            //EvaluationTicket evalTicket = new EvaluationTicket(indices, 3, maxTimeStepsDefault);

                                            List <AgentGenome> agentGenomesList = new List <AgentGenome>();
                                            agentGenomesList.Add(teamsConfig.playersList[0].representativeGenomeList[i]);
                                            agentGenomesList.Add(teamsConfig.playersList[1].representativeGenomeList[j]);
                                            agentGenomesList.Add(teamsConfig.playersList[2].agentGenomeList[k]);
                                            EvaluationTicket evalTicket = new EvaluationTicket(teamsConfig.environmentPopulation.representativeGenomeList[e], agentGenomesList, 3, maxTimeStepsDefault);
                                            evaluationTicketList.Add(evalTicket);
                                        }
                                    }
                                }
                            }
                        }
                        if (numPlayers > 3)
                        {
                            // 4 Players:
                            for (int m = 0; m < teamsConfig.playersList[3].agentGenomeList.Count; m++)   // Player 2 focus
                            {
                                for (int e = 0; e < teamsConfig.environmentPopulation.representativeGenomeList.Count; e++)
                                {
                                    for (int i = 0; i < teamsConfig.playersList[0].representativeGenomeList.Count; i++)
                                    {
                                        for (int j = 0; j < teamsConfig.playersList[1].representativeGenomeList.Count; j++)
                                        {
                                            for (int k = 0; k < teamsConfig.playersList[2].representativeGenomeList.Count; k++)
                                            {
                                                // 4 Players:
                                                //string text = "envIndex: " + teamsConfig.environmentPopulation.representativeGenomeList[e].index.ToString() + ", agentIndex: [" + teamsConfig.playersList[0].representativeGenomeList[i].index.ToString() + "," + teamsConfig.playersList[1].representativeGenomeList[j].index.ToString() + "," + teamsConfig.playersList[1].representativeGenomeList[k].index.ToString() + ",*" + m.ToString() + "*]";
                                                //Debug.Log(text);
                                                //int[] indices = new int[5];
                                                //indices[0] = e; // teamsConfig.environmentPopulation.representativeGenomeList[e].index;
                                                //indices[1] = i; // teamsConfig.playersList[0].representativeGenomeList[i].index;
                                                //indices[2] = j; // teamsConfig.playersList[1].representativeGenomeList[j].index;
                                                //indices[3] = k; // teamsConfig.playersList[2].representativeGenomeList[k].index;
                                                //indices[4] = m;
                                                //EvaluationTicket evalTicket = new EvaluationTicket(indices, 4, maxTimeStepsDefault);

                                                List <AgentGenome> agentGenomesList = new List <AgentGenome>();
                                                agentGenomesList.Add(teamsConfig.playersList[0].representativeGenomeList[i]);
                                                agentGenomesList.Add(teamsConfig.playersList[1].representativeGenomeList[j]);
                                                agentGenomesList.Add(teamsConfig.playersList[2].representativeGenomeList[k]);
                                                agentGenomesList.Add(teamsConfig.playersList[3].agentGenomeList[m]);
                                                EvaluationTicket evalTicket = new EvaluationTicket(teamsConfig.environmentPopulation.representativeGenomeList[e], agentGenomesList, 4, maxTimeStepsDefault);
                                                evaluationTicketList.Add(evalTicket);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        /*string evalText = "";
         * for(int i = 0; i < evaluationTicketList.Count; i++) {
         *  evalText += "(";
         *  for (int j = 0; j < evaluationTicketList[i].genomeIndices.Length; j++) {
         *      evalText += evaluationTicketList[i].genomeIndices[j].ToString() + ",";
         *  }
         *  evalText += ")\n";
         * }
         * Debug.Log(evalText);*/
    }
예제 #14
0
    public void Init1(TeamsConfig teamsConfig)
    {
        challengeType = teamsConfig.challengeType;

        // Temp hardcoded!!!!!
        competitionType   = CompetitionType.Independent;
        competitionFormat = CompetitionFormat.HighScore;
        numOpponents      = 1;

        tournamentRoundList = new List <TournamentRound>();

        TournamentRound round1 = new TournamentRound(0);

        // MOCKUP:
        int[] competitorIDs = new int[1];
        competitorIDs[0] = -1;
        // Match1
        string savename = "env1";
        string path     = Application.dataPath + "/IndividualSaves/Environments/" + savename + ".json";
        // Read the json from the file into a string
        string             dataAsJson        = File.ReadAllText(path);
        EnvironmentGenome  loadedGenome1     = JsonUtility.FromJson <EnvironmentGenome>(dataAsJson);
        List <AgentGenome> agentGenomesList1 = new List <AgentGenome>();

        agentGenomesList1.Add(teamsConfig.playersList[0].agentGenomeList[0]);
        EvaluationTicket ticket1 = new EvaluationTicket(loadedGenome1, agentGenomesList1, 1, 1000);

        TournamentMatchup matchup1 = new TournamentMatchup(0, ticket1, 0, competitorIDs);

        round1.matchupList.Add(matchup1);

        // Match2
        savename = "env2";
        path     = Application.dataPath + "/IndividualSaves/Environments/" + savename + ".json";
        // Read the json from the file into a string
        dataAsJson = File.ReadAllText(path);
        EnvironmentGenome  loadedGenome2     = JsonUtility.FromJson <EnvironmentGenome>(dataAsJson);
        List <AgentGenome> agentGenomesList2 = new List <AgentGenome>();

        agentGenomesList2.Add(teamsConfig.playersList[0].agentGenomeList[0]);
        EvaluationTicket  ticket2  = new EvaluationTicket(loadedGenome2, agentGenomesList2, 1, 1000);
        TournamentMatchup matchup2 = new TournamentMatchup(1, ticket2, 1, competitorIDs);

        round1.matchupList.Add(matchup2);

        // Matchup3:
        savename = "env3";
        path     = Application.dataPath + "/IndividualSaves/Environments/" + savename + ".json";
        // Read the json from the file into a string
        dataAsJson = File.ReadAllText(path);
        EnvironmentGenome  loadedGenome3     = JsonUtility.FromJson <EnvironmentGenome>(dataAsJson);
        List <AgentGenome> agentGenomesList3 = new List <AgentGenome>();

        agentGenomesList3.Add(teamsConfig.playersList[0].agentGenomeList[0]);
        EvaluationTicket  ticket3  = new EvaluationTicket(loadedGenome3, agentGenomesList3, 1, 1000);
        TournamentMatchup matchup3 = new TournamentMatchup(2, ticket3, 2, competitorIDs);

        round1.matchupList.Add(matchup3);


        tournamentRoundList.Add(round1);
    }
예제 #15
0
    public void CreateOneTrueParticleSystem(TeamsConfig teamsConfig)
    {
        GameObject particleGO = Instantiate(Resources.Load("Prefabs/ParticleSystems/Trajectory")) as GameObject;

        particleGO.name             = "theOneTrueCurve";
        particleGO.transform.parent = this.transform;
        singleTrajectoryCurvesPS    = particleGO.GetComponent <ParticleSystem>();


        /*var children = new List<GameObject>();
         * foreach (Transform child in gameObject.transform) children.Add(child.gameObject);
         * children.ForEach(child => Destroy(child));
         *
         * if (particleDictionary == null) {
         *  particleDictionary = new Dictionary<string, ParticleSystem>();
         * }
         * else {
         *  particleDictionary.Clear();
         * }
         *
         * int numPlayers = teamsConfig.playersList.Count;
         *
         * for(int i = 0; i < numPlayers; i++) {
         *  // For each Player:
         *
         *  //for each combination of opponent representatives:
         *  //List<int[]> indicesList = new List<int[]>();
         *  // use these as key?
         *
         *
         *  if(numPlayers > 1) {
         *      // 2 or more players:
         *      for(int j = 0; j < teamsConfig.environmentPopulation.representativeGenomeList.Count; j++) {
         *          // env reps
         *          // will only work with 2 players!!!  v v v v v v v  !!!
         *          for(int k = 0; k < teamsConfig.playersList[1 - i].representativeGenomeList.Count; k++) {
         *              int[] indices = new int[numPlayers + 2]; // focusPop, + env, + players
         *              indices[0] = i + 1;  // focusPop index, env = 0, player 1 = 1
         *              indices[1] = j;  // environment
         *              indices[2] = 0;  // player1, irrelevant
         *              indices[3] = 0;  // player2, irrelevant
         *              indices[3 - i] = k; // overwrite proper index
         *
         *              string txt = "";
         *              for (int x = 0; x < indices.Length; x++) {
         *                  txt += indices[x].ToString();
         *              }
         *              GameObject particleGO = Instantiate(Resources.Load("Prefabs/ParticleSystems/Trajectory")) as GameObject;
         *              particleGO.name = txt;
         *              particleGO.transform.parent = this.transform;
         *              ParticleSystem particle = particleGO.GetComponent<ParticleSystem>();
         *              particleDictionary.Add(txt, particle);
         *
         *              //Debug.Log(particleDictionary.TryGetValue(txt, out particle));
         *          }
         *      }
         *  }
         *  else {
         *      // 1 Player!
         *      for(int j = 0; j < teamsConfig.environmentPopulation.representativeGenomeList.Count; j++) {
         *          int[] indices = new int[numPlayers + 2]; // focusPop, + env, + players
         *          indices[0] = i+1;  // focusPop index, env = 0, player 1 = 1
         *          indices[1] = j;  // environment
         *          indices[2] = 0;  // player1, irrelevant
         *
         *          string txt = "";
         *          for(int x = 0; x < indices.Length; x++) {
         *              txt += indices[x].ToString();
         *          }
         *          GameObject particleGO = Instantiate(Resources.Load("Prefabs/ParticleSystems/Trajectory")) as GameObject;
         *          particleGO.name = txt;
         *          particleGO.transform.parent = this.transform;
         *          ParticleSystem particle = particleGO.GetComponent<ParticleSystem>();
         *          particleDictionary.Add(txt, particle);
         *      }
         *  }
         * }*/
    }
예제 #16
0
    public TournamentInfo(TeamsConfig teamsConfig)
    {
        Debug.Log("TournamentInfo()");

        //Init1(teamsConfig);
    }
예제 #17
0
 public void ResetExhibitionInstance(TeamsConfig teamsConfig)
 {
     exhibitionInstance.SetUpInstance(exhibitionTicketList[exhibitionTicketCurrentIndex], teamsConfig);
 }
예제 #18
0
    public void SetUpInstance(EvaluationTicket evalTicket, TeamsConfig teamsConfig, ExhibitionParticleCurves exhibitionParticleCurves)
    {
        this.teamsConfig   = teamsConfig;
        this.challengeType = teamsConfig.challengeType;
        this.maxTimeSteps  = evalTicket.maxTimeSteps;

        /*string debugname = "";
         * for( int i = 0; i < evalTicket.genomeIndices.Length; i++) {
         *  debugname += evalTicket.genomeIndices[i].ToString() + ",";
         * }
         * debugname += evalTicket.focusPopIndex.ToString();
         * gameObject.name = debugname;*/

        // create particle key:

        /*int[] indices = new int[teamsConfig.playersList.Count + 2];
         * indices[0] = evalTicket.focusPopIndex;
         * for(int i = 0; i < evalTicket.genomeIndices.Length; i++) {
         *  indices[i + 1] = evalTicket.genomeIndices[i];
         * }
         * indices[indices[0] + 1] = 0; // focusPop is 0
         */
        /*int[] indices = new int[teamsConfig.playersList.Count + 2];
         * indices[0] = evalTicket.focusPopIndex;
         * for (int i = 0; i < evalTicket.agentGenomesList.Count + 1; i++) {
         *  if (i == 0) {
         *      indices[i + 1] = evalTicket.environmentGenome.index;
         *  }
         *  else {
         *      indices[i + 1] = evalTicket.agentGenomesList[i - 1].index;
         *  }
         *  //indices[i + 1] = ticket.genomeIndices[i];
         * }
         *
         * string txt = "";
         * for(int i = 0; i < indices.Length; i++) {
         *  txt += indices[i].ToString();
         * }*/
        //Debug.Log(txt);

        /*if (exhibitionParticleRef.particleDictionary != null) {
         *  if (exhibitionParticleRef.particleDictionary.TryGetValue(txt, out particleCurves)) {
         *      // particleCurves
         *      //Debug.Log("FOUND IT! set up " + txt);
         *
         *      emit = true;
         *      if (isExhibition)
         *          emit = false;
         *  }
         *  else {
         *      //if (!isExhibition)
         *      //Debug.Log("Eval Instance Setup FAIL " + txt);
         *      emit = false;
         *  }
         * }*/
        if (evalTicket.environmentGenome.index == 0)  // if this instance is testing an agent vs. the Top Environment, record its curves:

        {
            if (isExhibition)
            {
                //emit = false;
                particleCurves = exhibitionParticleCurves.singleTrajectoryCurvesPS;
                emit           = true;
            }
            else
            {
                particleCurves = exhibitionParticleCurves.singleTrajectoryCurvesPS;
                emit           = true;
            }
        }
        else
        {
            emit = false;
        }


        currentEvalTicket = evalTicket;

        BruteForceInit();

        currentEvalTicket.status = EvaluationTicket.EvaluationStatus.InProgress;


        //emitterParamsDefault.startSize = 0.12f;
        //emitterParamsDefault.startColor = new Color(1f, 1f, 1f, 0.1f);

        emitterParamsWin.startSize  = 1.2f;
        emitterParamsWin.startColor = new Color(0.1f, 1f, 0.1f, 1f);

        emitterParamsLose.startSize  = 1.2f;
        emitterParamsLose.startColor = new Color(1f, 0.1f, 0.1f, 1f);

        emitterParamsDraw.startSize  = 1.0f;
        emitterParamsDraw.startColor = new Color(0.4f, 0.4f, 0.4f, 1f);
    }
예제 #19
0
    public void TickEvaluations(TeamsConfig teamsConfig)
    {
        // Check training status:

        // Auto Parallel Mode!!!!!

        // loop through evalInstances -- if pending, start evaluating with next free evalPair
        // if inProgress, Tick()
        int maxEvalConstructionsPerFrame  = 1;
        int numEvalConstructionsThisFrame = 0;

        for (int i = 0; i < evaluationInstancesList.Count; i++)
        {
            if (evaluationInstancesList[i].currentEvalTicket == null)
            {
                if (numEvalConstructionsThisFrame >= maxEvalConstructionsPerFrame)
                {
                    // ignore
                }
                else
                {
                    // available for use
                    // Find next available evalPair:
                    int currentEvalPairIndex = GetNextPendingEvalPairIndex();
                    if (currentEvalPairIndex == -1)
                    {
                        // no evals pending
                    }
                    else
                    {
                        //print("evalPair: " + currentEvalPairIndex.ToString() + " (" + evaluationPairsList[currentEvalPairIndex].status.ToString() + "), [" + evaluationPairsList[currentEvalPairIndex].evalPairIndices[0].ToString() + "," + evaluationPairsList[currentEvalPairIndex].evalPairIndices[1].ToString() + "]");
                        evaluationInstancesList[i].SetUpInstance(evaluationTicketList[currentEvalPairIndex], teamsConfig);
                        numEvalConstructionsThisFrame++;
                    }
                }
            }
            else
            {
                if (evaluationInstancesList[i].currentEvalTicket.status == EvaluationTicket.EvaluationStatus.InProgress)
                {
                    // Tick
                    evaluationInstancesList[i].Tick();
                }
                if (evaluationInstancesList[i].currentEvalTicket.status == EvaluationTicket.EvaluationStatus.PendingComplete)
                {
                    // CleanUp and Process
                    // Instance finished but not fully processed

                    // STORE FITNESS
                    if (evaluationInstancesList[i].currentEvalTicket.focusPopIndex == 0)    // Environment
                    //teamsConfig.environmentPopulation.fitnessManager.rawFitnessScores[evaluationInstancesList[i].currentEvalTicket.genomeIndices[0]] += evaluationInstancesList[i].score;
                    //Debug.Log("evalInstance " + i.ToString() + ", Enviro rawScore=" + evaluationInstancesList[i].fitnessComponentEvaluationGroup.fitCompList[0].rawScore.ToString());
                    {
                    }
                    // Players:
                    else if (evaluationInstancesList[i].currentEvalTicket.focusPopIndex == 1)
                    {
                        //teamsConfig.playersList[0].fitnessManager.rawFitnessScores[evaluationInstancesList[i].currentEvalTicket.genomeIndices[1]] += evaluationInstancesList[i].score;
                        //Debug.Log("evalInstance " + i.ToString() + ", Player 1 rawScore=" + evaluationInstancesList[i].fitnessComponentEvaluationGroup.fitCompList[0].rawScore.ToString());
                    }
                    else if (evaluationInstancesList[i].currentEvalTicket.focusPopIndex == 2)
                    {
                        //teamsConfig.playersList[1].fitnessManager.rawFitnessScores[evaluationInstancesList[i].currentEvalTicket.genomeIndices[2]] += evaluationInstancesList[i].score;
                    }
                    else if (evaluationInstancesList[i].currentEvalTicket.focusPopIndex == 3)
                    {
                        //teamsConfig.playersList[2].fitnessManager.rawFitnessScores[evaluationInstancesList[i].currentEvalTicket.genomeIndices[3]] += evaluationInstancesList[i].score;
                    }
                    else   // 4
                           //teamsConfig.playersList[3].fitnessManager.rawFitnessScores[evaluationInstancesList[i].currentEvalTicket.genomeIndices[4]] += evaluationInstancesList[i].score;
                    {
                    }
                    evaluationInstancesList[i].DeleteAllGameObjects();
                    evaluationInstancesList[i].currentEvalTicket.status = EvaluationTicket.EvaluationStatus.Complete;
                    evaluationInstancesList[i].currentEvalTicket        = null;
                }
            }
        }
        // check for Gen complete:
        bool genComplete = true;

        for (int i = 0; i < evaluationTicketList.Count; i++)
        {
            if (evaluationTicketList[i].status == EvaluationTicket.EvaluationStatus.Complete)
            {
            }
            else
            {
                genComplete = false;
            }
        }
        if (genComplete)
        {
            // All evals complete!
            //TerrainConstructorGPU.ClearCustomHeightRT();
            //Debug.Log("EvaluationManager allEvalsComplete!!!");
            allEvalsComplete = true;
            // NEXTGEN READY
        }
    }