static void BuildAdjacencies(VaultNode vn, string originalPassword) { string adjacencyTest = GetMD5(string.Concat(originalPassword, vn.DirectionString)).Substring(0, 4); // Up 0 // Down 1 // Left 2 // Right 3 // UP TEST if (adjacencyTest[0] >= 98 && adjacencyTest[0] <= 102 && vn.Y < 3) { // up available // swap D/U for visible reflection (start node at 0,0 but will render right) var child = new VaultNode() { X = vn.X, Y = vn.Y + 1, LastDirection = "U" }; vn.AddChild(child); nodesToVisit.Enqueue(child); } // DOWN TEST if (adjacencyTest[1] >= 98 && adjacencyTest[1] <= 102 && vn.Y > 0) { // DOWN available // swap D/U for visible reflection (start node at 0,0 but will render right) var child = new VaultNode() { X = vn.X, Y = vn.Y - 1, LastDirection = "D" }; vn.AddChild(child); nodesToVisit.Enqueue(child); } // LEFT TEST if (adjacencyTest[2] >= 98 && adjacencyTest[2] <= 102 && vn.X > 0) { // LEFT available var child = new VaultNode() { X = vn.X - 1, Y = vn.Y, LastDirection = "L" }; vn.AddChild(child); nodesToVisit.Enqueue(child); } // RIGHT TEST if (adjacencyTest[3] >= 98 && adjacencyTest[3] <= 102 && vn.X < 3) { // RIGHT available var child = new VaultNode() { X = vn.X + 1, Y = vn.Y, LastDirection = "R" }; vn.AddChild(child); nodesToVisit.Enqueue(child); } }
static void Main(string[] args) { var input = "pgflpeqp"; VaultNode vn = new VaultNode(); vn.X = 0; vn.Y = 3; BuildAdjacencies(vn, input); WalkNodes(input); //BuildAdjacencies(nodesToVisit.Dequeue(), input); Console.WriteLine("Last Solution {0}. Length {1}", solutions.Peek(), solutions.Peek().Length); }
public VaultNode AddChild(VaultNode child) { this.Children.Enqueue(child); child.Parent = this; return(child); }
public VaultNode(VaultNode parent) { this.Parent = parent; this.Children = new Queue <VaultNode>(); }