public LinkedL(int x, int y, double rdb, LinkedL entity) { PARENT = new Entity(x, y, rdb); LINK = entity; PARENT.extraSize = (int)entity.PARENT.extraSize / 3; Init(); }
private LinkedL FindByIndex(int index) { LinkedL tmp = null; tmp = ents.ElementAt(index); return(tmp); }
private LinkedL FindByID(int id) { LinkedL index = null; foreach (LinkedL ent in ents) { if (ent.linkID == id) { index = ent; } } return(index); }
public LinkedL Oldest() { LinkedL[] result = new LinkedL[ents.Count]; ents.CopyTo(result); LinkedL tmp = result.FirstOrDefault(); foreach (LinkedL ent in result) { if (ent.Depth() > tmp.Depth()) { tmp = ent; } } return(tmp); }
private bool KillByID(int id) { bool result = false; LinkedL index = FindByID(id); result = ents.Contains(index) ? true : false; ents.Remove(index); string message = index.linkID + " is no more. It had " + (index.Depth() - 1) + " children"; Console.WriteLine(message); if (!logger.busy && log) { logger.LogMessage(message, "kill " + id, Form1.runHashCode); } return(result); }
// // Summary: // Gets the number of elements contained in the Current Linked List. // // Returns: // The number of elements contained in the Current Linked List. public int Depth() { int counter = 1; LinkedL tmp = LINK; if (tmp != null) { counter++; while (tmp.HasNext()) { tmp = tmp.GetNext(); counter++; } } return(counter); }
// // Summary: // Gets the list of elements contained in the Current Linked List. // // Returns: // The list of elements contained in the Current Linked List. public string[] PreviousList() { string[] list = new string[this.Depth()]; int counter = 0; LinkedL tmp = LINK; list[counter] = (this.linkID.ToString().PadLeft(8, ' ')); if (tmp != null) { counter++; list[counter] = (tmp.linkID.ToString().PadLeft(8, ' ')); while (tmp.HasNext()) { counter++; tmp = tmp.GetNext(); list[counter] = (tmp.linkID.ToString().PadLeft(8, ' ')); } } return(list); }
private bool KillByIndex(int index) { bool result = false; try { LinkedL ent = ents.ElementAt(index); result = ents.Contains(ent) ? true : false; ents.Remove(ent); string message = ent.linkID + " is no more. It had " + (ent.Depth() - 1) + " children"; Console.WriteLine(message); if (!logger.busy && log) { logger.LogMessage(message, "kill " + index, Form1.runHashCode); } } catch (Exception e) { result = false; } return(result); }
private void Show(string input, string value) { string message = ""; if (Regex.IsMatch(input, "^\\d+$")) { int max = ents.Count - 1; int val = Convert.ToInt32(input); val = val > max ? max : val; LinkedL tmp = FindByID(val); if (tmp == null) { tmp = FindByIndex(val); } if (tmp != null) { message = tmp.PARENT.EntStat() + " " + string.Join(" : ", tmp.PreviousList()); Console.WriteLine(message); Console.WriteLine("maxAge: " + tmp.PARENT.maxAge); Console.WriteLine("entCnt: " + tmp.PARENT.entCnt); Console.WriteLine("entRep: " + tmp.PARENT.entRep); Console.WriteLine("hungry: " + tmp.PARENT.hungry.ToString()); } } else { switch (input) { case "count": Console.SetCursorPosition(20, Console.CursorTop - 1); message = ents.Count + ""; Console.WriteLine(message); break; case "food": Console.SetCursorPosition(20, Console.CursorTop - 1); message = chrgs.Count + ""; Console.WriteLine(message); break; case "size": Console.SetCursorPosition(20, Console.CursorTop - 1); message = WIDTH + "x" + HEIGHT; Console.WriteLine(message); break; case "ents": Console.SetCursorPosition(2, Console.CursorTop); Console.Write("Index"); Console.SetCursorPosition(10, Console.CursorTop); Console.WriteLine("ID"); List <LinkedL> temps = new List <LinkedL>(); temps = ents.Take(ents.Count).ToList(); foreach (LinkedL ent in temps) { Console.SetCursorPosition(2, Console.CursorTop); Console.Write(ents.IndexOf(ent)); Console.SetCursorPosition(10, Console.CursorTop); Console.WriteLine(ent.linkID); } temps.Clear(); break; } } if (!logger.busy && log) { logger.LogMessage(message, "show " + input + " " + value, Form1.runHashCode); } }
public void AddLink(LinkedL enitity) { LINK = enitity; }
public LinkedL(LinkedL entity) { PARENT = new Entity(); LINK = entity; Init(); }