예제 #1
0
        private void Simulate()
        {
            CrossOverManager crossOver = new CrossOverManager(amount, amountOfWater, numberOfWashrooms, numberOfWatertanks, numberOfTents, numberOfPeople, tentCapacity, mapSizeX, mapSizeY, waterPerPersonToDrink);
            int max = 0;
            int min = 100;

            minCamp = null;
            maxCamp = null;
            for (int i = 0; i < 50; i++)
            {
                Camp tmp   = crossOver.Run(50);
                int  happy = tmp.GetHappiness();
                if (max < happy)
                {
                    max     = happy;
                    maxCamp = tmp;
                }
                if (min > happy && happy != 0)
                {
                    min     = happy;
                    minCamp = tmp;
                }
            }
            Debug.Log("Done! Best result is " + maxCamp.GetHappiness());
            done = true;
        }
예제 #2
0
        private int CalculateHappiness()
        {
            Camp currentCamp  = Simulation.GetEmptyCamp();
            int  tentCapacity = Simulation.TentCapacity;
            // Set tents
            List <Tent> tentsForLord = new List <Tent>();

            foreach (GameObject tent in tents)
            {
                Vector2 position = new Vector3(tent.transform.position.x, tent.transform.position.z);
                tentsForLord.Add(new Tent(position, tentCapacity));
            }
            currentCamp.SetTents(tentsForLord);
            // Set watertanks
            List <Water> watertanksForLord = new List <Water>();

            foreach (GameObject watertank in watertanks)
            {
                watertanksForLord.Add(new Water((int)watertank.transform.position.x, (int)watertank.transform.position.z));
            }
            currentCamp.SetWaters(watertanksForLord);
            // Set washrooms
            List <Toilet> washroomsForLord = new List <Toilet>();

            foreach (GameObject washroom in washrooms)
            {
                Vector2 position = new Vector3(washroom.transform.position.x, washroom.transform.position.z);
                washroomsForLord.Add(new Toilet(position));
            }
            currentCamp.SetToilets(washroomsForLord);

            // Set water per person
            currentCamp.SetWaterPerPersonForDrink((int)UI.WaterPerPerson);
            return(currentCamp.GetHappiness());
        }
예제 #3
0
        public void OnClickDump()
        {
            string       path     = Application.dataPath + "/../SavedMap_" + System.DateTime.Now.ToBinary().ToString() + ".rc";
            BinaryWriter writer   = new BinaryWriter(new FileStream(path, FileMode.Create));
            Camp         bestCamp = GetComponent <SimulationController>().BestCamp;

            writer.Write(CalculateHappiness());
            // Player's camp
            writer.Write(tents.Count);
            foreach (GameObject tent in tents)
            {
                writer.Write((int)tent.transform.position.x);
                writer.Write((int)tent.transform.position.z);
            }

            writer.Write(watertanks.Count);
            foreach (GameObject watertank in watertanks)
            {
                writer.Write((int)watertank.transform.position.x);
                writer.Write((int)watertank.transform.position.z);
            }

            writer.Write(washrooms.Count);
            foreach (GameObject washroom in washrooms)
            {
                writer.Write((int)washroom.transform.position.x);
                writer.Write((int)washroom.transform.position.z);
            }
            // AI's camp
            writer.Write(bestCamp.GetHappiness());
            foreach (Tent tent in bestCamp.GetTents())
            {
                writer.Write(tent.X());
                writer.Write(tent.Y());
            }

            foreach (Water water in bestCamp.GetWaters())
            {
                writer.Write(water.X());
                writer.Write(water.Y());
            }

            foreach (Toilet toilet in bestCamp.GetToilets())
            {
                writer.Write(toilet.X());
                writer.Write(toilet.Y());
            }
            writer.Write(Settings.WaterHeight);
            writer.Close();
            Application.Quit();
        }