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
423f42a3
Commit
423f42a3
authored
8 years ago
by
Ori Almog
Browse files
Options
Downloads
Patches
Plain Diff
Fixed warning, diagonal pathfinding should work
parent
2367a99d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/include/level.h
+5
-10
5 additions, 10 deletions
src/include/level.h
src/level.cpp
+57
-109
57 additions, 109 deletions
src/level.cpp
with
62 additions
and
119 deletions
src/include/level.h
+
5
−
10
View file @
423f42a3
...
...
@@ -39,9 +39,6 @@ class Level {
//Performs BFS without diagonals, returns deltas
std
::
vector
<
Coord
>
bfsPerp
(
Coord
,
Coord
);
//Gets a delta vector based on a path and a start coord
std
::
vector
<
Coord
>
getDeltas
(
std
::
vector
<
Coord
>
,
Coord
);
//Given a coord, returns coords to which you can move to nearby (3x3 box)
std
::
vector
<
Coord
>
getAdjPassable
(
Coord
);
...
...
@@ -49,7 +46,7 @@ class Level {
Coord
throwLocation
(
Coord
,
Coord
);
std
::
vector
<
Room
>&
getRooms
();
private
:
// Store mobs with a notation for how many
...
...
@@ -78,15 +75,13 @@ class Level {
Coord
size
;
int
depth
;
//Add perpendicular coords
void
addPerps
(
Coord
,
std
::
queue
<
Coord
>&
);
//Add diagonal coords
void
addDiags
(
Coord
,
std
::
queue
<
Coord
>&
);
//Try to add a coord to the q
void
tryAddPassable
(
Coord
,
std
::
queue
<
Coord
>&
,
Coord
);
//Try to add a coord to the q
void
tryAdd
(
Coord
,
std
::
queue
<
Coord
>&
,
Coord
);
void
resetPF
();
std
::
vector
<
Coord
>
traceBack
(
Coord
,
Coord
);
};
This diff is collapsed.
Click to expand it.
src/level.cpp
+
57
−
109
View file @
423f42a3
...
...
@@ -177,8 +177,6 @@ void Level::generate(PlayerChar player) {
}
}
std
::
cout
<<
"I'm made "
<<
tunnels
.
size
()
<<
" tunnels"
<<
std
::
endl
;
for
(
Tunnel
t
:
tunnels
){
t
.
dig
(
*
this
);
}
...
...
@@ -192,126 +190,90 @@ void Level::addTunnel(int i, int j, bool* a, bool* b, Generator gen){
}
}
void
Level
::
addPerps
(
Coord
current
,
std
::
queue
<
Coord
>&
deltas
){
Coord
target
;
target
=
current
+
Coord
(
1
,
0
);
tryAdd
(
current
,
deltas
,
target
);
target
=
current
+
Coord
(
-
1
,
0
);
tryAdd
(
current
,
deltas
,
target
);
target
=
current
+
Coord
(
0
,
1
);
tryAdd
(
current
,
deltas
,
target
);
target
=
current
+
Coord
(
0
,
-
1
);
tryAdd
(
current
,
deltas
,
target
);
}
void
Level
::
addDiags
(
Coord
current
,
std
::
queue
<
Coord
>&
deltas
){
Coord
target
;
target
=
current
+
Coord
(
1
,
1
);
tryAdd
(
current
,
deltas
,
target
);
target
=
current
+
Coord
(
-
1
,
1
);
tryAdd
(
current
,
deltas
,
target
);
target
=
current
+
Coord
(
-
1
,
-
1
);
tryAdd
(
current
,
deltas
,
target
);
target
=
current
+
Coord
(
1
,
-
1
);
tryAdd
(
current
,
deltas
,
target
);
}
void
Level
::
tryAddPassable
(
Coord
current
,
std
::
queue
<
Coord
>&
q
,
Coord
target
){
if
(
target
[
0
]
>
0
&&
target
[
0
]
<
size
[
0
]
&&
target
[
1
]
>
0
&&
target
[
1
]
<
size
[
1
]){
if
(
tiles
[
target
[
0
]][
target
[
1
]].
isPassable
()
==
Terrain
::
Passable
&&
!
tiles
[
target
[
0
]][
target
[
1
]].
checked
){
q
.
push
(
target
.
copy
());
tiles
[
target
[
0
]][
target
[
1
]].
checked
=
true
;
Coord
t_
=
target
.
copy
();
if
(
tiles
[
target
[
0
]][
target
[
1
]].
isPassable
()
==
Terrain
::
Passable
&&
!
(
tiles
[
target
[
0
]][
target
[
1
]].
checked
)){
Coord
c_
=
current
.
copy
();
Coord
p_
=
target
.
copy
();
//parents.insert(std::make_pair(t_, c_));
q
.
push
(
p_
);
tiles
[
target
[
0
]][
target
[
1
]].
checked
=
true
;
tiles
[
target
[
0
]][
target
[
1
]].
parent
=
c_
;
}
}
}
void
Level
::
tryAdd
(
Coord
current
,
std
::
queue
<
Coord
>&
deltas
,
Coord
target
){
void
Level
::
tryAdd
(
Coord
current
,
std
::
queue
<
Coord
>&
q
,
Coord
target
){
if
(
target
[
0
]
>
0
&&
target
[
0
]
<
size
[
0
]
&&
target
[
1
]
>
0
&&
target
[
1
]
<
size
[
1
]){
if
(
!
(
tiles
[
target
[
0
]][
target
[
1
]].
checked
)){
Coord
t_
=
target
.
copy
();
Coord
c_
=
current
.
copy
();
Coord
p_
=
target
.
copy
();
Coord
f_
=
target
.
copy
(
);
q
.
push
(
p_
);
deltas
.
push
(
p_
);
tiles
[
f_
[
0
]][
f_
[
1
]].
checked
=
true
;
tiles
[
f_
[
0
]][
f_
[
1
]].
parent
=
c_
;
tiles
[
target
[
0
]][
target
[
1
]].
checked
=
true
;
tiles
[
target
[
0
]][
target
[
1
]].
parent
=
c_
;
}
}
}
std
::
vector
<
Coord
>
Level
::
bfsDiag
(
Coord
start
,
Coord
end
){
/*
for (auto x=0; x < size[0]; x++) {
for (auto y=0; y < size[1]; y++) {
tiles[x][y].checked = false;
}
}
resetPF
();
std::queue<Coord>
delta
;
delta
.push(start.copy());
std
::
queue
<
Coord
>
q
;
q
.
push
(
start
.
copy
());
while(!
delta
.empty()){
while
(
!
q
.
empty
()){
Coord current =
delta
.front();
delta
.pop();
Coord
current
=
q
.
front
()
.
copy
()
;
q
.
pop
();
if
(
current
==
end
){
break
;
}
Coord
target
;
//addPerps(current, delta, parents);
//addDiags(current, delta, parents);
}
target
=
current
+
Coord
(
1
,
0
);
tryAddPassable
(
current
,
q
,
target
);
//TODO: Put this into its own function
std::vector<Coord> path;
Coord current = end.copy();
while(current != start){
target
=
current
+
Coord
(
-
1
,
0
);
tryAddPassable
(
current
,
q
,
target
);
path.push_back(current);
current = parent[current[0]][current[1]].copy();
target
=
current
+
Coord
(
0
,
1
);
tryAddPassable
(
current
,
q
,
target
);
target
=
current
+
Coord
(
0
,
-
1
);
tryAddPassable
(
current
,
q
,
target
);
target
=
current
+
Coord
(
1
,
1
);
tryAddPassable
(
current
,
q
,
target
);
target
=
current
+
Coord
(
-
1
,
1
);
tryAddPassable
(
current
,
q
,
target
);
target
=
current
+
Coord
(
1
,
-
1
);
tryAddPassable
(
current
,
q
,
target
);
target
=
current
+
Coord
(
-
1
,
-
1
);
tryAddPassable
(
current
,
q
,
target
);
}
path.push_back(start.copy());
std
::
vector
<
Coord
>
path
=
traceBack
(
end
,
start
);
return
path
;
*/
}
std
::
vector
<
Coord
>
Level
::
bfsPerp
(
Coord
start
,
Coord
end
){
std
::
cout
<<
"AAA"
<<
std
::
endl
;
for
(
auto
x
=
0
;
x
<
size
[
0
];
x
++
)
{
for
(
auto
y
=
0
;
y
<
size
[
1
];
y
++
)
{
tiles
[
x
][
y
].
checked
=
false
;
tiles
[
x
][
y
].
parent
=
Coord
(
0
,
0
);
}
}
resetPF
();
std
::
queue
<
Coord
>
q
;
q
.
push
(
start
.
copy
());
...
...
@@ -340,18 +302,27 @@ std::vector<Coord> Level::bfsPerp(Coord start, Coord end){
tryAdd
(
current
,
q
,
target
);
}
std
::
cout
<<
"FEF"
<<
std
::
endl
;
std
::
vector
<
Coord
>
path
=
traceBack
(
end
,
start
);
return
path
;
}
void
Level
::
resetPF
(){
for
(
auto
x
=
0
;
x
<
size
[
0
];
x
++
)
{
for
(
auto
y
=
0
;
y
<
size
[
1
];
y
++
)
{
tiles
[
x
][
y
].
checked
=
false
;
tiles
[
x
][
y
].
parent
=
Coord
(
0
,
0
);
}
}
}
std
::
vector
<
Coord
>
Level
::
traceBack
(
Coord
end
,
Coord
start
){
std
::
vector
<
Coord
>
path
;
Coord
current
=
end
.
copy
();
std
::
cout
<<
"Going from: "
<<
start
[
0
]
<<
", "
<<
start
[
1
]
<<
std
::
endl
;
std
::
cout
<<
"Going to: "
<<
end
[
0
]
<<
", "
<<
end
[
1
]
<<
std
::
endl
;
int
count
=
0
;
std
::
cout
<<
current
[
0
]
<<
", "
<<
current
[
1
]
<<
std
::
endl
;
while
(
current
!=
start
){
Coord
c_
=
current
.
copy
();
...
...
@@ -359,8 +330,6 @@ std::vector<Coord> Level::bfsPerp(Coord start, Coord end){
path
.
push_back
(
c_
);
current
=
tiles
[
current
[
0
]][
current
[
1
]].
parent
.
copy
();
std
::
cout
<<
current
[
0
]
<<
", "
<<
current
[
1
]
<<
std
::
endl
;
count
++
;
if
(
count
==
100
||
current
==
Coord
(
0
,
0
)){
...
...
@@ -369,28 +338,7 @@ std::vector<Coord> Level::bfsPerp(Coord start, Coord end){
}
}
std
::
cout
<<
"Start: "
<<
start
[
0
]
<<
", "
<<
start
[
1
]
<<
std
::
endl
;
std
::
cout
<<
"Current: "
<<
current
[
0
]
<<
", "
<<
current
[
1
]
<<
std
::
endl
;
path
.
push_back
(
start
.
copy
());
return
path
;
}
std
::
vector
<
Coord
>
Level
::
getDeltas
(
std
::
vector
<
Coord
>
path
,
Coord
start
){
std
::
vector
<
Coord
>
deltas
;
std
::
reverse
(
path
.
begin
(),
path
.
end
());
if
(
start
!=
path
[
0
]){
std
::
cout
<<
"Start != path[0]"
<<
std
::
endl
;
}
for
(
int
i
=
0
;
i
<
path
.
size
()
-
1
;
i
++
){
Coord
delta
=
path
[
i
+
1
]
-
path
[
i
];
deltas
.
push_back
(
delta
);
}
return
deltas
;
}
\ No newline at end of file
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