Beispiel #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            Ecosystem dARESystem = db.Ecosystems.Find(id);

            db.Ecosystems.Remove(dARESystem);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        private static void Ecosystem()
        {
            Console.Clear();
            Ecosystem ecosystem = new Ecosystem();

            ecosystem.RunEco();
            Console.ReadKey();
        }
 // called on child thread to enqueue functions to run
 public void QueueMainThread(Ecosystem ecosys)
 {
     // lock ecoQueue before enqueueing
     lock (ecoQueueLock)
     {
         ecoQueue.AddLast(ecosys);
         //Debug.Log("adding to queue with length: " + ecoQueue.Count);
     }
 }
        public async Task <Transaction> CreateManagedAsync(
            BitcoinAddress owner,
            Ecosystem ecosystem,
            PropertyType type,
            Property current,
            string category,
            string subcategory,
            string name,
            string url,
            string description,
            CancellationToken cancellationToken)
        {
            if (owner == null)
            {
                throw new ArgumentNullException(nameof(owner));
            }

            if (category == null)
            {
                throw new ArgumentNullException(nameof(category));
            }

            if (subcategory == null)
            {
                throw new ArgumentNullException(nameof(subcategory));
            }

            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (url == null)
            {
                throw new ArgumentNullException(nameof(url));
            }

            if (description == null)
            {
                throw new ArgumentNullException(nameof(description));
            }

            var resp = await Client.SendCommandAsync(
                "exodus_sendissuancemanaged",
                owner.ToString(),
                ToNative(ecosystem),
                ToNative(type),
                current != null?ToNative(current.Id) : 0U,
                    category,
                    subcategory,
                    name,
                    url,
                    description
                );

            return(Transaction.Parse(resp.Result.Value <string>(), Factory.Network));
        }
        public DogTreasureHuntScene(Ecosystem ecosystem, Keycosystem keycosystem, SpriteBatch spriteBatch, ContentManager content, StandardKeyboard keyboard)
        {
            this.Ecosystem   = ecosystem;
            this.Keycosystem = keycosystem;
            this.Keyboard    = keyboard;

            this.SpriteBatch = spriteBatch;
            this.Content     = content;
        }
        public ActionResult Create(Ecosystem objOrder)
        {
            EcoGameModelContainer db = new EcoGameModelContainer();


            db.EcosystemSet.Add(objOrder);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
    private void Awake()
    {
        TerrainGenerator generator = GetComponent <TerrainGenerator>();

        Assert.IsNotNull(generator);
        terrainData = generator.TerrainData;

        ecosystem = FindObjectOfType <Ecosystem>();
    }
Beispiel #8
0
 public ActionResult Edit([Bind(Include = "Name,DateInitiated,HomeAddress,City,State,ZIP,Description,FamilyName")] Ecosystem dARESystem)
 {
     if (ModelState.IsValid)
     {
         db.Entry(dARESystem).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(dARESystem));
 }
Beispiel #9
0
    /// <summary>
    /// convert a particular amount of startResources into endResources
    /// </summary>
    // TODO: write test for this
    public override void perform(Creature creature, Ecosystem eco)
    {
        // don't produce more than the creature can store
        foreach (string key in endResources.Keys)
        {
            CreatureResource resource     = creature.storedResources[key];
            float            storageSpace = resource.maxLevel - resource.currentLevel;
            float            toProduce    = amtToProduce * endResources[key];
            if (storageSpace < toProduce)
            {
                amtToProduce = storageSpace / endResources[key];
            }
        }


        // determine how much of the products can actually be produced
        // amount produced is the full amount intended, unless overriden below by a limiting reactant
        float actualAmtProduced = amtToProduce;

        foreach (string resource in startResources.Keys)
        {
            float multipleNeeded   = startResources[resource];
            float amtOfResRequired = amtToProduce * multipleNeeded;
            // if the creature doesn't have enough of a particular resource
            float actualStored = creature.storedResources[resource].currentLevel;
            // if there is not enough of the resource to produce the full amount
            if (actualStored < amtOfResRequired)
            {
                // calculate how much the resource can produce
                float amtProducedByRes = actualStored / multipleNeeded;
                // if that amount is less than the current amount actually produced, update the current amount
                if (amtProducedByRes < actualAmtProduced)
                {
                    actualAmtProduced = amtProducedByRes;
                }
            }
        }

        /* use the amount that can actaully be produced to update resource values */

        // update reactant levels
        foreach (string resource in startResources.Keys)
        {
            float amtUsed = startResources[resource] * actualAmtProduced;
            creature.storedResources[resource].currentLevel -= amtUsed;
        }

        // update product levels
        foreach (string resource in endResources.Keys)
        {
            float amtCreated = endResources[resource] * actualAmtProduced;
            creature.storedResources[resource].currentLevel += amtCreated;
        }
    }
    public void StartEcoSim()
    {
        statsPrinter = statsPrinterObj.GetComponent <StatsPrinter>();
        statsPrinter.printFirstLine(unityEco);

        // create a copy, and set simulationEco to set the copy, then use the copy for the simulation
        Ecosystem simulationEco = Copier.getEcosystemCopy(unityEco);
        int       localSteps    = steps; // just in case next line causes threading error

        StartThreadedFunction(() => { runSystem(simulationEco, localSteps, Thread.CurrentThread); });
    }
Beispiel #11
0
	// BIG TODO: change the hierarchy to a messaging system
	void Start() {
		// TODO: make this read from a file instead of hardcoded ofc lol
		foodWeb = new RungeEcosystem();
		foodWeb.AddSpecies("grass",       -0.03f,  1.0f,  0f);
		foodWeb.AddSpecies("oak tree",    -0.03f,  0.8f, 10f);
		foodWeb.AddSpecies("berries",     -0.03f,  0.6f, 10f);
		foodWeb.AddSpecies("rabbit",      -0.01f, -0.1f,  0f);
		foodWeb.AddSpecies("caterpillar", -0.01f, -0.2f, 10f);
		foodWeb.AddSpecies("squirrel",    -0.01f, -0.2f, 10f);
		foodWeb.AddSpecies("fox",         -0.01f, -0.2f,  0f);
		
		foodWeb.AddInteraction("rabbit",      "grass",       0.05f, 0.8f);
		foodWeb.AddInteraction("rabbit",      "berries",     0.02f, 0.8f);
		foodWeb.AddInteraction("squirrel",    "berries",     0.02f, 0.8f);
		foodWeb.AddInteraction("squirrel",    "oak tree",    0.04f, 0.8f);
		foodWeb.AddInteraction("caterpillar", "oak tree",    0.04f, 0.8f);
		foodWeb.AddInteraction("fox",         "berries",     0.02f, 0.5f);
		foodWeb.AddInteraction("fox",         "squirrel",    0.02f, 0.6f);
		foodWeb.AddInteraction("fox",         "rabbit",      0.05f, 0.6f);
		foodWeb.AddInteraction("fox",         "caterpillar", 0.01f, 0.5f);
		// TODO: add humans hunting as the interesting bit of this ecosystem

		Transform iconTransform = new GameObject("Icon Manager").transform; // for organisation
		iconTransform.SetParent(transform);
		iconWeb = new IconManager(iconTransform, transferPrefab, interactionPrefab);
		iconWeb.AddSpecies("grass",       'p',    0f,  0f,  100f, 1f, iconPrefab, pictures[0], Color.green);
		iconWeb.AddSpecies("oak tree",    'p',    0f, 10f,  100f, 1f, iconPrefab, pictures[1], Color.black);
		iconWeb.AddSpecies("berries",     'p',    0f, 10f,  100f, 1f, iconPrefab, pictures[2], Color.magenta);
		iconWeb.AddSpecies("rabbit",      'h',    1f,  0f,  100f, 1f, iconPrefab, pictures[3], Color.grey);
		iconWeb.AddSpecies("caterpillar", 'h', 0.03f, 10f,  100f, 1f, iconPrefab, pictures[4], Color.yellow);
		iconWeb.AddSpecies("squirrel",    'h',  0.5f, 10f,  100f, 1f, iconPrefab, pictures[5], Color.white);
		iconWeb.AddSpecies("fox",         'o',    5f,  0f,  100f, 1f, iconPrefab, pictures[6], Color.red);

		speciesNames = new List<string>();
		speciesNames.Add("grass");
		speciesNames.Add("oak tree");
		speciesNames.Add("berries");
		speciesNames.Add("rabbit");
		speciesNames.Add("caterpillar");
		speciesNames.Add("squirrel");
		speciesNames.Add("fox");
		foreach (string species in speciesNames) SetIconInteractionSprings(species);
		
		CreateGraph();
		InvokeRepeating("UpdateIconPopulations", 0.7f, 2f);

		screenWidth = 2f * Camera.main.orthographicSize * Screen.width / Screen.height;
		screenHeight = screenWidth / Screen.width * Screen.height;

		gui = transform.Find("GUI").GetComponent<GUI>();
		gui.Init(screenWidth, screenHeight);
	}
Beispiel #12
0
        public KbScene(
            Ecosystem ecosystem,
            Keycosystem keycosystem,
            DirectiveRenderer renderer,
            FpsCounter fpsCounter)
        {
            this.Ecosystem   = ecosystem;
            this.Keycosystem = keycosystem;
            this.Renderer    = renderer;
            this.FpsCounter  = fpsCounter;

            this.Camera = renderer.GetViewport("default");
        }
    public static NetworkResponse Parse(MemoryStream dataStream)
    {
        ResponseEcosystem response = new ResponseEcosystem();

        response.status = DataReader.ReadShort(dataStream);

        List <Zone> zones = new List <Zone>();

        if (response.status == 0)
        {
            int eco_id = DataReader.ReadInt(dataStream);

            Ecosystem ecosystem = new Ecosystem(eco_id);
            ecosystem.type  = DataReader.ReadShort(dataStream);
            ecosystem.score = DataReader.ReadInt(dataStream);

            int player_id = DataReader.ReadInt(dataStream);

            Player player = new Player(player_id);
            player.name = DataReader.ReadString(dataStream);

            string[] rgb = DataReader.ReadString(dataStream).Split(',');
            player.color = new Color32(byte.Parse(rgb[0]), byte.Parse(rgb[1]), byte.Parse(rgb[2]), 255);

            ecosystem.player = player;

            string zone_str = DataReader.ReadString(dataStream);
            foreach (string item in zone_str.Split(';'))
            {
                if (item == "")
                {
                    continue;
                }

                string[] temp = item.Split(',');

                Zone zone = new Zone(int.Parse(temp[0]));
                zone.row          = short.Parse(temp[1]);
                zone.column       = short.Parse(temp[2]);
                zone.terrain_type = short.Parse(temp[3]);
                zone.v_capacity   = int.Parse(temp[4]);

                zones.Add(zone);
            }
            ecosystem.zones = zones;

            response.ecosystem = ecosystem;
        }

        return(response);
    }
Beispiel #14
0
        protected static byte ToNative(Ecosystem ecosystem)
        {
            switch (ecosystem)
            {
            case Ecosystem.Main:
                return(1);

            case Ecosystem.Test:
                return(2);

            default:
                throw new ArgumentOutOfRangeException(nameof(ecosystem), ecosystem, "The value is not valid.");
            }
        }
Beispiel #15
0
        // GET: Ecosystem/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Ecosystem dARESystem = db.Ecosystems.Find(id);

            if (dARESystem == null)
            {
                return(HttpNotFound());
            }
            return(View(dARESystem));
        }
    private void Start()
    {
        m_Ecosystem = GameObject.FindGameObjectWithTag("Ecosystem").GetComponent <Ecosystem>();

        NoduleMaxField.onEndEdit.AddListener(val => Manager.ForwardCommand("/world limit nodules " + val));
        PlantCurrentField.onEndEdit.AddListener(val => Manager.ForwardCommand("/world set-count plants " + val));
        PlantMaxField.onEndEdit.AddListener(val => Manager.ForwardCommand("/world limit plants " + val));
        HerbivoreMinField.onEndEdit.AddListener(val => Manager.ForwardCommand("/world minimum herbivores " + val));
        HerbivoreCurrentField.onEndEdit.AddListener(val => Manager.ForwardCommand("/world set-count herbivores " + val));
        HerbivoreMaxField.onEndEdit.AddListener(val => Manager.ForwardCommand("/world limit herbivores " + val));
        CarnivoreMinField.onEndEdit.AddListener(val => Manager.ForwardCommand("/world minimum carnivores " + val));
        CarnivoreCurrentField.onEndEdit.AddListener(val => Manager.ForwardCommand("/world set-count carnivores " + val));
        CarnivoreMaxField.onEndEdit.AddListener(val => Manager.ForwardCommand("/world limit carnivores " + val));
    }
Beispiel #17
0
    public override void perform(Creature creature, Ecosystem eco)
    {
        // TODO: reduce redundancy in code
        switch (direction)
        {
        case moveDir.up:
            if (!creature.neighborLands[1].creatureIsOn() && creature.position[1] + 1 < creature.map[creature.position[0]].Count)
            {
                creature.neighborLands[0].creatureOn = null;
                creature.position[1] += 1;
                creature.updateNeighbors();
                creature.neighborLands[0].creatureOn = creature;
            }
            break;

        case moveDir.down:
            if (!creature.neighborLands[2].creatureIsOn() && creature.position[1] - 1 >= 0)
            {
                creature.neighborLands[0].creatureOn = null;
                creature.position[1] -= 1;
                creature.updateNeighbors();
                creature.neighborLands[0].creatureOn = creature;
            }
            break;

        case moveDir.left:
            if (!creature.neighborLands[3].creatureIsOn() && creature.position[0] - 1 >= 0)
            {
                creature.neighborLands[0].creatureOn = null;
                creature.position[0] -= 1;
                creature.updateNeighbors();
                creature.neighborLands[0].creatureOn = creature;
            }
            break;

        case moveDir.right:
            if (!creature.neighborLands[4].creatureIsOn() && creature.position[0] + 1 < creature.map.Count)
            {
                creature.neighborLands[0].creatureOn = null;
                creature.position[0] += 1;
                creature.updateNeighbors();
                creature.neighborLands[0].creatureOn = creature;
            }
            break;

        default:
            break;
        }
    }
