Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
COMS327
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
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
Jake Feddersen
COMS327
Commits
a12c1151
Commit
a12c1151
authored
6 years ago
by
Jake Feddersen
Browse files
Options
Downloads
Patches
Plain Diff
Print distance maps the way we were given them
parent
0c5483ae
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
feddersen_jacob.assignment-1.03/generate_dungeon.c
+23
-23
23 additions, 23 deletions
feddersen_jacob.assignment-1.03/generate_dungeon.c
with
23 additions
and
23 deletions
feddersen_jacob.assignment-1.03/generate_dungeon.c
+
23
−
23
View file @
a12c1151
...
...
@@ -142,13 +142,13 @@ void write_int(FILE* f, uint32_t val);
*
* Algorithm is modified from Dr. Sheaffer's Dijkstra code using his provided heap.
*/
static
void
dijkstra_from_player
(
dungeon
*
d
,
int
dist
[
MAP_HEIGHT
][
MAP_WIDTH
],
int
hardness_limit
);
static
void
dijkstra_from_player
(
dungeon
*
d
,
u
int
32_t
dist
[
MAP_HEIGHT
][
MAP_WIDTH
],
int
hardness_limit
);
void
draw_dist_map
(
int
player_x
,
int
player_y
,
in
t
dist
[
MAP_HEIGHT
][
MAP_WIDTH
]);
void
draw_dist_map
(
dungeon
*
d
,
u
int
32_
t
dist
[
MAP_HEIGHT
][
MAP_WIDTH
]
,
int
hardness_limit
);
int
main
(
int
argc
,
char
*
argv
[])
{
int
i
;
int
load
=
0
;
int
save
=
0
;
...
...
@@ -178,20 +178,19 @@ int main(int argc, char* argv[]) {
draw_map
(
&
d
);
int
non_tunneling_dist
[
MAP_HEIGHT
][
MAP_WIDTH
];
int
tunneling_dist
[
MAP_HEIGHT
][
MAP_WIDTH
];
u
int
32_t
non_tunneling_dist
[
MAP_HEIGHT
][
MAP_WIDTH
];
u
int
32_t
tunneling_dist
[
MAP_HEIGHT
][
MAP_WIDTH
];
dijkstra_from_player
(
&
d
,
non_tunneling_dist
,
1
);
draw_dist_map
(
d
.
player_pos
.
x
,
d
.
player_pos
.
y
,
non_tunneling_dist
);
draw_dist_map
(
&
d
,
non_tunneling_dist
,
0
);
dijkstra_from_player
(
&
d
,
tunneling_dist
,
255
);
draw_dist_map
(
d
.
player_pos
.
x
,
d
.
player_pos
.
y
,
tunneling_dist
);
draw_dist_map
(
&
d
,
tunneling_dist
,
255
);
free_dungeon
(
&
d
);
}
static
void
dijkstra_from_player
(
dungeon
*
d
,
int
dist
[
MAP_HEIGHT
][
MAP_WIDTH
],
int
hardness_limit
)
static
void
dijkstra_from_player
(
dungeon
*
d
,
u
int
32_t
dist
[
MAP_HEIGHT
][
MAP_WIDTH
],
int
hardness_limit
)
{
// Initialize the vairables
static
dijkstra_path_t
path
[
MAP_HEIGHT
][
MAP_WIDTH
],
*
p
;
...
...
@@ -225,17 +224,13 @@ static void dijkstra_from_player(dungeon *d, int dist[MAP_HEIGHT][MAP_WIDTH], in
// Initialize all of the heap pointers
// Also initialize the distance map
// Impossible-to-tunnel cells (all rock for non-tunneling monsters
// and border for tunneling monsters get -1, all theoretically
// reachable cells get INT_MAX
for
(
y
=
0
;
y
<
MAP_HEIGHT
;
y
++
)
{
for
(
x
=
0
;
x
<
MAP_WIDTH
;
x
++
)
{
dist
[
y
][
x
]
=
INT_MAX
;
if
(
d
->
hardness
[
y
][
x
]
<
hardness_limit
)
{
path
[
y
][
x
].
hn
=
heap_insert
(
&
h
,
&
path
[
y
][
x
]);
dist
[
y
][
x
]
=
INT_MAX
;
}
else
{
path
[
y
][
x
].
hn
=
NULL
;
dist
[
y
][
x
]
=
-
1
;
}
}
}
...
...
@@ -245,6 +240,11 @@ static void dijkstra_from_player(dungeon *d, int dist[MAP_HEIGHT][MAP_WIDTH], in
// Visit the current node, and set its distance
p
->
hn
=
NULL
;
dist
[
p
->
pos
[
0
]][
p
->
pos
[
1
]]
=
p
->
cost
;
// If this node is at infinity distance, don't visit its neighbors; it is disconnected
if
(
p
->
cost
==
INT_MAX
)
{
continue
;
}
// Iterate through all neighbors
for
(
y
=
p
->
pos
[
0
]
-
1
;
y
<
p
->
pos
[
0
]
+
2
;
y
++
)
{
...
...
@@ -261,18 +261,18 @@ static void dijkstra_from_player(dungeon *d, int dist[MAP_HEIGHT][MAP_WIDTH], in
}
}
void
draw_dist_map
(
int
player_x
,
int
player_y
,
in
t
dist
[
MAP_HEIGHT
][
MAP_WIDTH
])
{
void
draw_dist_map
(
dungeon
*
d
,
u
int
32_
t
dist
[
MAP_HEIGHT
][
MAP_WIDTH
]
,
int
hardness_limit
)
{
int
x
,
y
;
for
(
y
=
0
;
y
<
MAP_HEIGHT
;
y
++
)
{
for
(
x
=
0
;
x
<
MAP_WIDTH
;
x
++
)
{
if
(
y
==
player_y
&&
x
==
player_
x
)
if
(
y
==
d
->
player_
pos
.
y
&&
x
==
d
->
player_
pos
.
x
)
{
printf
(
"@"
);
else
if
(
d
ist
[
y
][
x
]
=
=
INT_MAX
)
printf
(
"X"
);
else
if
(
dist
[
y
][
x
]
>=
0
)
printf
(
"%d"
,
dist
[
y
][
x
]
%
10
);
else
printf
(
" "
);
}
else
if
(
d
->
hardness
[
y
][
x
]
<
=
hardness_limit
)
{
if
(
dist
[
y
][
x
]
==
INT_MAX
)
printf
(
"X"
);
else
printf
(
"%d"
,
dist
[
y
][
x
]
%
1
0
)
;
}
else
{
printf
(
" "
);
}
}
printf
(
"
\n
"
);
}
...
...
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