namespace Holo.Virtual.Rooms.Pathfinding { using System; using System.Collections.ObjectModel; public class mapNode : IComparable { private double _esToGoal; internal double Cost; private mapNode Goal; internal mapNode Parent; internal mapNode Start; internal int X; internal int Y; public mapNode(int X, int Y, double Cost, mapNode Parent, mapNode Goal, mapNode Start) { this.Parent = Parent; this.Start = Start; this.Goal = Goal; this.X = X; this.Y = Y; this.Cost = Cost; } private mapNode createNode(int X, int Y) { int dx1 = this.X - this.Goal.X; int dy1 = this.X - this.Goal.Y; int dx2 = this.Start.X - this.Goal.X; int dy2 = this.Start.Y - this.Goal.Y; double Tie = Math.Abs((int) ((dx1 * dy2) - (dx2 * dy1))) * 0.005; return new mapNode(X, Y, this.Cost + Tie, this, this.Goal, this.Start); } internal Collection Successors(DenDribbelaerPathfinder Pathfinder) { Collection tmp = new Collection(); if (Pathfinder.Passable(this.X, this.Y, this.X - 1, this.Y)) { tmp.Add(this.createNode(this.X - 1, this.Y)); } if (Pathfinder.Passable(this.X, this.Y, this.X + 1, this.Y)) { tmp.Add(this.createNode(this.X + 1, this.Y)); } if (Pathfinder.Passable(this.X, this.Y, this.X, this.Y + 1)) { tmp.Add(this.createNode(this.X, this.Y + 1)); } if (Pathfinder.Passable(this.X, this.Y, this.X, this.Y - 1)) { tmp.Add(this.createNode(this.X, this.Y - 1)); } if (Pathfinder.Passable(this.X, this.Y, this.X - 1, this.Y + 1)) { tmp.Add(this.createNode(this.X - 1, this.Y + 1)); } if (Pathfinder.Passable(this.X, this.Y, this.X - 1, this.Y - 1)) { tmp.Add(this.createNode(this.X - 1, this.Y - 1)); } if (Pathfinder.Passable(this.X, this.Y, this.X, this.Y + 1)) { tmp.Add(this.createNode(this.X, this.Y + 1)); } if (Pathfinder.Passable(this.X, this.Y, this.X, this.Y - 1)) { tmp.Add(this.createNode(this.X, this.Y - 1)); } if (Pathfinder.Passable(this.X, this.Y, this.X + 1, this.Y + 1)) { tmp.Add(this.createNode(this.X + 1, this.Y + 1)); } if (Pathfinder.Passable(this.X, this.Y, this.X + 1, this.Y - 1)) { tmp.Add(this.createNode(this.X + 1, this.Y - 1)); } return tmp; } int IComparable.CompareTo(object obj) { return -this.totalCost.CompareTo(((mapNode) obj).totalCost); } internal double goalEstimate { get { if (this.Goal == null) { return 0.0; } int a1 = 2 * this.X; int a2 = ((2 * this.Y) + (this.X % 2)) - this.X; int a3 = ((-2 * this.Y) - (this.X % 2)) - this.X; int b1 = 2 * this.Goal.X; int b2 = ((2 * this.Goal.Y) + (this.Goal.X % 2)) - this.Goal.X; int b3 = ((-2 * this.Goal.Y) - (this.Goal.X % 2)) - this.Goal.X; return Math.Max(Math.Abs((int) (a1 - b1)), Math.Max(Math.Abs((int) (a2 - b2)), Math.Abs((int) (a3 - b3)))); } set { this._esToGoal = value; } } internal double totalCost { get { return (this.Cost + this.goalEstimate); } } } }