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
df56c648
Commit
df56c648
authored
Jan 20, 2020
by
15박보승
Committed by
18류지석
Jan 20, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implementing PriorityQueue for A*
parent
c7f409a0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
101 additions
and
8 deletions
+101
-8
Generals.meta
Assets/Scripts/Generals.meta
+8
-0
PriorityQueue.cs
Assets/Scripts/Generals/PriorityQueue.cs
+78
-0
PriorityQueue.cs.meta
Assets/Scripts/Generals/PriorityQueue.cs.meta
+11
-0
NodalPathfinding2D.cs
Assets/Scripts/NodalPathfinding/NodalPathfinding2D.cs
+4
-8
No files found.
Assets/Scripts/Generals.meta
0 → 100644
View file @
df56c648
fileFormatVersion: 2
guid: 6b7073261dd8e5d4284df86af077644d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
Assets/Scripts/Generals/PriorityQueue.cs
0 → 100644
View file @
df56c648
using
System.Collections
;
using
System.Collections.Generic
;
public
enum
SortMode
{
ASCENDING
,
DECENDING
}
public
class
PriorityQueue
<
T
>
{
private
List
<
T
>
heap
=
new
List
<
T
>();
private
IComparer
<
T
>
comparer
;
private
SortMode
sortMode
;
public
PriorityQueue
(
IComparer
<
T
>
comparer
,
SortMode
sortMode
=
SortMode
.
ASCENDING
)
{
this
.
comparer
=
comparer
;
this
.
sortMode
=
sortMode
;
}
public
void
Enqueue
(
T
item
)
{
InsertHeap
(
item
);
}
public
T
Dequeue
()
{
T
first
=
heap
[
0
];
heap
[
0
]
=
heap
[
heap
.
Count
-
1
];
heap
.
RemoveAt
(
heap
.
Count
-
1
);
Heapify
();
return
first
;
}
private
void
InsertHeap
(
T
item
)
{
heap
.
Add
(
item
);
int
index
=
heap
.
Count
-
1
;
while
(
sortMode
==
SortMode
.
ASCENDING
?
comparer
.
Compare
(
heap
[
index
],
heap
[
index
/
2
])
<=
0
:
comparer
.
Compare
(
heap
[
index
],
heap
[
index
/
2
])
>
0
)
{
T
tmp
=
heap
[
index
];
heap
[
index
]
=
heap
[
index
/
2
];
heap
[
index
/
2
]
=
tmp
;
index
/=
2
;
}
}
private
void
Heapify
()
{
int
index
=
0
;
while
(
true
)
{
int
left
=
2
*
index
+
1
;
int
right
=
2
*
index
+
2
;
int
target
=
index
;
if
(
left
<
heap
.
Count
&&
(
sortMode
==
SortMode
.
ASCENDING
?
comparer
.
Compare
(
heap
[
index
],
heap
[
left
])
<=
0
:
comparer
.
Compare
(
heap
[
index
],
heap
[
left
])
>
0
))
{
target
=
left
;
}
if
(
right
<
heap
.
Count
&&
(
sortMode
==
SortMode
.
ASCENDING
?
comparer
.
Compare
(
heap
[
index
],
heap
[
right
])
<=
0
:
comparer
.
Compare
(
heap
[
index
],
heap
[
right
])
>
0
))
{
target
=
right
;
}
if
(
index
!=
target
)
{
T
tmp
=
heap
[
index
];
heap
[
index
]
=
heap
[
target
];
heap
[
target
]
=
tmp
;
index
=
target
;
}
else
{
break
;
}
}
}
}
\ No newline at end of file
Assets/Scripts/Generals/PriorityQueue.cs.meta
0 → 100644
View file @
df56c648
fileFormatVersion: 2
guid: e72f9fd752085534aa021681d36b4d5d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Assets/Scripts/NodalPathfinding/NodalPathfinding2D.cs
View file @
df56c648
...
...
@@ -272,16 +272,12 @@ namespace BS
public
List
<
Vector2Int
>
adjacencies
;
}
public
class
PriorityQueue
<
T
>
class
NodeComparer
:
IComparer
<
Node
>
{
public
PriorityQueue
(
)
private
Vector3
destination
;
NodeComparer
(
Vector3
destination
)
{
}
public
void
Enqueue
(
T
item
)
{
this
.
destination
=
destination
;
}
}
}
\ No newline at end of file
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