Пример #1
0
 void AddExperimentToWorld(Experiment e)
 {
     e.id = experiments.Count;
     experiments.Add(e);
     e.transform.parent   = expHolder;
     e.transform.position = NewBoundedRandomLoc();
     state = SocState.Regrouping;
 }
Пример #2
0
 public bool TriggerJoin()
 {
     if (state == SocState.Sleeping && mouseSelectedExps.Count > 1)
     {
         state = SocState.Joining;
         return(true);
     }
     return(false);
 }
Пример #3
0
    // Use this for initialization
    void Awake()
    {
        if (geneMap.Length == 0)
        {
            geneMap = new string[2] {
                "shape", "color"
            }
        }
        ;
        experiments               = new List <Experiment> ();
        mouseSelectedExps         = new List <Experiment> ();
        gConditions               = GetComponents <GroupCondition> ();
        aConditions               = GetComponents <AttackCondition> ();
        GeneValues.NUM_BASE_TYPES = NUM_BASE_TYPES;
        expHolder     = ((GameObject)GameObject.Find("ExperimentHolder")).transform;
        factoryHolder = ((GameObject)GameObject.Find("FactoryHolder")).transform;
        goalHolder    = ((GameObject)GameObject.Find("GoalHolder")).transform;
        tempExp       = ((GameObject)Resources.Load("temp_experiment")).transform;
        foreach (GroupCondition gc in GetComponents <GroupCondition>())
        {
            gc.Setup();
        }
    }

    void Start()
    {
        // Rogue node setup
        GameObject rogueNode = (GameObject)Resources.Load("nodes/roguenode");

        rogueSpots = new Vector3[rogueNode.transform.childCount];
        for (int i = 0; i < rogueNode.transform.childCount; i++)
        {
            rogueSpots [i] = rogueNode.transform.GetChild(i).position;
        }
        groupMarker = Resources.Load("nodes/groupmarker") as GameObject;

        // UI Setup
        UI        = GameObject.Find("LabCanvas").GetComponent <UIFramework> ();
        SocStatus = GameObject.Find("SocietyStatus");
        SocStatus.SetActive(false);
        societyCenter = new Vector3(UI.societyBounds.x + UI.societyBounds.z / 2, UI.societyBounds.y + UI.societyBounds.w / 2, 0);

        // GameObject Setup
        for (int i = 0; i < geneMapDefaultExps.Length; i++)
        {
            Experiment e = CreateExperiment(expHolder, i, NewBoundedRandomLoc());
            e.dna.Setup(geneMapDefaultExps[i].mapList);
        }
        SpawnGoalExperiments();
        AddFactoryExperiment();
        AddNucleobases();

        // Interaction Setup
        for (int i = 0; i < expHolder.childCount; i++)
        {
            Experiment e = expHolder.GetChild(i).GetComponent <Experiment> ();
            // Check if this is a valid experiment
            if (e.gameObject.activeInHierarchy && !e.gameObject.name.Equals("ToBeDestroyed"))
            {
                experiments.Add(e);
            }
        }
        state = SocState.Regrouping;
    }

    Experiment CreateExperiment(Transform holder, int id, Vector3 pos)
    {
        Experiment exp = ((GameObject)GameObject.Instantiate(Resources.Load("temp_experiment"), holder)).GetComponent <Experiment>();

        exp.BaseSetup();
        exp.id = id;
        exp.transform.position = pos;
        return(exp);
    }

    // Update is called once per frame
    void Update()
    {
        //print (numInteracting);
        switch (state)
        {
        case SocState.CheckVictory:
            ActivateStatusUIWith(false, "");
            CheckForVictory();
            break;

        case SocState.Waiting:
            if (numInteracting == 0)
            {
                state = nextState;
            }
            break;

        case SocState.Regrouping:
            BucketExpsIntoGroups();
            foreach (Experiment e in experiments)
            {
                e.SetState(Experiment.ExpState.Moving);
            }
            ActivateStatusUIWith(true, "Grouping");
            state     = SocState.Waiting;
            nextState = SocState.Attacking;
            DrawGroupMarkers();
            break;

        case SocState.Attacking:
            ActivateStatusUIWith(true, "Attacking");
            UpdateExpAttacks();
            state     = SocState.Waiting;
            nextState = SocState.CheckVictory;
            break;

        case SocState.Joining:
            EraseGroupMarkers();
            JoinSelectedExps();
            state     = SocState.Waiting;
            nextState = SocState.Regrouping;
            break;
        }
    }

    void ActivateStatusUIWith(bool active, string text)
    {
        SocStatus.SetActive(active);
        SocStatus.GetComponentInChildren <Text> ().text = text;
    }

    void InsertExpIntoList(Experiment e)
    {
        //int index;
        //if ((index = experiments.BinarySearch (e, (Experiment x, Experiment y) => x.transform.position.x.CompareTo (y.transform.position.x))) < 0)
        //	index = 0;
        //experiments.Insert (index, e);
        //print ("Added: " + e.name);
    }
Пример #4
0
    void CheckForVictory()
    {
        bool victory  = true;
        bool allMatch = true;

        bool[] checkedOff    = new bool[experiments.Count];
        int    numCheckedOff = 0;

        int[,] values = new int[experiments.Count, geneMap.Length];
        int counter = 0;

        for (int i = 0; i < experiments.Count; i++)
        {
            foreach (int j in experiments[i].dna.GetGeneValues())
            {
                values [i, counter++] = j;
            }
            counter = 0;
        }
        if (goalGeneMapping.Length == 0 && GetNumOfExps() > 0)
        {
            victory = false;
        }
        else
        {
            for (int i = 0; i < goalGeneMapping.Length; i++)
            {
                for (int j = 0; j < experiments.Count; j++)
                {
                    if (checkedOff [j])
                    {
                        continue;
                    }
                    allMatch = true;
                    for (int k = 0; k < geneMap.Length; k++)
                    {
                        if (values [j, k] != goalGeneMapping [i].mapList [k])
                        {
                            allMatch = false;
                            break;
                        }
                    }
                    if (allMatch)
                    {
                        checkedOff [j] = true;
                        numCheckedOff++;
                        break;
                    }
                }
                if (numCheckedOff == i)
                {
                    victory = false;
                    break;
                }
            }
        }

        if (victory)
        {
            state = SocState.Finished;
            UI.ReportFinished();
        }
        else
        {
            state = SocState.Sleeping;
        }
        //print ("Victorious: " + victory);
    }