-
Notifications
You must be signed in to change notification settings - Fork 12
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
Michael Sheely Pull Request #8
base: master
Are you sure you want to change the base?
Conversation
let from = chars.next().and_then(char_to_peg); | ||
let to = chars.next().and_then(char_to_peg); | ||
match (from, to, chars.next()) { | ||
(Some(from_peg), Some(to_peg), None) => Ok(Action::Move(Move::new(from_peg, to_peg))), |
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.
This is awesome. Jackson and I are looking at how people did parsing and I really like your match
on a 3-tuple.
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.
Nice work!
Just nits regarding style & use of std
@@ -1,6 +1,6 @@ | |||
[package] | |||
name = "wk0-starter" | |||
version = "0.1.0" | |||
authors = ["Alex Ozdemir <aozdemir@hmc.edu>"] | |||
authors = ["Alex Ozdemir <aozdemir@hmc.edu>", "Michael Sheely <msheely@hmc.edu>"] |
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.
Oh man!
You found the Cargo.toml!
// It has been completed by Michael Sheely to form | ||
// a functional command line game: Towers of Hanoi | ||
// | ||
// Talked to Jackson Warely and Adam Dunlap |
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.
😄
let mut vec = Vec::new(); | ||
for i in 0..disks { | ||
vec.push(Disk(disks - i)); | ||
} |
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.
Definitely works! You can also take of the advantage of the fact that 0..disks
is Iterator<i32>
and use Iterator::collect
to pull the items in the iterator into a vector.
Peg::Left => self.left.push(disk), | ||
Peg::Center => self.center.push(disk), | ||
Peg::Right => self.right.push(disk), | ||
}) |
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.
You may have already written code for this.
|
||
/// Returns the next step of the algorithm, based on if we're done or not | ||
fn next_step(&self) -> NextStep { | ||
if self.done() { NextStep::Win } else { NextStep::Continue } | ||
} |
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.
😄
match result { | ||
Ok(()) => { self.pop_disk(from); Ok(self.next_step()) }, | ||
Err(e) => Err(e), | ||
} |
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.
Hmm... If it's Ok
do something, else pass the error though... Have we seen this pattern?
No description provided.