private void UpdateInstructions() { #if XBOX Thread.CurrentThread.SetProcessorAffinity(new int[] { currentCore++ }); #endif updating = true; if (Me.IsAlive) { LetsGo = Node.Handle.BuildPath(new Point((int)Math.Round(Me.X), (int)Math.Round(Me.Y)), ElementTypes.PacPlayer, Previous); } else { LetsGo = Node.Handle.BuildPath(new Point((int)Math.Round(Me.X), (int)Math.Round(Me.Y)), ElementTypes.GhostSpawn, Previous); } updating = false; }
private void BuildPath(InstructionSet IS, ElementTypes Type, Node Start) { //AlreadySearched.Add(this); //Random rnd = new Random(); //for (int i = IS.Last.Paths.Count; i > 1; i--) //{ // int pos = rnd.Next(i); // var x = IS.Last.Paths[i - 1]; // IS.Last.Paths[i - 1] = IS.Last.Paths[pos]; // IS.Last.Paths[pos] = x; //} //for (int i = 0; i < IS.Last.Paths.Count; i++ ) //{ // Path Path = IS.Last.Paths[i]; // if (Path.ContainsType(Type, Board) && (Shortest == null || Shortest.distance > IS.distance)) // { // Shortest = IS.AddPath(Path); // continue; // } // if (AlreadySearched.Contains(Path.End)) // { // continue; // } // Path.End.BuildPath(IS.AddPath(Path), Type); //} //AlreadySearched.Remove(this); Queue <Node> State = new Queue <Node>(); List <Node> Traveled = new List <Node>(); Queue <InstructionSet> Instructions = new Queue <InstructionSet>(); Traveled.Add(Start); State.Enqueue(Start); Instructions.Enqueue(IS); while (State.Count > 0) { Node T = State.Dequeue(); InstructionSet How = Instructions.Dequeue(); foreach (Path P in T.Paths) { if (P.ContainsType(Type, Board)) { InstructionSet Found = How.AddPath(P); if (Shortest == null || Found.distance < Shortest.distance) { Shortest = Found; } continue; } Node N = P.End; if (!Traveled.Contains(N)) { Traveled.Add(N); State.Enqueue(N); Instructions.Enqueue(How.AddPath(P)); } } } }