Beispiel #18
0
 private void startRender(Ecosystem sys)
 {
     //Debug.Log("in render");
     for (int x = 0; x < sys.map.Count; x++)
     {
         tiles.Add(new List <GameObject>());
         for (int y = 0; y < sys.map[x].Count; y++)
         {
             GameObject tile             = GameObject.Instantiate(tilePrefab, new Vector3(x, y, 0), Quaternion.identity);
             float      proportionStored = (float)sys.map[x][y].propertyDict["grass"].getProportionStored();
             //Debug.Log(proportionStored);
             tile.GetComponent <SpriteRenderer>().color = new Color(proportionStored, proportionStored, proportionStored);
             tiles[x].Add(tile);
         }
     }
 }
    public static NetworkResponse Parse(MemoryStream dataStream)
    {
        ResponseEcosystem response = new ResponseEcosystem();
        response.status = DataReader.ReadShort(dataStream);

        List<Zone> zones = new List<Zone>();

        if (response.status == 0) {
            int eco_id = DataReader.ReadInt(dataStream);

            Ecosystem ecosystem = new Ecosystem(eco_id);
            ecosystem.type = DataReader.ReadShort(dataStream);
            ecosystem.score = DataReader.ReadInt(dataStream);

            int player_id = DataReader.ReadInt(dataStream);

            Player player = new Player(player_id);
            player.name = DataReader.ReadString(dataStream);

            string[] rgb = DataReader.ReadString(dataStream).Split(',');
            player.color = new Color32(byte.Parse(rgb[0]), byte.Parse(rgb[1]), byte.Parse(rgb[2]), 255);

            ecosystem.player = player;

            string zone_str = DataReader.ReadString(dataStream);
            foreach (string item in zone_str.Split(';')) {
                if (item == "") {
                    continue;
                }

                string[] temp = item.Split(',');

                Zone zone = new Zone(int.Parse(temp[0]));
                zone.row = short.Parse(temp[1]);
                zone.column = short.Parse(temp[2]);
                zone.terrain_type = short.Parse(temp[3]);
                zone.v_capacity = int.Parse(temp[4]);

                zones.Add(zone);
            }
            ecosystem.zones = zones;

            response.ecosystem = ecosystem;
        }

        return response;
    }
