-
Notifications
You must be signed in to change notification settings - Fork 0
/
PathNode.cs
62 lines (50 loc) · 1.44 KB
/
PathNode.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using UnityEngine;
public class PathNode : Node
{
protected Location dest;
public PathNode(PathNode parent, Location dest) : base(parent)
{
G = (parent == null) ? 0 : (parent.G + 1);
this.dest = dest;
}
// The heuristic of the Path node is the manhattan-distance
// from the current location to the target location.
public override double H
{
get
{
return CurLocation.DistanceTo(dest);
}
}
public override bool IsGoalState()
{
return CurLocation.Equals(dest);
}
public override Node ChildNode(Location loc)
{
PathNode n = new PathNode(this, dest)
{
CurLocation = loc,
Obstacles = Obstacles
};
return n;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
return false;
if (ReferenceEquals(this, obj))
return true;
if (obj.GetType() != this.GetType())
return false;
PathNode other = (PathNode)obj;
return !System.Object.ReferenceEquals(null, CurLocation)
&& CurLocation.Equals(other.CurLocation);
}
public override int GetHashCode()
{
int hash = 13;
hash = (hash * 7) + (!System.Object.ReferenceEquals(null, CurLocation) ? CurLocation.GetHashCode() : 0);
return hash;
}
}