/// <returns>True if val == (True OR Undefined)</returns> public static bool IsNotFalse(this TriBool val) { return(val != TriBool.False); }
/// <summary> /// Method that switfly finds the best path from start to end. Doesn't reverse outcome /// </summary> /// <returns>The end breadcrump where each next is a step back)</returns> private static BreadCrumb FindPathReversed(Level world, BotMap level, Point3D start, Point3D end) { MinHeap <BreadCrumb> openList = new MinHeap <BreadCrumb>(256); BreadCrumb[, ,] brWorld = new BreadCrumb[world.Size.x, world.Size.y, world.Size.z]; BreadCrumb node; Point3D tmp; int cost; int diff; BreadCrumb current = new BreadCrumb(start); current.cost = 0; BreadCrumb finish = new BreadCrumb(end); try { brWorld[current.position.X, current.position.Y, current.position.Z] = current; } catch { return(current); } openList.Add(current); while (openList.Count > 0) { //Find best item and switch it to the 'closedList' current = openList.ExtractFirst(); current.onClosedList = true; //Find neighbours for (int i = 0; i < surrounding.Length; i++) { tmp = current.position + surrounding[i]; if ((tmp.X <= -1 || tmp.Y <= -1 || tmp.Z <= -1) || (tmp.X >= level.Size.x || tmp.Y >= level.Size.y || tmp.Z >= level.Size.z)) { break; } TriBool block = false; try { block = level.AirMap[tmp.X, tmp.Z, tmp.Y]; //Check if block is air } catch { } if (block != TriBool.Unknown) { //Check if we've already examined a neighbour, if not create a new node for it. if (brWorld[tmp.X, tmp.Y, tmp.Z] == null) { node = new BreadCrumb(tmp); brWorld[tmp.X, tmp.Y, tmp.Z] = node; } else { node = brWorld[tmp.X, tmp.Y, tmp.Z]; } //If the node is not on the 'closedList' check it's new score, keep the best if (!node.onClosedList) { diff = 0; if (current.position.X != node.position.X) { diff += 1; } if (current.position.Y != node.position.Y) { diff += 1; } if (current.position.Z != node.position.Z) { diff += 1; } if (block == false) //Solid but breakable, allows bot to go through solid areas { diff += 50; } cost = current.cost + diff + node.position.GetDistanceSquared(end); if (cost < node.cost) { node.cost = cost; node.next = current; } //If the node wasn't on the openList yet, add it if (!node.onOpenList) { //Check to see if we're done if (node.Equals(finish)) { node.next = current; return(node); } node.onOpenList = true; openList.Add(node); } } } } } return(null); //no path found }
public static bool IsFalse(this TriBool val) { return(val == TriBool.False); }
/// <returns>True if val == (False OR Undefined)</returns> public static bool IsNotTrue(this TriBool val) { return(val != TriBool.True); }
public static bool IsUndefined(this TriBool val) { return(val == TriBool.Undefined); }
public static void Load(string path) { if (!File.Exists(path)) { throw new FileNotFoundException(path + " not found."); } Program.program.Clear(); Program.encoded_files.Clear(); Program.written = new List <KeyValuePair <char, ConsoleColor> >(); char key = '\x0'; char ch1 = '\x0'; TriBool triBool = TriBool.False; bool flag1 = false; string s = ""; bool flag2 = false; bool flag3 = false; MplPeriod mplPeriod = MplPeriod.LoadInstruction; List <string> list1 = new List <string>(); string input = File.ReadAllText(path); Program.ToWords(input, '\n', (ICollection <string>)list1); foreach (string str1 in list1) { if (str1 == "") { if (!flag1) { ++mplPeriod; } flag1 = true; if (mplPeriod == MplPeriod.Instance && (!Program.auto)) { Console.Clear(); foreach (KeyValuePair <char, ConsoleColor> keyValuePair in Program.written) { Console.ForegroundColor = keyValuePair.Value; Console.Write(keyValuePair.Key); } Console.ResetColor(); } } else { flag1 = false; if (mplPeriod == MplPeriod.LoadInstruction) { Program.program.Add(Program.LoadInstruction(str1)); } else if (mplPeriod == MplPeriod.Written) { foreach (char ch2 in str1) { if (triBool == TriBool.False) { key = ch2; } else if (triBool == TriBool.Null) { ch1 = ch2; } else { Program.written.Add(new KeyValuePair <char, ConsoleColor>(key, (ConsoleColor)Convert.ToInt32(ch1.ToString() + ch2.ToString()))); } if (triBool == TriBool.True) { triBool = TriBool.False; } else { ++triBool; } } key = '\n'; triBool = TriBool.Null; } else if (mplPeriod == MplPeriod.Password) { Random random = new Random(); Console.Clear(); bool flag4 = true; while (flag4) { Console.WriteLine("What's the password?"); string str2 = Console.ReadLine(); Thread.Sleep(random.Next(1000)); int result; if (!int.TryParse(str1, out result) && str2 == str1) { flag2 = true; flag4 = false; } if (str2.GetHashCode() == result) { flag2 = true; flag4 = false; } else if (Program.master_mode) { Console.WriteLine("Would you like to reconstruct and remove password?"); string str3; do { str3 = Console.ReadLine(); if (str3.ToLower() == "yes") { Program.password = 0; flag4 = false; } }while (str3.ToLower() != "yes" && str3.ToLower() != "no"); } } Program.password = int.Parse(str1); Console.Clear(); Program.WriteWritten(); } else if (mplPeriod == MplPeriod.MagicNumber) { flag3 = true; s = str1; } else if (mplPeriod == MplPeriod.LoadEncodedFiles) { List <string> list2 = new List <string>(); Program.ToWords(str1, 'ﻃ', (ICollection <string>)list2); } else if (mplPeriod == MplPeriod.Instance) { Program.readend = Convert.ToBoolean(str1); } } } if (flag2) { if (input.Length - 3 - Convert.ToString(Program.password).Length - s.Length != int.Parse(s)) { flag3 = false; } } else if (input.Length - s.Length - 1 != int.Parse(s)) { flag3 = false; } if (flag3) { return; } if (!Program.master_mode) { Console.Clear(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("This file has been hacked or corrupt."); File.Delete(path); } else { Console.Clear(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("This file has been hacked or corrupt."); string str; do { Console.WriteLine("Would you like to reconstruct the file?"); str = Console.ReadLine(); if (str.ToLower() == "yes") { Program.Save(new StreamWriter(path)); } else { File.Delete(path); } }while (str.ToLower() != "yes" && str.ToLower() != "no"); Console.ResetColor(); } Console.ReadKey(); }
/// <summary> /// Evaluates whether a bool value is null. /// </summary> /// <param name="value">The TriBool value to evaluate</param> /// <returns>A bool indicating whether the value is null</returns> public static bool IsNull(TriBool value) { if (value == TriBool.Null) { return true; } else { return false; } }