This repository has been archived by the owner on Jan 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode.cs
189 lines (171 loc) · 5.07 KB
/
Node.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using BibliotecaComun;
using System.Collections;
namespace SolucionAlumno
{
/**
* Clase que representa un nodo en el mapa.
*/
class Node : IComparable
{
/**
* Nodo padre
*/
private Node parent;
/**
* punto en el mapa al que pertenece dicho nodo
*/
private Point point;
/**
* Costo en dicho nodo
*/
private Costo costo;
/**
* Valor de la funcion f(x) Utilizada para el algoritmo A*, f = g + h
*/
private int fValue;
/**
* Valor de la funcion g(x) Utilizada para el algoritmo A*, Representa el costo por moverse a dicha posicion.
*/
private int gValue;
/**
* Valor de la funcion f(x) Utilizada para el algoritmo A*, Representa el costo aproximado para llegar al destino.
*/
private int hValue;
/**
* Constructor por con costo y punto
* @param costo del nodo creado.
* @param point del nodo creado.
*/
public Node(Costo costo, Point point) {
this.costo = costo;
this.point = point;
}
/**
* Calcula el costo de movimiento para el Nodo
*/
public void calculateCost(Point start, Node previousPoint, Point goal, CostCalculator costCalculator) {
this.gValue = costCalculator.move(previousPoint, this);
this.hValue = costCalculator.aproximateMove(start, this.Point, goal);
fValue = gValue + hValue;
}
/**
* Obtiene la lista de Nodos adyasentes en el mapa.
*/
public List<Node> getAdjacent(MapaDeCostos mapaDeCostos, Hashtable closeList, IPreProcesingZones zonasProhibidas)
{
List<Node> nodosAdyacentes = new List<Node>();
for (int x = this.Point.X - 1; x <= this.Point.X + 1; x++)
{
for (int y = this.Point.Y - 1; y <= this.Point.Y + 1; y++)
{
if (!((x == this.Point.X) && (y == this.Point.Y)))
{
Point point = new Point();
point.X = x;
point.Y = y;
if (mapaDeCostos.verificarPosicion(point))
{
Node nodoAdyacente = new Node(mapaDeCostos.getCostoPosicion(point), point);
if (nodoAdyacente.Costo.esTransitable() &&
!closeList.Contains(nodoAdyacente.GetHashCode()))
{
ZonaProhibida zonaProhibida = zonasProhibidas[nodoAdyacente.Point.X, nodoAdyacente.Point.Y];
if (zonaProhibida != null)// && mapaDeCostos.verificarZonaProhibida(nodoAdyacente.Point, zonaProhibida))
{
continue;
}
nodosAdyacentes.Add(nodoAdyacente);
}
}
}
}
}
return nodosAdyacentes;
}
/**
* Get y Set de parent
*/
public Node Parent
{
get { return parent; }
set { parent = value; }
}
/**
* Get y Set de point
*/
public Point Point
{
get { return point; }
set { point = value; }
}
/**
* Get y Set de costo
*/
public Costo Costo
{
get { return costo; }
set { costo = value; }
}
/**
* Get de fValue
*/
public int FValue
{
get { return fValue; }
//set { fValue = value; }
}
/**
* Get de gValue
*/
public int GValue
{
get { return gValue; }
//set { gValue = value; }
}
/**
* Get de hValue
*/
public int HValue
{
get { return hValue; }
//set { hValue = value; }
}
/**
* Implementacion de la IComparable.
*/
public int CompareTo(object obj) {
if (this.fValue < ((Node)obj).fValue) {
return -1;
} else if(this.fValue == ((Node)obj).fValue) {
return 0;
}
return 1;
}
/**
* Implementacion de Equals.
*/
public override bool Equals(object obj)
{
if (obj is Node)
{
return this.point.Equals(((Node) obj).Point);
}
return false;
}
/**
* Implementacion de GetHastCode.
*/
public override int GetHashCode()
{
return this.point.X << 10000 | this.point.Y;
}
public override string ToString()
{
return this.Point.ToString();
}
}
}