Beispiel #20
0
        public static void Restore()
        {
            EcoSnapshot last = History.GetInstance().Pop();

            if (last != null)
            {
                History.GetInstance().ClearData();
                Ecosystem.GetInstance().Species.Clear();
                int i = 0;
                foreach (Species sp in last.Spec)
                {
                    Ecosystem.GetInstance().AddSpecies(sp);
                    History.GetInstance().Data[i].Add(sp.Population);
                    i++;
                }
            }
        }
Beispiel #21
0
    public void printStats(Ecosystem eco)
    {
        string age = eco.age.ToString();

        StringBuilder csv = new StringBuilder();

        StringBuilder line = new StringBuilder(eco.populations.Keys.Count * 30);

        foreach (string key in eco.populations.Keys)
        {
            line.Append(age + ", " + eco.populations[key].size + ", " + eco.populations[key].overallVariability + ", ");
        }
        line.Remove(line.Length - 3, 2);
        //Debug.Log(line);
        csv.AppendLine(line.ToString());
        File.AppendAllText(fileName, csv.ToString());
    }
Beispiel #22
0
    public void menuStart()
    {
        List <string> options = new List <string>();

        dropD = gameObject.GetComponent <Dropdown>();
        sys   = dataRetriever.GetComponent <EcosystemGetter>().GetEcosystem();
        foreach (string res in sys.resourceOptions.Keys)
        {
            options.Add(res);
        }
        options.Add("Black");
        dropD.ClearOptions();
        dropD.AddOptions(options);

        dropD.onValueChanged.AddListener(delegate {
            valueChanged();
        });
    }
