Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
RogueReborn
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mikhail Andrenkov
RogueReborn
Commits
7d7cc676
Commit
7d7cc676
authored
8 years ago
by
Ori Almog
Browse files
Options
Downloads
Patches
Plain Diff
basic pathfinding
parent
410c33aa
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
src/algs.cpp
+83
-0
83 additions, 0 deletions
src/algs.cpp
src/include/algs.h
+38
-0
38 additions, 0 deletions
src/include/algs.h
src/include/terrain.h
+1
-0
1 addition, 0 deletions
src/include/terrain.h
src/terrain.cpp
+1
-1
1 addition, 1 deletion
src/terrain.cpp
src/tunnel.cpp
+1
-0
1 addition, 0 deletions
src/tunnel.cpp
with
124 additions
and
1 deletion
src/algs.cpp
0 → 100644
+
83
−
0
View file @
7d7cc676
#include
"include/terrain.h"
#include
"include/tiles.h"
#include
"include/level.h"
#include
"include/coord.h"
#include
<vector>
#include
<queue>
#include
<map>
#include
<math.h>
Algs
::
Algs
(){}
void
Algs
::
addPerps
(
Coord
current
,
&
std
::
vector
<
Coord
>
deltas
,
Level
&
lvl
,
std
::
map
<
Coord
,
Coord
>&
parents
){
Coord
target
;
target
=
current
+
Coord
(
1
,
0
);
tryAdd
(
current
,
delta
,
lvl
,
parents
,
target
);
target
=
current
+
Coord
(
-
1
,
0
);
tryAdd
(
current
,
delta
,
lvl
,
parents
,
target
);
target
=
current
+
Coord
(
0
,
1
);
tryAdd
(
current
,
delta
,
lvl
,
parents
,
target
);
target
=
current
+
Coord
(
0
,
-
1
);
tryAdd
(
current
,
delta
,
lvl
,
parents
,
target
);
}
void
Algs
::
addDiags
(
Coord
current
,
std
::
vector
<
Coord
>&
deltas
,
Level
&
lvl
,
std
::
map
<
Coord
,
Coord
>&
parents
){
Coord
target
;
target
=
current
+
Coord
(
1
,
1
);
tryAdd
(
current
,
delta
,
lvl
,
parents
,
target
);
target
=
current
+
Coord
(
-
1
,
1
);
tryAdd
(
current
,
delta
,
lvl
,
parents
,
target
);
target
=
current
+
Coord
(
-
1
,
-
1
);
tryAdd
(
current
,
delta
,
lvl
,
parents
,
target
);
target
=
current
+
Coord
(
1
,
-
1
);
tryAdd
(
current
,
delta
,
lvl
,
parents
,
target
);
}
void
Algs
::
tryAdd
(
Coord
current
,
std
::
vector
<
Coord
>&
deltas
,
Level
&
lvl
,
std
::
map
<
Coord
,
Coord
>&
parents
,
Coord
target
){
if
(
lvl
[
target
].
isPassable
()
==
Terrain
::
Passable
&&
!
lvl
[
target
].
checked
){
delta
.
push_back
(
target
);
lvl
[
target
].
checked
=
true
;
parents
[
target
,
current
];
}
}
std
::
vector
<
Coord
>
Algs
::
bfsDiag
(
Coord
start
,
Coord
end
,
Level
&
lvl
){
std
::
map
<
Coord
,
Coord
>
parents
;
std
::
queue
<
Coord
>
delta
;
delta
.
push
(
start
.
copy
());
while
(
!
delta
.
empty
()){
Coord
current
=
delta
.
front
();
delta
.
pop
();
if
(
current
==
end
){
break
;
}
addPerps
(
current
,
delta
,
lvl
,
parents
);
addDiags
(
current
,
delta
,
lvl
,
parents
);
}
}
std
::
vector
<
Coord
>
Algs
::
bfsPerp
(
Coord
start
,
Coord
end
){
}
std
::
vector
<
Coord
>
Algs
::
getPath
(
std
::
vector
<
Coord
>
delta
,
Coord
start
){
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/include/algs.h
0 → 100644
+
38
−
0
View file @
7d7cc676
#pragma once
#include
"include/terrain.h"
#include
"include/tiles.h"
#include
"include/level.h"
#include
"include/coord.h"
#include
<map>
#include
<vector>
class
Level
;
class
Algs
{
public:
Algs
();
//Performs BFS with diagonals
std
::
vector
<
Coord
>
bfsDiag
(
Coord
,
Coord
);
//Performs BFS without diagonals
std
::
vector
<
Coord
>
bfsPerp
(
Coord
,
Coord
);
//Gets a path given a delta vector and starting position
std
::
vector
<
Coord
>
getPath
(
Coord
,
std
::
vector
<
Coord
>
);
private:
//Add perpendicular coords
void
addPerps
(
Coord
,
std
::
vector
<
Coord
>
,
Level
*
,
std
::
map
<
Coord
,
Coord
>
);
//Add diagonal coords
void
addDiags
(
Coord
,
std
::
vector
<
Coord
>
,
Level
*
,
std
::
map
<
Coord
,
Coord
>
);
//Add diagonal coords
void
tryAdd
(
Coord
,
std
::
vector
<
Coord
>
,
Level
*
,
std
::
map
<
Coord
,
Coord
>
,
Coord
);
};
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/include/terrain.h
+
1
−
0
View file @
7d7cc676
...
...
@@ -11,6 +11,7 @@ class Terrain {
char
getSymbol
();
Passability
isPassable
();
Visibility
getVisibility
();
bool
checked
=
false
;
private
:
char
character
;
Visibility
visible
;
...
...
This diff is collapsed.
Click to expand it.
src/terrain.cpp
+
1
−
1
View file @
7d7cc676
...
...
@@ -16,4 +16,4 @@ Terrain::Passability Terrain::isPassable() {
Terrain
::
Visibility
Terrain
::
getVisibility
()
{
return
visible
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/tunnel.cpp
+
1
−
0
View file @
7d7cc676
...
...
@@ -91,6 +91,7 @@ void Tunnel::dig(Level& level){
delta
*=
-
1
;
}
//TODO: This is fine, but after the shuffle it might still break!
if
(
!
p
->
touches
(
current
+
delta
)
&&
!
q
->
touches
(
current
+
delta
)){
path
.
push_back
(
delta
);
current
+=
delta
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment