Skip to content
Snippets Groups Projects
Commit d66473bd authored by radow's avatar radow
Browse files

simpler path building for now

parent 392098ed
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......@@ -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));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment