protected void UpdateFileName() { String newName = @"\" + TypeProperty + "_" + ColonyIDProperty.ToString("D2") + "_" + IDProperty.ToString("D4") + "_" + StateProperty + ".ant"; System.IO.File.Move(FullPathProperty, LocationProperty + newName); FullPathProperty = (LocationProperty + newName); }
public Larvae(int id, int colonyID, String location, bool loaded = false) : base(1000, 0, id, colonyID, 0, location, AntType.Larvae) { this.StateProperty = State.Standby; //delete old egg from colony array //might be a usefull find function. this.LocationProperty = location; this.FullPathProperty = LocationProperty + @"\" + TypeProperty + "_" + ColonyIDProperty.ToString("D2") + "_" + IDProperty.ToString("D4") + "_" + StateProperty + ".ant"; if (!File.Exists(FullPathProperty) && loaded == false) { // Create a file to write to. using (StreamWriter sw = File.CreateText(FullPathProperty)) { sw.WriteLine("Type:" + this.TypeProperty); sw.WriteLine("Health:" + this.HealthProperty); sw.Close(); } } for (int a = 0; a < AntFarmForm.antHills[this.ColonyIDProperty].ants.Count; a++) { if (MyAnthillProperty.ants[a] != null && MyAnthillProperty.ants[a].IDProperty == id && MyAnthillProperty.ants[a].TypeProperty == AntType.Egg) { MyAnthillProperty.ants[a] = this; } } }
protected void SearchForLocalPheromones(String pheromoneType) { localPheromonePath = ""; if (File.Exists(LocationProperty + @"\" + pheromoneType + "_" + ColonyIDProperty.ToString("D2") + ".phe"))//File.Exists(folders[i] + pheromoneType + ".phe") { //add location to list localPheromonePath = LocationProperty + @"\" + pheromoneType + "_" + ColonyIDProperty.ToString("D2") + ".phe"; } }
protected void SearchForPheromones(String pheromoneType) { pheromoneLocations = new List <string>(); //get string array of directory paths. string[] folders; string directoryName = Path.GetFileName(Path.GetDirectoryName(FullPathProperty)); String parentPath = ""; parentPath = new FileInfo(LocationProperty).Directory.FullName; folders = Directory.GetDirectories(LocationProperty); //get directory path of previous folder. If the folder being checked is that folder, dont include in the list. if (folders.Length != 0) { for (int i = 0; i < folders.Length; i++) { if (folders[i] != PreviousLocationProperty) { if (!File.Exists(folders[i] + @"\DoNotEnter.phe")) //the the user placed "DoNotEnter" Pheromone file exists in a folder, the ant will refuse to enter it. { if (i <= folders.Length && File.Exists(folders[i] + @"\" + pheromoneType + "_" + ColonyIDProperty.ToString("D2") + ".phe")) //File.Exists(folders[i] + pheromoneType + ".phe") { //add location to list pheromoneLocations.Add(folders[i] + @"\" + pheromoneType + "_" + ColonyIDProperty.ToString("D2") + ".phe"); } } } } } if (!File.Exists(parentPath + @"\DoNotEnter.phe")) //if the user placed "DoNotEnter" Pheromone file exists in a folder, the ant will refuse to enter it. { if (File.Exists(parentPath + @"\" + pheromoneType + "_" + ColonyIDProperty.ToString("D2") + ".phe") && parentPath != PreviousLocationProperty) //File.Exists(folders[i] + pheromoneType + ".phe") { //This is a fail safe to prevent ants from leaving the nest in search of inNest tasks without explicitly being told. if (!InNestProperty) { //add location to list pheromoneLocations.Add(parentPath + @"\" + pheromoneType + "_" + ColonyIDProperty.ToString("D2") + ".phe"); } else { if (directoryName != "Anthill_" + ColonyIDProperty.ToString("D2")) { //add location to list pheromoneLocations.Add(parentPath + @"\" + pheromoneType + "_" + ColonyIDProperty.ToString("D2") + ".phe"); } } } } }
protected bool SearchForLocalFoodStash() { if (File.Exists(LocationProperty + @"\FoodStash_" + ColonyIDProperty.ToString("D2") + ".txt")) { return(true); } else { return(false); } }
protected bool SearchForLocalNest() { if (Directory.Exists(LocationProperty + @"\Anthill_" + ColonyIDProperty.ToString("D2"))) { return(true); } else { return(false); } }
public Egg(int id, int colonyID, String location, bool loaded = false) : base(1000, 0, id, colonyID, 0, location, AntType.Egg) { this.TypeProperty = AntType.Egg; this.StateProperty = State.Standby; //create file this.LocationProperty = location; this.FullPathProperty = LocationProperty + @"\" + TypeProperty + "_" + ColonyIDProperty.ToString("D2") + "_" + IDProperty.ToString("D4") + "_" + StateProperty + ".ant"; if (!File.Exists(FullPathProperty) && loaded == false) { // Create a file to write to. using (StreamWriter sw = File.CreateText(FullPathProperty)) { sw.WriteLine("Type:" + this.TypeProperty); sw.WriteLine("Health:" + this.HealthProperty); sw.Close(); } } }
public Queen(int id, int colonyID, String location, bool loaded = false) : base(QUEEN_START_HEALTH, QUEEN_START_HUNGER, id, colonyID, 0, location, AntType.Queen) { TypeProperty = AntType.Queen; CarryingProperty = Carrying.Food; CarryAmountProperty = 10000; LocationProperty = location; FullPathProperty = LocationProperty + @"\" + TypeProperty + "_" + ColonyIDProperty.ToString("D2") + "_" + IDProperty.ToString("D4") + "_" + StateProperty + ".ant"; StateProperty = State.Standby; if (!File.Exists(FullPathProperty) && loaded == false) { // Create a file to write to. using (StreamWriter sw = File.CreateText(FullPathProperty)) { sw.WriteLine("Type:" + this.TypeProperty); sw.WriteLine("Health:" + this.HealthProperty); sw.WriteLine("Hunger:" + this.HungerProperty); sw.Close(); } } }
protected String GetRandomPath() { //for some reason this is returning blank String path = ""; Random rnd = new Random(); int index = 0; List <string> folderList = new List <string>(); string[] folders; string directoryName = Path.GetFileName(Path.GetDirectoryName(FullPathProperty)); String parentPath = ""; parentPath = new FileInfo(LocationProperty).Directory.FullName; folders = Directory.GetDirectories(LocationProperty); //If there are folders at the current directory, add them to the list of possible Destinations if (folders.Length != 0) { for (int i = 0; i < folders.Length; i++) { //if the folder is not the previous location of the ant if (folders[i] != PreviousLocationProperty) { //if the do not enter phermone does not exist at the potential destination if (!File.Exists(folders[i] + @"\DoNotEnter.phe")) //the the user placed "DoNotEnter" Pheromone file exists in a folder, the ant will refuse to enter it. { //if the ant is not in the nest, it has to check if one of the folders is its anthill if (InNestProperty == false) { if (folders[i] != (LocationProperty + "Anthill_" + ColonyIDProperty.ToString("D2"))) { //if the folder in question is not the anthill folderList.Add(folders[i]); } } else { //the ant is in the nest. folderList.Add(folders[i]); } } } } } //the goal of this logic to to determine why the parent path cannot be added to the list //if the ant is within the nest if (InNestProperty) { //make sure it is not leaving the nest if (directoryName != "Anthill_" + ColonyIDProperty.ToString("D2")) { if (parentPath != PreviousLocationProperty) { //the parent path is not the previous location if (!File.Exists(parentPath + @"\DoNotEnter.phe")) //check if the the user placed "DoNotEnter" Pheromone file exists in a folder { //add folderList.Add(parentPath); } } else { //if the ant just came from the parent, check to see if there are other folders to enter if (folderList.Count == 0) { //if not, then the ant is at a dead end and should add the parent path //check if there is not DONOTENTER if (!File.Exists(parentPath + @"\DoNotEnter.phe")) //check if the the user placed "DoNotEnter" Pheromone file exists in a folder { //add folderList.Add(parentPath); } } } } } else { if (parentPath != PreviousLocationProperty) { //the parent path is not the previous location if (!File.Exists(parentPath + @"\DoNotEnter.phe")) //check if the the user placed "DoNotEnter" Pheromone file exists in a folder { //add folderList.Add(parentPath); } } else { //if the ant just came from the parent, check to see if there are other folders to enter if (folderList.Count == 0) { //if not, then the ant is at a dead end and should add the parent path //check if there is not DONOTENTER if (!File.Exists(parentPath + @"\DoNotEnter.phe")) //check if the the user placed "DoNotEnter" Pheromone file exists in a folder { //add folderList.Add(parentPath); } } } } //Attempt to choose a random path from the list try { index = rnd.Next(folderList.Count); path = folderList[index]; } catch (ArgumentException err) { //if it fails, then somehow no paths were properly added. I NEED TO FIX THIS //this string will be read by the move function path = "nopath"; } return(path); }
override public void Move()// The ant finds a suitable folder to enter, sets it to 'destination' then moves itself there. { //not used by queen unless being carried by another ant. if (DestinationProperty != "") { //Set current location to previouslocation property. try { PreviousLocationProperty = LocationProperty; File.Move(FullPathProperty, DestinationProperty + @"\" + TypeProperty + "_" + ColonyIDProperty.ToString("D2") + "_" + IDProperty.ToString("D4") + "_" + StateProperty + ".ant"); LocationProperty = DestinationProperty; FullPathProperty = DestinationProperty + @"\" + TypeProperty + "_" + ColonyIDProperty.ToString("D2") + "_" + IDProperty.ToString("D4") + "_" + StateProperty + ".ant"; } catch (UnauthorizedAccessException err) { } } }