Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance game initialization so that creepers never spawn on the house or Ferris #5

Open
darioalessandro opened this issue Jul 13, 2022 · 0 comments
Labels
help wanted Extra attention is needed

Comments

@darioalessandro
Copy link
Member

darioalessandro commented Jul 13, 2022

Check this method:

GameEvents::InitGameWithCreepers(creepers, rows, columns) => {
// spawn creepers
let mut randy = thread_rng();
let creepers = (0..creepers)
.into_iter()
.map(|_i| {
let row = randy.gen_range(0..rows);
let column = randy.gen_range(0..columns);
Creeper {
location: Location { x: row, y: column },
}
})
.collect();
// TODO: validate that Ferris does not spawn next or on top of a creeper.
let row = randy.gen_range(0..rows);
let column = randy.gen_range(0..columns);
let ferris = Ferris {
location: Location { x: row, y: column },
path: vec![],
};
let row = randy.gen_range(0..rows);
let column = randy.gen_range(0..columns);
let target = Location { x: row, y: column };
let moves = vec![GameState { creepers, ferris }];
let mut game = Game {
rows: rows,
columns: columns,
moves,
target,
status: Status::Idle,
};
let origin = &game.moves.last().unwrap().ferris.location;
let target = &game.target;
let result = Dijkstra::run(&game, origin, &target, &Mode::Ferris);
match result {
Ok(result) => {
// This unwrap will work because we just added a move.
let mut ferris = &mut game.moves.last_mut().unwrap().ferris;
ferris.path = result;
game.validate_status();
game.into()
}
Err(err) => {
game.status = Status::Error(format!("{}", err));
game.into()
}
}
}

Ensure that creepers never spawn on the house game.target or ferris game.moves.last().ferris.location

@darioalessandro darioalessandro added the help wanted Extra attention is needed label Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant