示例#1
0
 private void GenerateAnts()
 {
     for (short i = 0; i < ConfigurationManager.Instance.coloniesPerWorld; i++)
     {
         if (colonies[i] == topColony)
         {
             continue;
         }
         colonies[i] = new Agents.Colony(i, topColony);
     }
 }
示例#2
0
        /// <summary>
        /// Awake is called before any start method is called.
        /// </summary>
        void Awake()
        {
            // Generate new random number generator
            RNG = new System.Random(ConfigurationManager.Instance.Seed);

            // Generate new simplex noise generator
            SimplexNoise = new SimplexNoise(ConfigurationManager.Instance.Seed);

            // Initialize a new 3D array of blocks with size of the number of chunks times the size of each chunk
            Blocks = new AbstractBlock[
                ConfigurationManager.Instance.World_Diameter * ConfigurationManager.Instance.Chunk_Diameter,
                ConfigurationManager.Instance.World_Height *ConfigurationManager.Instance.Chunk_Diameter,
                ConfigurationManager.Instance.World_Diameter *ConfigurationManager.Instance.Chunk_Diameter];

            // Initialize a new 3D array of chunks with size of the number of chunks
            Chunks = new Chunk[
                ConfigurationManager.Instance.World_Diameter,
                ConfigurationManager.Instance.World_Height,
                ConfigurationManager.Instance.World_Diameter];

            topColony = new Agents.Colony();
            colonies  = new List <Agents.Colony>();
        }
示例#3
0
        /// <summary>
        /// Called after every awake has been called.
        /// </summary>
        private void Start()
        {
            GenerateData();
            GenerateChunks();

            Camera.main.transform.position = new Vector3(0 / 2, Blocks.GetLength(1), 0);
            Camera.main.transform.LookAt(new Vector3(Blocks.GetLength(0), 0, Blocks.GetLength(2)));



            if (!ConfigurationManager.Instance.loadTopColony)
            {
                topColony = new Agents.Colony(Deserialize("ant.dat"), Deserialize("queen.dat"));
                colonies.Add(null);
                colonies.Add(null);
                colonies.Add(null);
                colonies.Add(null);
                GenerateAnts();
            }
            else
            {
                topColony = new Agents.Colony(Deserialize("ant.dat"), Deserialize("queen.dat"));
            }
        }
示例#4
0
        private void FixedUpdate()
        {
            if (ConfigurationManager.Instance.loadTopColony)
            {
                if (Input.GetKeyUp(KeyCode.KeypadPlus))
                {
                    topColony.MoveColony();
                }

                return;
            }


            if (Input.GetKeyUp(KeyCode.End))
            {
                pause = !pause;
            }

            if (pause && !Input.GetKeyUp(KeyCode.KeypadPlus))
            {
                return;
            }
            // Update all ants

            // Must determine when to respawn everything
            bool allDead = true;

            // If all colonies dead, regenerate world and colonies
            foreach (Agents.Colony colony in colonies)
            {
                if (!colony.isAllDead())
                {
                    allDead = false;

                    // Move all ants according to their environment and nervous system
                    colony.MoveColony();
                }
            }

            if (allDead)
            {
                generation++;

                float bestFitness = topColony.fitness();
                foreach (Agents.Colony colony in colonies)
                {
                    if (colony.getTotalNestBlocks() > bestFitness)
                    {
                        topColony.DestroyColony();
                        topColony           = colony;
                        bestFitness         = colony.fitness();
                        noNewTopColonySince = generation;
                    }
                }


                // Remove all but the best
                foreach (Agents.Colony colony1 in colonies)
                {
                    if (colony1 != topColony)
                    {
                        colony1.DestroyColony();
                    }
                }



                Debug.Log("On generation " + generation.ToString() + " the best colony produced " + Mathf.Max(new float[] { colonies[0].getTotalNestBlocks(), colonies[1].getTotalNestBlocks(), colonies[2].getTotalNestBlocks(), colonies[3].getTotalNestBlocks() }).ToString() + " blocks.");
                Debug.Log("BUT no new top colony since generation " + noNewTopColonySince.ToString() + " with a global best of " + bestFitness.ToString());
                Debug.Log("Queen of Top Colony size - nodes: " + topColony.queen.GetComponent <Agents.Ant>().getNervousSystem().nodes.Count.ToString() + " connections " + topColony.queen.GetComponent <Agents.Ant>().getNervousSystem().connections.Count.ToString());

                if (bestFitness > prevBestFitness)
                {
                    prevBestFitness = bestFitness;
                    Serialize(new Agents.SerializableNS(topColony.bestAnt.GetComponent <Antymology.Agents.Ant>().getNervousSystem()), "ant.dat");
                    Serialize(new Agents.SerializableNS(topColony.queen.GetComponent <Antymology.Agents.Ant>().getNervousSystem()), "queen.dat");
                }


                // Resetting the world
                if (generation % 10 == 0)
                {
                    // Reset the world. Every 20 generations
                    RNG          = new System.Random((int)Time.time);
                    SimplexNoise = new SimplexNoise((int)Time.time);
                    // Initialize a new 3D array of blocks with size of the number of chunks times the size of each chunk
                    Blocks = new AbstractBlock[
                        ConfigurationManager.Instance.World_Diameter * ConfigurationManager.Instance.Chunk_Diameter,
                        ConfigurationManager.Instance.World_Height *ConfigurationManager.Instance.Chunk_Diameter,
                        ConfigurationManager.Instance.World_Diameter *ConfigurationManager.Instance.Chunk_Diameter];

                    for (int i = 0; i < ConfigurationManager.Instance.World_Diameter * ConfigurationManager.Instance.Chunk_Diameter; i++)
                    {
                        for (int j = 0; j < ConfigurationManager.Instance.World_Height * ConfigurationManager.Instance.Chunk_Diameter; j++)
                        {
                            for (int k = 0; k < ConfigurationManager.Instance.World_Diameter * ConfigurationManager.Instance.Chunk_Diameter; k++)
                            {
                                Blocks[i, j, k] = new AirBlock();
                            }
                        }
                    }


                    GameObject chunks = GameObject.Find("Chunks");
                    Destroy(chunks);

                    // Initialize a new 3D array of chunks with size of the number of chunks
                    Chunks = new Chunk[
                        ConfigurationManager.Instance.World_Diameter,
                        ConfigurationManager.Instance.World_Height,
                        ConfigurationManager.Instance.World_Diameter];


                    GenerateData();
                    GenerateChunks();
                }

                GenerateAnts();
            }
        }