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

Single-Player Mode #7

Merged
merged 7 commits into from
Feb 12, 2017
Merged

Single-Player Mode #7

merged 7 commits into from
Feb 12, 2017

Conversation

tbohne
Copy link
Collaborator

@tbohne tbohne commented Feb 8, 2017

First version of a single player mode

  • Random ship placement for the AI (restarts the process in a "dead-end" situation)
  • Random moves (considers nothing; just random for now)
  • Error types

Copy link
Owner

@SvantjeJung SvantjeJung left a 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> {
Copy link
Owner

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?

Copy link
Collaborator Author

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 ;)

Copy link
Collaborator

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. */
Copy link
Owner

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()) {
Copy link
Owner

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 ""?

Copy link
Collaborator Author

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. */
Copy link
Owner

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...

Copy link
Collaborator Author

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.

@SvantjeJung SvantjeJung merged commit f9213d6 into dev Feb 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants