-
Notifications
You must be signed in to change notification settings - Fork 3
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
Single-Player Mode #7
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't have a closer look at the whole code, should be sufficient for the moment.
src/model/mod.rs
Outdated
|
||
/// Random ship placement for the AI. | ||
fn place_ai(player: &mut types::Player, ship: &types::ShipType, | ||
mut vec: &mut Vec<usize>) -> Result<(), types::ErrorType> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, was there a guideline about formatting parameters and return type when multiple lines are necessary? I would have put the return type to the next line. Does someone knows for sure what has been said about that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure either, changed it ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like it has been decided 14 hours ago. I think this means the right formatting for you is:
fn place_ai(
player: &mut types::Player,
ship: &types::ShipType,
mut vec: &mut Vec<usize>,
) -> Result<(), types::ErrorType> {
...
}
src/model/mod.rs
Outdated
let mut rand = *rng.choose(&vec).unwrap(); | ||
|
||
/* The complete Moore neighborhood needs to be free | ||
to place the first part of the ship. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Citing the lecture slides:
// Multiline comments are
// written like this. You shall
// not use /* */ comments ;-)
Would be nice (but is a minor detail), if you could change the /**/ to // in every file.
src/model/mod.rs
Outdated
need to restart the whole placement process. */ | ||
if vec.len() == 1 { | ||
return Err(types::ErrorType::DeadEnd); | ||
} else if valid_field(&player, rand, &"".to_string()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
&"".to_string()
first making ""
a String, then taking a reference of it? Why not just ""
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remainder of the String confusion..
src/model/mod.rs
Outdated
|
||
let mut last_part = false; | ||
|
||
/* To prevent subtraction with overflow. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There were functions like saturating_sub
or checked_sub
could we use them at this point? ...maybe I just don't get how your AI setting works in its entirety at the moment...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good advice, changed it torand = rand.checked_sub(10).unwrap_or(100);
to get the 100 as kind of an error code. Not sure if this is the best way to do it, but I need to keep track of the result of checked_sub()
somehow to recognize the case in which it would be negative.
First version of a single player mode