Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ColdShot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
15박보승
ColdShot
Commits
7d1e5e5f
Commit
7d1e5e5f
authored
Jan 24, 2020
by
15박보승
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove Contains function from A*. Optimization completed.
parent
a0205e78
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
21 deletions
+28
-21
Pathfinding.unity
Assets/Scenes/Pathfinding.unity
+2
-2
PriorityQueue.cs
Assets/Scripts/Generals/PriorityQueue.cs
+10
-0
NodalPathfinding2D.cs
Assets/Scripts/NodalPathfinding/NodalPathfinding2D.cs
+16
-19
No files found.
Assets/Scenes/Pathfinding.unity
View file @
7d1e5e5f
...
@@ -261,13 +261,13 @@ MonoBehaviour:
...
@@ -261,13 +261,13 @@ MonoBehaviour:
bounds
:
bounds
:
m_Center
:
{
x
:
0
,
y
:
0
,
z
:
0
}
m_Center
:
{
x
:
0
,
y
:
0
,
z
:
0
}
m_Extent
:
{
x
:
10
,
y
:
10
,
z
:
0
}
m_Extent
:
{
x
:
10
,
y
:
10
,
z
:
0
}
pointInterval
:
0.
768
pointInterval
:
0.
614
agentRadius
:
0.1
agentRadius
:
0.1
blockMask
:
blockMask
:
serializedVersion
:
2
serializedVersion
:
2
m_Bits
:
256
m_Bits
:
256
isOptimizing
:
1
isOptimizing
:
1
complementLevel
:
10
complementLevel
:
8
enableGizmos
:
1
enableGizmos
:
1
---
!u!4
&178212235
---
!u!4
&178212235
Transform
:
Transform
:
...
...
Assets/Scripts/Generals/PriorityQueue.cs
View file @
7d1e5e5f
...
@@ -32,6 +32,11 @@ public class PriorityQueue<T>
...
@@ -32,6 +32,11 @@ public class PriorityQueue<T>
{
{
heap
.
HeapUpdated
(
item
);
heap
.
HeapUpdated
(
item
);
}
}
public
IEnumerator
<
T
>
GetEnumerator
()
{
return
heap
.
GetEnumerator
();
}
}
}
class
Heap
<
T
>
class
Heap
<
T
>
...
@@ -219,4 +224,9 @@ class Heap<T>
...
@@ -219,4 +224,9 @@ class Heap<T>
TryWithParent
(
Parent
(
index
));
TryWithParent
(
Parent
(
index
));
}
}
}
}
public
IEnumerator
<
T
>
GetEnumerator
()
{
return
list
.
GetEnumerator
();
}
}
}
\ No newline at end of file
Assets/Scripts/NodalPathfinding/NodalPathfinding2D.cs
View file @
7d1e5e5f
...
@@ -425,6 +425,7 @@ namespace BS
...
@@ -425,6 +425,7 @@ namespace BS
List
<
Node
>
closed
=
new
List
<
Node
>();
List
<
Node
>
closed
=
new
List
<
Node
>();
queue
.
Enqueue
(
start
);
queue
.
Enqueue
(
start
);
start
.
state
=
1
;
while
(
queue
.
Count
>
0
)
while
(
queue
.
Count
>
0
)
{
{
Node
cur
=
queue
.
Dequeue
();
Node
cur
=
queue
.
Dequeue
();
...
@@ -436,6 +437,7 @@ namespace BS
...
@@ -436,6 +437,7 @@ namespace BS
if
(
cur
.
gridPosition
==
goal
.
gridPosition
)
if
(
cur
.
gridPosition
==
goal
.
gridPosition
)
{
{
closed
.
Add
(
cur
);
closed
.
Add
(
cur
);
cur
.
state
=
-
1
;
break
;
break
;
}
}
...
@@ -443,8 +445,8 @@ namespace BS
...
@@ -443,8 +445,8 @@ namespace BS
foreach
(
var
adj
in
cur
.
adjacencies
)
foreach
(
var
adj
in
cur
.
adjacencies
)
{
{
Node
adjNode
=
nodes
[
adj
];
Node
adjNode
=
nodes
[
adj
];
bool
isOpened
=
queue
.
Contains
(
nodes
[
adj
])
;
bool
isOpened
=
nodes
[
adj
].
state
>
0
;
bool
isClosed
=
closed
.
Contains
(
nodes
[
adj
])
;
bool
isClosed
=
nodes
[
adj
].
state
<
0
;
if
(
isOpened
)
if
(
isOpened
)
{
{
...
@@ -462,10 +464,11 @@ namespace BS
...
@@ -462,10 +464,11 @@ namespace BS
adjNode
.
cost
=
cur
.
cost
+
Vector2
.
Distance
(
cur
.
worldPositon
,
adjNode
.
worldPositon
);
adjNode
.
cost
=
cur
.
cost
+
Vector2
.
Distance
(
cur
.
worldPositon
,
adjNode
.
worldPositon
);
adjNode
.
CalculateScore
(
to
);
adjNode
.
CalculateScore
(
to
);
queue
.
Enqueue
(
adjNode
);
queue
.
Enqueue
(
adjNode
);
adjNode
.
state
=
1
;
}
}
}
}
cur
.
state
=
-
1
;
closed
.
Add
(
cur
);
closed
.
Add
(
cur
);
}
}
...
@@ -492,14 +495,16 @@ namespace BS
...
@@ -492,14 +495,16 @@ namespace BS
{
{
path
.
Add
(
to
);
path
.
Add
(
to
);
}
}
/*
foreach(var
node in nodes.Values
)
foreach
(
var
close
in
closed
)
{
{
node.cost = 0;
close
.
state
=
0
;
node.parent = null;
node.score = 0;
}
}
*/
foreach
(
var
open
in
queue
)
{
open
.
state
=
0
;
}
return
path
;
return
path
;
}
}
...
@@ -632,15 +637,7 @@ namespace BS
...
@@ -632,15 +637,7 @@ namespace BS
cost
=
0
;
cost
=
0
;
score
=
0
;
score
=
0
;
parent
=
null
;
parent
=
null
;
}
state
=
0
;
public
Node
(
Node
node
,
Node
parent
,
float
cost
=
0
)
{
this
.
gridPosition
=
node
.
gridPosition
;
this
.
worldPositon
=
node
.
worldPositon
;
this
.
adjacencies
=
node
.
adjacencies
;
this
.
cost
=
cost
;
this
.
parent
=
parent
;
score
=
0
;
}
}
public
Vector2Int
gridPosition
;
public
Vector2Int
gridPosition
;
...
@@ -649,7 +646,7 @@ namespace BS
...
@@ -649,7 +646,7 @@ namespace BS
public
float
cost
;
public
float
cost
;
public
float
score
;
public
float
score
;
public
Node
parent
;
public
Node
parent
;
public
int
state
;
// -1 : closed, 1 : opened, 0 : neutral
public
void
CalculateScore
(
Vector3
destination
)
public
void
CalculateScore
(
Vector3
destination
)
{
{
score
=
cost
+
GetHeuristic
(
destination
);
score
=
cost
+
GetHeuristic
(
destination
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment