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 3 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
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ mod shop;
mod strings;

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

fn main() {
Expand Down
19 changes: 18 additions & 1 deletion src/shop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +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 mut this_store_wins = 0;
let mut other_store_wins = 0;

for card1 in &self.cards {
for card2 in &other.cards {
match card1.fight(card2) {
FightResult::Win => this_store_wins += 1,
FightResult::Loss => other_store_wins += 1,
_ => {}
}
}
}

match this_store_wins.cmp(&other_store_wins) {
std::cmp::Ordering::Greater => FightResult::Win,
std::cmp::Ordering::Less => FightResult::Loss,
std::cmp::Ordering::Equal => FightResult::Tie,
}
}
}

Expand Down