Beispiel #23
0
        public void SimpleStrategyTest()
        {
            //Data Init
            Species fox = new Species("Fox", 10, 3, 1, 200);

            Ecosystem.GetInstance().AddSpecies(fox);
            Counter.GetInstance().ChangeMathModel(new LogisticModel());
            IRefreshStrategy strategy = new ManualRefresh();
            int expectResult          = 29;

            //Actions
            strategy.Refresh();

            //Check results
            Assert.AreEqual(expectResult, fox.Population);
            Ecosystem.GetInstance().Species.Clear();
            History.GetInstance().Data.Clear();
        }
Beispiel #24
0
    public void menuStart()
    {
        sr = mapSpriteObj.GetComponent <SpriteRenderer>();
        Debug.LogWarning("*******************              simRunner awake              ******************");
        // create threader
        threader = gameObject.GetComponent <ThreadManager>();
        // perform initial renderings
        //startRender(threader.getEcosystem());
        Ecosystem sys = threader.getEcosystem();

        texture            = new Texture2D(sys.map.Count, sys.map[0].Count, TextureFormat.ARGB32, false);
        texture.filterMode = FilterMode.Point;
        //updateRenderT(sys); // is this one necessary? costly?
        // set steps for each interval
        threader.setSteps(intervalSteps);
        // initiate simulation on child thread
        threader.StartEcoSim();
        started = true;
    }
