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

Feedback #1

Open
wants to merge 4 commits into
base: feedback
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ pub struct Card {

impl Card {
pub fn fight(&self, other: &Card) -> FightResult {
todo!()
match (self.damage >= other.health, other.damage >= self.health) {
(true, true) => FightResult::Tie,
(true, false) => FightResult::Win,
(false, true) => FightResult::Loss,
(false, false) => FightResult::Draw,
}
}

/// Give a play by play of the battle
Expand Down
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ mod strings;

pub enum FightResult {
// TODO: Add variants for win, loss, tie, and draw
Win,
Loss,
Tie,
Draw,
}

fn main() {
Expand Down
18 changes: 16 additions & 2 deletions src/shop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,24 @@ impl Shop {
/// this store wins, FightResult::Loss if this store loses, and a
/// FightResult::Tie if both stores win the same number of battles.
pub fn fight_store(&self, other: &Shop) -> FightResult {
todo!()
let zipped: i32 = self
.cards
.iter()
.zip(&other.cards)
.map(|(x, y)| x.fight(y))
.map(|x| match x {
FightResult::Win => 1,
FightResult::Loss => -1,
_ => 0,
})
.sum();
match zipped {
1.. => FightResult::Win,
0 => FightResult::Tie,
_ => FightResult::Loss,
}
}
}

// Implement the Display trait for Shop so that it can be printed. Print the
// shop's stats, including the most expensive card, the total damage, and the
// total health.
Expand Down