Esempio n. 1
0
        // creates a chamber folder that can contain certain objects and has certain functions.
        private void CreateChamber()
        {
            int randomChamberID = 0;
            Chamber chamber;
            // This is a random id for the tunnel. The tunnel is not tracked, but we dont want tunnels overwriting eachother.

            Random rnd = new Random();

            /*
             * I think my plan here will be to generate a random 6 digit number
             * check the folder to see if a tunnel with that id already exists
             * if yes, re-generate the ID and try again. (do -while loop for random generation?)
             * if no, create the tunnel and enter it.
             */
            do
            {
                randomChamberID = rnd.Next(999999);//generate ID
            }
            while (Directory.Exists(LocationProperty + @"\"+ digTask + "_" + randomChamberID.ToString("D6"))); // check if exists.

            Directory.CreateDirectory(LocationProperty + @"\" + digTask +"_" + randomChamberID.ToString("D6"));

            if (digTask == "ThroneRoom")
            {
                MyAnthillProperty.ants[0].NewThroneRoomProperty = true;
            }
            chamber = new Chamber();
            chamber.TypeProperty = (ChamberType) Enum.Parse(typeof(ChamberType), digTask);
            chamber.IDProperty = randomChamberID;
            MyAnthillProperty.chambers.Add(randomChamberID, chamber);
        }
Esempio n. 2
0
        // Here the ant decides how to act, and "per-tick" actions take place (ex. hunger drops etc)
        public override void Act()
        {
            Pheromone placedPheromone = null;
            string directoryName = Path.GetFileName(Path.GetDirectoryName(FullPathProperty));
            pheromoneLocations.Clear();
            DestinationProperty = "";

            Update();

            /*

             * Split logic into two major chains
             * InNest logic and !InNest logic.
             *
             * The reason behind this split is due to the fact that different things should happen in the nest compared to outside
             * for example:
             *      if the ant has food and is OUTSIDE the nest, she must find her way back by following "ToNest" pheromones
             *
             *      else if the ant is INSIDE the nest, the ant must find her way to the food stashes and back to the entrance
             *      following the "ToFoodStash" and "ToEntrance" pheromones.
             *
             *      also, ants that have no task inside the nest must be in a "Scouting" State. Outside the nest they would look for food
             *      but INSIDE the nest they would have to find the entrance to the nest in order to leave.
             *
             * thus i have split the logic into two function calls to InNest and !InNest logic.
             * The key to these seperate logic groups is that i can also easily identify when the ant has entered or left the nest
             * allowing me to track its InNest state.
            */
            if(!InNestProperty)
            {

                OutOfNestLogic(placedPheromone, directoryName);
            }
            else
            {
                dirSplit = Regex.Split(directoryName, "_");
                chamber = dirSplit[0];
                if (chamber != "Anthill")
                {
                    try
                    {
                        currentChamber = MyAnthillProperty.chambers[int.Parse(dirSplit[1])];
                    }
                    catch (KeyNotFoundException err)
                    { }

                }
                InNestLogic(placedPheromone, directoryName);
            }
        }
Esempio n. 3
0
        //passed the enviroment root
        private void LoadScenario(string saveFilePath)
        {
            //take root folder as selected by user
            //init ant hill
            //store anthill stats.
            //store pointer in dictionary
            //init ant
            //store stats
            //store pointer in dictionary
            if (new FileInfo(saveFilePath).Length != 0)
            {

                using (StreamReader sr = new StreamReader(saveFilePath))
                {
                    string line = "";
                    int counter = 0;

                    //A temp value for parsing ints
                    int temp;
                    bool tempBool;

                    //temp objects
                    AntHill tempAnthill;
                    Chamber tempChamber = new Chamber();
                    Pheromone tempPhe = new Pheromone(0, "", PheromoneEnum.Danger, true);

                    Worker tempWorker = new Worker(0, 0, "", true);
                    Queen tempQueen = new Queen(0, 0, "", true);
                    Egg tempEgg = new Egg(0, 0, "", true);
                    Larvae tempLarvae = new Larvae(0, 0, "", true);
                    Pupae tempPupae = new Pupae(0, 0, "", true);
                    Ant antPointer = tempWorker;

                    while ((line = sr.ReadLine()) != "[Enviroment Stats End]")
                    {
                        counter++;

                        if (counter == 1)
                        {
                            this.enviromentFullPath = line;
                        }
                    }

                    tempAnthill = new AntHill(0, "", false);
                    counter = 0;
                    while ((line = sr.ReadLine()) != "[Anthill Stats End]")
                    {

                        counter++;

                        /*
                         1   sw.WriteLine(antHills[0].LocationProperty);
                         2   sw.WriteLine(antHills[0].IDProperty);
                         3   sw.WriteLine(antHills[0].AntsDiggingProperty);
                         4   sw.WriteLine(antHills[0].AntsMoveingEggsProperty);
                         5   sw.WriteLine(antHills[0].AntsScoutingProperty);
                         6   sw.WriteLine(antHills[0].AntsTendingToBroodProperty);
                         7   sw.WriteLine(antHills[0].AntsTendingToQueenProperty);
                         8   sw.WriteLine(antHills[0].AntsTotalProperty);
                         */

                        if (counter == 1)
                        {
                            tempAnthill.LocationProperty = line;

                        }
                        else if (counter == 2)
                        {

                            int.TryParse(line, out temp);
                            tempAnthill.IDProperty = temp;

                        }
                        else if (counter == 3)
                        {
                            int.TryParse(line, out temp);
                            tempAnthill.AntsDiggingProperty = temp;

                        }
                        else if (counter == 4)
                        {
                            int.TryParse(line, out temp);
                            tempAnthill.AntsMoveingEggsProperty = temp;

                        }
                        else if (counter == 5)
                        {
                            int.TryParse(line, out temp);
                            tempAnthill.AntsScoutingProperty = temp;

                        }
                        else if (counter == 6)
                        {
                            int.TryParse(line, out temp);
                            tempAnthill.AntsTendingToBroodProperty = temp;

                        }
                        else if (counter == 7)
                        {
                            int.TryParse(line, out temp);
                            tempAnthill.AntsTendingToQueenProperty = temp;
                            antHills[0] = tempAnthill;
                            txtOutput.Text += Environment.NewLine + "Anthill" + tempAnthill.IDProperty + " Loaded";

                        }

                    }

                    counter = 0;
                    txtOutput.Text += Environment.NewLine + "Chambers Start: ";
                    //For the rest of the categories, I will have to set up a couple of loops.
                    //One for the category as a whole, and one for each record in that category.
                    while ((line = sr.ReadLine()) != "[Anthill Chamber Stats End]")
                    {
                        if (line == "[Anthill Chamber End]")
                        {
                            tempChamber = new Chamber();
                            counter = 0;
                        }
                        else
                        {
                            counter++;
                        }

                        /*
                        1 sw.WriteLine(antHills[0].chambers[i].IDProperty);
                        2 sw.WriteLine(antHills[0].chambers[i].TypeProperty);
                        3 sw.WriteLine(antHills[0].chambers[i].LocationProperty);
                        4 sw.WriteLine(antHills[0].chambers[i].AmountOfFoodProperty);
                        5 sw.WriteLine(antHills[0].chambers[i].AmountOfOffspringProperty);
                        6 sw.WriteLine(antHills[0].chambers[i].CapacityReachedProperty);
                        */

                        if (counter == 1)
                        {
                            int.TryParse(line, out temp);
                            tempChamber.IDProperty = temp;

                        }
                        else if (counter == 2)
                        {
                            tempChamber.TypeProperty = (ChamberType)Enum.Parse(typeof(ChamberType), line);

                        }
                        else if (counter == 3)
                        {
                            tempChamber.LocationProperty = line;

                        }
                        else if (counter == 4)
                        {
                            int.TryParse(line, out temp);
                            tempChamber.AmountOfFoodProperty = temp;

                        }
                        else if (counter == 5)
                        {
                            int.TryParse(line, out temp);
                            tempChamber.AmountOfOffspringProperty = temp;

                        }
                        else if (counter == 6)
                        {
                            bool.TryParse(line, out tempBool);
                            tempChamber.CapacityReachedProperty = tempBool;
                            txtOutput.Text += Environment.NewLine + "Anthill Chamber" + tempChamber.IDProperty + " Loaded";

                        }

                        //Add to list

                    }

                    while ((line = sr.ReadLine()) != "[Pheremone Stats End]")
                    {
                        if (line == "[Anthill Chamber End]")
                        {
                            tempPhe = new Pheromone(0, "", PheromoneEnum.Danger, true);
                            counter = 0;
                        }
                        else
                        {
                            counter++;
                        }

                        /*
                        1 sw.WriteLine(antHills[0].pheromonesPlaced[i].ColonyIDProperty);
                        2 sw.WriteLine(antHills[0].pheromonesPlaced[i].FullPathProperty);
                        3 sw.WriteLine(antHills[0].pheromonesPlaced[i].LocationProperty);
                        4 sw.WriteLine(antHills[0].pheromonesPlaced[i].StrengthProperty);
                        5 sw.WriteLine(antHills[0].pheromonesPlaced[i].TypeProperty);
                         */

                        if (counter == 1)
                        {
                            int.TryParse(line, out temp);
                            tempPhe.ColonyIDProperty = temp;
                        }
                        else if (counter == 2)
                        {
                            tempPhe.FullPathProperty = line;
                        }
                        else if (counter == 3)
                        {
                            tempPhe.LocationProperty = line;
                        }
                        else if (counter == 4)
                        {
                            int.TryParse(line, out temp);
                            tempPhe.StrengthProperty = temp;
                        }
                        else if (counter == 5)
                        {
                            tempPhe.TypeProperty = (PheromoneEnum)Enum.Parse(typeof(PheromoneEnum), line);
                            txtOutput.Text += Environment.NewLine + "Pheremone" + tempPhe.TypeProperty.ToString() + " Loaded";
                        }

                    }

                    while ((line = sr.ReadLine()) != "[Ant Stats End]")
                    {

                        if (line == "[Ant End]")
                        {
                            counter = 0;
                        }
                        else
                        {
                            counter++;
                        }

                        /*
                        1 sw.WriteLine(antHills[0].ants[i].TypeProperty);
                        2 sw.WriteLine(antHills[0].ants[i].IDProperty);
                        3 sw.WriteLine(antHills[0].ants[i].FullPathProperty);
                        4 sw.WriteLine(antHills[0].ants[i].LocationProperty);
                        5 sw.WriteLine(antHills[0].ants[i].HungerProperty);
                        6 sw.WriteLine(antHills[0].ants[i].HealthProperty);
                        7 sw.WriteLine(antHills[0].ants[i].AgeProperty);
                        8 sw.WriteLine(antHills[0].ants[i].BeingCarriedProperty);
                        9 sw.WriteLine(antHills[0].ants[i].CarriedAntProperty.IDProperty);
                        10 sw.WriteLine(antHills[0].ants[i].CarriedObjectFullPathProperty);
                        11 sw.WriteLine(antHills[0].ants[i].CarriedObjectLocationProperty);
                        12 sw.WriteLine(antHills[0].ants[i].CarryAmountProperty);
                        13 sw.WriteLine(antHills[0].ants[i].CarryingProperty);
                        14 sw.WriteLine(antHills[0].ants[i].ColonyIDProperty);
                        15 sw.WriteLine(antHills[0].ants[i].DestinationProperty);
                        16 sw.WriteLine(antHills[0].ants[i].InNestProperty);
                        17 sw.WriteLine(antHills[0].ants[i].NewThroneRoomProperty);
                        18 sw.WriteLine(antHills[0].ants[i].PheromoneProperty);
                        19 sw.WriteLine(antHills[0].ants[i].PreviousLocationProperty);
                        20 sw.WriteLine(antHills[0].ants[i].StateProperty);
                        21 sw.WriteLine(antHills[0].ants[i].StepCountProperty);

                        */

                        if (counter == 1)
                        {
                            if (line == "Queen")
                            {
                                tempQueen = new Queen(0, 0, "", true);
                                antPointer = tempQueen;
                            }
                            else if (line == "Egg")
                            {
                                tempEgg = new Egg(0, 0, "", true);
                                antPointer = tempEgg;
                            }
                            else if (line == "Larvae")
                            {
                                tempLarvae = new Larvae(0, 0, "", true);
                                antPointer = tempLarvae;
                            }
                            else if (line == "Pupae")
                            {
                                tempPupae = new Pupae(0, 0, "", true);
                                antPointer = tempPupae;
                            }
                            else if (line == "Worker")
                            {
                                tempWorker = new Worker(0, 0, "", true);
                                antPointer = tempWorker;
                            }

                        }
                        else if (counter == 2)
                        {
                            int.TryParse(line, out temp);
                            antPointer.IDProperty = temp;
                        }
                        else if (counter == 3)
                        {
                            antPointer.FullPathProperty = line;
                        }
                        else if (counter == 4)
                        {
                            antPointer.LocationProperty = line;
                        }
                        else if (counter == 5)
                        {
                            int.TryParse(line, out temp);
                            antPointer.HungerProperty = temp;
                        }
                        else if (counter == 6)
                        {
                            int.TryParse(line, out temp);
                            antPointer.HealthProperty = temp;
                        }
                        else if (counter == 7)
                        {
                            int.TryParse(line, out temp);
                            antPointer.AgeProperty = temp;
                        }
                        else if (counter == 8)
                        {
                            bool.TryParse(line, out tempBool);
                            antPointer.BeingCarriedProperty = tempBool;
                        }
                        else if (counter == 9)
                        {
                            //This is an object, so i will have to perhaps store the id of the ant instead, then get that ant.
                            //Or ignore this all together, but thats not good.
                            //I might have to change this property to store the ID anyway, then have the ant look for the
                            //cooresponding ant by ID.
                            //antPointer.CarriedAntProperty

                            //what i can do is use the ant dictionary and just point to the ID regardless of if it's a null value.
                            //that ant will get placed in the dictionary anyway at the end of the load.
                            if (line == "nullValue")
                            {
                                antPointer.CarriedAntProperty = null;
                            }
                            else
                            {
                                int.TryParse(line, out temp);
                                antPointer.CarriedAntProperty = antHills[0].ants[temp];
                            }

                        }
                        else if (counter == 10)
                        {
                            //10 sw.WriteLine(antHills[0].ants[i].CarriedObjectFullPathProperty);
                            if (line != "nullValue")
                            {
                                antPointer.CarriedObjectFullPathProperty = line;
                            }
                        }
                        else if (counter == 11)
                        {
                            //11 sw.WriteLine(antHills[0].ants[i].CarriedObjectLocationProperty);
                            if (line != "nullValue")
                            {
                                antPointer.CarriedObjectLocationProperty = line;
                            }
                        }
                        else if (counter == 12)
                        {
                            //12 sw.WriteLine(antHills[0].ants[i].CarryAmountProperty);
                            int.TryParse(line, out temp);
                            antPointer.CarryAmountProperty = temp;

                        }
                        else if (counter == 13)
                        {
                            //13 sw.WriteLine(antHills[0].ants[i].CarryingProperty);

                            antPointer.CarryingProperty = (Carrying)Enum.Parse(typeof(Carrying), line);

                        }
                        else if (counter == 14)
                        {
                            //14 sw.WriteLine(antHills[0].ants[i].ColonyIDProperty);
                            int.TryParse(line, out temp);
                            antPointer.ColonyIDProperty = temp;

                        }
                        else if (counter == 15)
                        {
                            //15 sw.WriteLine(antHills[0].ants[i].DestinationProperty);
                            antPointer.DestinationProperty = line;

                        }
                        else if (counter == 16)
                        {
                            //16 sw.WriteLine(antHills[0].ants[i].InNestProperty);
                            bool.TryParse(line, out tempBool);
                            antPointer.InNestProperty = tempBool;

                        }
                        else if (counter == 17)
                        {
                            // 17 sw.WriteLine(antHills[0].ants[i].NewThroneRoomProperty);
                            bool.TryParse(line, out tempBool);
                            antPointer.NewThroneRoomProperty = tempBool;

                        }
                        else if (counter == 18)
                        {
                            //18 sw.WriteLine(antHills[0].ants[i].PheromoneProperty);

                            antPointer.PheromoneProperty = (PheromoneEnum)Enum.Parse(typeof(PheromoneEnum), line);

                        }
                        else if (counter == 19)
                        {
                            //19 sw.WriteLine(antHills[0].ants[i].PreviousLocationProperty);
                            antPointer.PreviousLocationProperty = line;

                        }
                        else if (counter == 20)
                        {
                            //20 sw.WriteLine(antHills[0].ants[i].StateProperty);
                            antPointer.StateProperty = (State)Enum.Parse(typeof(State), line);

                        }
                        else if (counter == 21)
                        {
                            //21 sw.WriteLine(antHills[0].ants[i].StepCountProperty);
                            int.TryParse(line, out temp);
                            antPointer.StepCountProperty = temp;

                            antPointer.MyAnthillProperty = antHills[0];
                            antHills[0].ants[antPointer.IDProperty] = antPointer;

                            txtOutput.Text += Environment.NewLine + "Ant" + antPointer.ColonyIDProperty.ToString("D2") + "_" + antPointer.IDProperty.ToString("D4") + " Loaded";
                        }

                        //add ant to dictionary.
                        //set anthill pointer to anthill[0]
                        //

                    }

                    txtOutput.Text += Environment.NewLine + "LOAD COMPLETE";
                    sr.Close();
                }

            }
        }