Beispiel #25
0
    void SpawnInRandomLocation()
    {
        Ecosystem ecosystem = FindObjectOfType <Ecosystem>();

        int   posX = Random.Range(0, (int)ecosystem.terrainManager.terrainSize.x);
        int   posY = Random.Range(0, (int)ecosystem.terrainManager.terrainSize.y);
        float rotY = Random.Range(-180f, 180f);

        transform.position = new Vector3(posX, ecosystem.terrainManager.maxHeight + 1, posY);

        RaycastHit newHit;
        Ray        newRay = new Ray(transform.position, Vector3.down);

        Physics.Raycast(newRay, out newHit, 50f);

        respawnPos         = newHit.transform.position + (newHit.normal * 3f);
        transform.position = respawnPos;
        transform.rotation = Quaternion.Euler(new Vector3(0, rotY, 0));
    }
        public void N_SpeciesModelTest_10to50_10to105()
        {
            //Init data
            int foxCurrentPopulation  = 10;
            int foxBirth              = 3;
            int foxDeath              = 1;
            int foxEcoCapacity        = 200;
            int foxExpectedPopulation = 50;

            int rabbitCurrentPopulation  = 10;
            int rabbitBirth              = 7;
            int rabbitDeath              = 2;
            int rabbitEcoCapacity        = 500;
            int rabbitExpectedPopulation = 105;


            //Actions
            Species fox = new Species("fox", foxCurrentPopulation, foxBirth, foxDeath, foxEcoCapacity);

            Ecosystem.GetInstance().AddSpecies(fox);

            Species rabbit = new Species("rabbit", rabbitCurrentPopulation, rabbitBirth, rabbitDeath, rabbitEcoCapacity);

            Ecosystem.GetInstance().AddSpecies(rabbit);

            fox.Relations[0] = -0.1;
            fox.Relations[1] = 0.3;

            rabbit.Relations[0] = -0.05;
            rabbit.Relations[1] = 0.5;


            IMathModel lm = new N_SpaciesModel_General();

            lm.Recount();

            //Check
            Assert.AreEqual(foxExpectedPopulation, fox.Population);
            Assert.AreEqual(rabbitExpectedPopulation, rabbit.Population);

            Ecosystem.GetInstance().Species.Clear();
            History.GetInstance().Data.Clear();
        }
Beispiel #27
0
    /// <summary>
    /// Starts creatures turn
    /// </summary>
    public void startTurn(Ecosystem eco)
    {
        //Debug.Log("pop size: " + parentPopulation.size);
        //Debug.Log("before: " + actionQueue.Count);
        // reset turn time
        remainingTurnTime = fullTurnTime;
        // run inputs through neural networks
        updateNets();
        // add actions to action queue
        addActionsToQueue();
        // perform actions
        performActions(eco);
        // update health based on resource levels
        resourceHealthUpdate();
        baseResourceUse();


        //Debug.Log("after: " + actionQueue.Count);
    }
        public GameSelectScene(
            Ecosystem ecosystem,
            Keycosystem keycosystem,
            Director director,
            DebugLogger debugLogger,
            DirectiveRenderer renderer,
            FpsCounter fpsCounter,
            Window window)
        {
            this.Ecosystem   = ecosystem;
            this.Keycosystem = keycosystem;
            this.Director    = director;
            this.DebugLogger = debugLogger;
            this.Renderer    = renderer;
            this.FpsCounter  = fpsCounter;
            this.Window      = window;

            this.Camera = renderer.GetViewport("default");
        }
    private void Awake()
    {
        motherGenesData = GetComponent <Genes>().genesData;

        GameObject pregnantSignGO = new GameObject();

        pregnantSignGO.name = "Pregnant Sign";

        BehaviourCommunicator communicator = GetComponentInChildren <BehaviourCommunicator>();

        pregnantSignGO.transform.parent        = communicator.transform;
        pregnantSignGO.transform.localPosition = COMMUNICATION_OFFSET;
        pregnantSignGO.transform.localScale    = new Vector3(COMMUNICATION_SCALE, COMMUNICATION_SCALE, COMMUNICATION_SCALE);

        pregnantIcon              = pregnantSignGO.AddComponent <SpriteRenderer>();
        pregnantIcon.sprite       = GetComponent <VitalFunctions>().PregnantCommunicationSprite;
        pregnantIcon.sortingOrder = communicator.GetComponent <SpriteRenderer>().sortingOrder + 1;

        ecosystem = FindObjectOfType <Ecosystem>();
    }
