Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
four
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
31
Issues
31
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
gadig
four
Commits
7b5d33f0
Commit
7b5d33f0
authored
Oct 20, 2016
by
Cody A Burchett
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
-m comments for heap
parent
30954f53
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
0 deletions
+10
-0
Assets/script/Heap.cs
Assets/script/Heap.cs
+10
-0
No files found.
Assets/script/Heap.cs
View file @
7b5d33f0
...
@@ -10,12 +10,15 @@ public class Heap <Tile> where Tile : HeapItem<Tile>{
...
@@ -10,12 +10,15 @@ public class Heap <Tile> where Tile : HeapItem<Tile>{
//add heapIndex, compareTo to tile class
//add heapIndex, compareTo to tile class
//compare fCost of node then hCost
//compare fCost of node then hCost
//item.compareTo(item2) should return pos if item is less than item2, neg if item is greater than item2
//create heap
public
Heap
(
int
maxSize
)
public
Heap
(
int
maxSize
)
{
{
heapTiles
=
new
Tile
[
maxSize
];
heapTiles
=
new
Tile
[
maxSize
];
}
}
//add item into heap and sort it into position
public
void
Add
(
Tile
item
)
public
void
Add
(
Tile
item
)
{
{
item
.
heapIndex
=
itemCount
;
item
.
heapIndex
=
itemCount
;
...
@@ -24,6 +27,7 @@ public class Heap <Tile> where Tile : HeapItem<Tile>{
...
@@ -24,6 +27,7 @@ public class Heap <Tile> where Tile : HeapItem<Tile>{
itemCount
++;
itemCount
++;
}
}
//remove first tile and resort heap
public
Tile
RemoveFirst
()
public
Tile
RemoveFirst
()
{
{
Tile
first
=
heapTiles
[
0
];
Tile
first
=
heapTiles
[
0
];
...
@@ -34,11 +38,13 @@ public class Heap <Tile> where Tile : HeapItem<Tile>{
...
@@ -34,11 +38,13 @@ public class Heap <Tile> where Tile : HeapItem<Tile>{
return
first
;
return
first
;
}
}
//resort item position
public
void
UpdateItem
(
Tile
item
)
public
void
UpdateItem
(
Tile
item
)
{
{
SortUp
(
item
);
SortUp
(
item
);
}
}
public
int
Count
public
int
Count
{
{
get
get
...
@@ -47,11 +53,13 @@ public class Heap <Tile> where Tile : HeapItem<Tile>{
...
@@ -47,11 +53,13 @@ public class Heap <Tile> where Tile : HeapItem<Tile>{
}
}
}
}
//does heap contain item
public
bool
Contains
(
Tile
item
)
public
bool
Contains
(
Tile
item
)
{
{
return
Equals
(
heapTiles
[
item
.
heapIndex
],
item
);
return
Equals
(
heapTiles
[
item
.
heapIndex
],
item
);
}
}
//sort tile lower into heap
void
SortDown
(
Tile
item
)
void
SortDown
(
Tile
item
)
{
{
while
(
true
)
while
(
true
)
...
@@ -88,6 +96,7 @@ public class Heap <Tile> where Tile : HeapItem<Tile>{
...
@@ -88,6 +96,7 @@ public class Heap <Tile> where Tile : HeapItem<Tile>{
}
}
}
}
//sort item higher into heap
void
SortUp
(
Tile
item
)
void
SortUp
(
Tile
item
)
{
{
int
indexOfParent
=
(
item
.
heapIndex
-
1
)
/
2
;
int
indexOfParent
=
(
item
.
heapIndex
-
1
)
/
2
;
...
@@ -108,6 +117,7 @@ public class Heap <Tile> where Tile : HeapItem<Tile>{
...
@@ -108,6 +117,7 @@ public class Heap <Tile> where Tile : HeapItem<Tile>{
}
}
}
}
//swap tiles
void
Swap
(
Tile
item1
,
Tile
item2
)
void
Swap
(
Tile
item1
,
Tile
item2
)
{
{
heapTiles
[
item1
.
heapIndex
]
=
item2
;
heapTiles
[
item1
.
heapIndex
]
=
item2
;
...
...
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