Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rustproject
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue 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
safarik
rustproject
Commits
d66473bd
Commit
d66473bd
authored
3 years ago
by
radow
Browse files
Options
Downloads
Patches
Plain Diff
simpler path building for now
parent
392098ed
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/game_state/config.rs
+2
-0
2 additions, 0 deletions
src/game_state/config.rs
src/game_state/level.rs
+29
-6
29 additions, 6 deletions
src/game_state/level.rs
with
31 additions
and
6 deletions
src/game_state/config.rs
+
2
−
0
View file @
d66473bd
...
...
@@ -5,3 +5,5 @@ pub const BOARD_HEIGHT: usize = 19;
pub
const
PLAYER_STARTING_AP
:
usize
=
1
;
pub
const
PLAYER_STARTING_HP
:
usize
=
10
;
pub
const
ROOM_NUMBER
:
usize
=
20
;
This diff is collapsed.
Click to expand it.
src/game_state/level.rs
+
29
−
6
View file @
d66473bd
...
...
@@ -78,9 +78,17 @@ impl Level {
fn
add_rooms
(
board
:
Board
)
->
Board
{
let
mut
board
=
board
.clone
();
for
n
in
0
..
config
::
ROOM_NUMBER
{
let
mut
rooms
:
Vec
<
Room
>
=
Vec
::
new
();
for
_n
in
0
..
config
::
ROOM_NUMBER
{
let
r
=
Room
::
new
();
board
=
r
.carve
(
board
);
rooms
.push
(
r
);
}
for
r
in
&
rooms
{
for
r2
in
&
rooms
{
let
p
:
Path
=
Path
::
new
(
Vec2
::
new
(
r
.x
,
r
.y
),
Vec2
::
new
(
r2
.x
,
r2
.y
));
board
=
p
.carve
(
board
);
}
}
board
}
...
...
@@ -162,10 +170,25 @@ impl Path{
}
fn
carve
(
&
self
,
board
:
Board
)
->
Board
{
let
start
:
Node
=
Node
::
new
(
board
,
self
.start
);
let
goal
:
Node
=
Node
::
new
(
board
,
self
.goal
);
let
result
=
astar
(
&
start
,
|
p
:
Node
|
p
.get_neighbours
(),
|
p
:
Node
|
p
.distance
(
&
goal
),
|
p
:
Node
|
p
==
goal
);
//let start: Node = Node::new(board, self.start);
//let goal: Node = Node::new(board, self.goal);
//let result = astar(&start, |p:Node|p.get_neighbours(), |p:Node|p.distance(&goal), |p:Node|p*==goal);
//assert_eq!(result.expect("no path found").1, 4);
let
mut
board
=
board
.clone
();
for
pos
in
self
.plot_path
()
.iter
(){
board
[
pos
.x
][
pos
.y
]
=
Tile
::
Empty
;
}
board
}
fn
plot_path
(
&
self
)
->
Vec
<
Vec2
<
usize
>>
{
let
mut
path
:
Vec
<
Vec2
<
usize
>>
=
Vec
::
new
();
for
x
in
self
.start.x
..
self
.goal.x
{
path
.push
(
Vec2
::
new
(
x
,
self
.start.y
));
}
for
y
in
self
.start.y
..
self
.goal.y
{
path
.push
(
Vec2
::
new
(
self
.goal.x
,
y
));
}
path
}
}
...
...
@@ -186,7 +209,7 @@ impl Node{
}
fn
get_neighbours
(
&
self
)
->
Vec
<
(
Node
,
usize
)
>
{
let
neighbours
:
Vec
<
(
Node
,
usize
)
>
=
Vec
::
new
();
let
mut
neighbours
:
Vec
<
(
Node
,
usize
)
>
=
Vec
::
new
();
if
self
.pos.x
>
0
{
let
newpos
:
Vec2
<
usize
>
=
Vec2
::
new
(
self
.pos.x
-
1
,
self
.pos.y
);
let
tuple
:(
Node
,
usize
)
=
(
Node
::
new
(
self
.board
,
newpos
),
Node
::
get_value
(
self
.board
,
newpos
));
...
...
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