Beispiel #30
0
        public void SnapshotTest()
        {
            int     startPopulation = 10;
            Species fox             = new Species("fox", startPopulation, 3, 1, 200);

            Ecosystem.GetInstance().AddSpecies(fox);
            Memento.Save();

            IMathModel model = new LogisticModel();

            model.Recount();

            Assert.AreEqual(29, fox.Population);

            Memento.Restore();
            Assert.AreEqual(startPopulation, Ecosystem.GetInstance().Species[0].Population);

            Ecosystem.GetInstance().Species.Clear();
            History.GetInstance().Data.Clear();
        }
Beispiel #31
0
    /// <summary>
    /// Performs whatever actions in the queue it can.
    /// </summary>
    public void performActions(Ecosystem eco)
    {
        // the queue for the next turn
        SimplePriorityQueue <Action> nextQueue = new SimplePriorityQueue <Action>();

        while (actionQueue.Count > 0)
        {
            Action nextAction = actionQueue.Dequeue();

            // if action is not possible, then ignore it (don't add it to the queue)
            if (nextAction.isPossible(this))
            {
                // ignore actions that the creature doesn't have enough resources to perform
                if (nextAction.enoughResources(this))
                {
                    // if there is time left for an action, perform it
                    if (nextAction.timeCost <= remainingTurnTime)
                    {
                        //Debug.Log("performing " + nextAction.name);
                        nextAction.performWrapper(this, eco);
                    }
                    else
                    {
                        // put actions that take too long on the next turn's queue
                        nextQueue.Enqueue(nextAction, nextAction.priority);
                    }
                }
            }
        }
        // actionQueue is now the queue for next turn
        actionQueue = nextQueue;

        // keep action queue a manageable size by clearing it every few steps, and clearing it if its size gets too big
        if (actionClearCount > actionClearInterval || actionQueue.Count >= actionClearSize)
        {
            actionClearCount = 0;
            actionQueue.Clear();
        }
        actionClearCount++;
        //Debug.Log("Queue size: " + actionQueue.Count);
    }
    public Ecosystem GetEcosystem()
    {
        Ecosystem eco = threader.getEcosystem();

        /*
         * Debug.Log("******************                     **********************               ***********");
         * for (int i = 0; i < eco.map.Count; i++)
         * {
         *  for (int j = 0; j < eco.map[i].Count; j++)
         *  {
         *
         *      if (eco.map[i][j].creatureIsOn())
         *      {
         *          Debug.Log("*** queue length: " + eco.map[i][j].creatureOn.actionQueue.Count);
         *      }
         *  }
         * }
         * Debug.Log("******************                     **********************               ***********");
         */
        return(threader.getEcosystem());
    }
Beispiel #33
0
 public Main(Ecosystem ecosystem)
 {
     this.Ecosystem = ecosystem;
 }