fn fight(boss: &Player, equipped: &[&Equipment; 4]) -> Outcome {
    let mut hero_hp = STARTING_HP;
    let mut boss_hp = boss.hp;
    let mut turn = Turn::Hero;

    let mut hero_attack = 0;
    let mut hero_defence = 0;
    let mut equipment_cost = 0;

    for &e in equipped.iter() {
        hero_attack += e.damage;
        hero_defence += e.armour;
        equipment_cost += e.cost;
    }

    while boss_hp > 0 && hero_hp > 0 {
        turn = match turn {
            Turn::Hero => {
                let damage = max(hero_attack.saturating_sub(boss.armour), 1);
                boss_hp = boss_hp.saturating_sub(damage);

                Turn::Boss
            }
            Turn::Boss => {
                let damage = max(boss.damage.saturating_sub(hero_defence), 1);
                hero_hp = hero_hp.saturating_sub(damage);

                Turn::Hero
            }
        }
    }

    if boss_hp == 0 {
        Outcome::Win(equipment_cost)
    } else {
        Outcome::Lose(equipment_cost)
    }
}
/// Simulate the boss fight using the given equipment loadout
///
/// Returns - Fight outcome with associated equipment cost
Simulate the boss fight using the given equipment loadout
Returns - Fight outcome with associated equipment cost
Simulate the boss fight using the given equipment loadout Returns - Fight outcome with associated equipment cost
fn fight(boss: &Player, equipped: &[&Equipment; 4]) -> Outcome {
    let mut hero_hp = STARTING_HP;
    let mut boss_hp = boss.hp;
    let mut turn = Turn::Hero;
    let mut hero_attack = 0;
    let mut hero_defence = 0;
    let mut equipment_cost = 0;
    for &e in equipped.iter() {
        hero_attack += e.damage;
        hero_defence += e.armour;
        equipment_cost += e.cost;
    }
    while boss_hp > 0 && hero_hp > 0 {
        turn = match turn {
            Turn::Hero => {
                let damage = max(hero_attack.saturating_sub(boss.armour), 1);
                boss_hp = boss_hp.saturating_sub(damage);
                Turn::Boss
            }
            Turn::Boss => {
                let damage = max(boss.damage.saturating_sub(hero_defence), 1);
                hero_hp = hero_hp.saturating_sub(damage);
                Turn::Hero
            }
        }
    }
    if boss_hp == 0 {
        Outcome::Win(equipment_cost)
    } else {
        Outcome::Lose(equipment_cost)
    }
}
fn fight ( boss : & Player , equipped : & [ & Equipment ; 4 ] ) -> Outcome { let mut hero_hp = STARTING_HP ; let mut boss_hp = boss . hp ; let mut turn = Turn :: Hero ; let mut hero_attack = 0 ; let mut hero_defence = 0 ; let mut equipment_cost = 0 ; for & e in equipped . iter ( ) { hero_attack += e . damage ; hero_defence += e . armour ; equipment_cost += e . cost ; } while boss_hp > 0 && hero_hp > 0 { turn = match turn { Turn :: Hero => { let damage = max ( hero_attack . saturating_sub ( boss . armour ) , 1 ) ; boss_hp = boss_hp . saturating_sub ( damage ) ; Turn :: Boss } Turn :: Boss => { let damage = max ( boss . damage . saturating_sub ( hero_defence ) , 1 ) ; hero_hp = hero_hp . saturating_sub ( damage ) ; Turn :: Hero } } } if boss_hp == 0 { Outcome :: Win ( equipment_cost ) } else { Outcome :: Lose ( equipment_cost ) } }
Simulate the boss fight using the given equipment loadout
Returns - Fight outcome with associated equipment cost
Simulate the boss fight using the given equipment loadout Returns - Fight outcome with associated equipment cost
boss
&Player
equipped
&[&Equipment; 4]
boss
&Player
equipped
&[&Equipment; 4]