-
Notifications
You must be signed in to change notification settings - Fork 5
/
INode.cs
114 lines (97 loc) · 3.81 KB
/
INode.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
astar-1.0.cs may be freely distributed under the MIT license.
Copyright (c) 2013 Josh Baldwin https://github.com/jbaldwin/astar.cs
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
using System.Collections.Generic;
namespace AStar
{
/// <summary>
/// The A* algorithm takes a starting node and a goal node and searchings from
/// start to the goal.
///
/// The nodes can be setup in a graph ahead of running the algorithm or the children
/// nodes can be generated on the fly when the A* algorithm requests the Children property.
///
/// See the square puzzle implementation to see the children being generated on the fly instead
/// of the classical image/graph search with walls.
/// </summary>
public interface INode
{
/// <summary>
/// Determines if this node is on the open list.
/// </summary>
bool IsOpenList(IEnumerable<INode> openList);
/// <summary>
/// Sets this node to be on the open list.
/// </summary>
void SetOpenList(bool value);
/// <summary>
/// Determines if this node is on the closed list.
/// </summary>
bool IsClosedList(IEnumerable<INode> closedList);
/// <summary>
/// Sets this node to be on the open list.
/// </summary>
void SetClosedList(bool value);
/// <summary>
/// Gets the total cost for this node.
/// f = g + h
/// TotalCost = MovementCost + EstimatedCost
/// </summary>
int TotalCost { get; }
/// <summary>
/// Gets the movement cost for this node.
/// This is the movement cost from this node to the starting node, or g.
/// </summary>
int MovementCost { get; }
/// <summary>
/// Gets the estimated cost for this node.
/// This is the heuristic from this node to the goal node, or h.
/// </summary>
int EstimatedCost { get; }
/// <summary>
/// Sets the movement cost for the current node, or g.
/// </summary>
/// <param name="parent">Parent node, for access to the parents movement cost.</param>
void SetMovementCost(INode parent);
/// <summary>
/// Sets the estimated cost for the current node, or h.
/// </summary>
/// <param name="goal">Goal node, for acces to the goals position.</param>
void SetEstimatedCost(INode goal);
/// <summary>
/// Gets or sets the parent node to this node.
/// </summary>
INode Parent { get; set; }
/// <summary>
/// Gets this node's children.
/// </summary>
/// <remarks>The children can be setup in a graph before starting the
/// A* algorithm or they can be dynamically generated the first time
/// the A* algorithm calls this property.</remarks>
IEnumerable<INode> Children { get; }
/// <summary>
/// Returns true if this node is the goal, false if it is not the goal.
/// </summary>
/// <param name="goal">The goal node to compare this node against.</param>
/// <returns>True if this node is the goal, false if it s not the goal.</returns>
bool IsGoal(INode goal);
}
}