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

Michael Sheely Pull Request #8

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

MichaelSheely
Copy link

No description provided.

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

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.

Copy link
Contributor

@alex-ozdemir alex-ozdemir left a 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>"]
Copy link
Contributor

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
Copy link
Contributor

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));
}
Copy link
Contributor

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),
})
Copy link
Contributor

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 }
}
Copy link
Contributor

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),
}
Copy link
Contributor

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?

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