fn fight(
            attacker: Unit,
            defender: Unit,
            mut attack_value: u8,
            mut defense_value: u8,
            board: &[[Option<Card>; 5]; 4],
            attacking_player: u8,
            defending_player: u8,
        ) -> FightResult {
            match defender {
                // Warden has a defense bonus ONLY against enemies
                Unit::Warden => {
                    if attacking_player != defending_player {
                        defense_value += 1;
                    }
                }
                // Swarm gets ally bonus
                Unit::Swarm => {
                    let defending_player = (attacking_player % 2) + 1;
                    defense_value = min(
                        10,
                        defense_value + Card::swarm_count(board, defending_player),
                    );
                }
                _ => {}
            }

            match attacker {
                // Slayer uses swapped attack values
                Unit::Slayer => {
                    swap(&mut defense_value, &mut attack_value);
                }
                // Swarm gets ally bonus
                Unit::Swarm => {
                    attack_value = min(
                        10,
                        attack_value + Card::swarm_count(board, attacking_player),
                    );
                }
                _ => {}
            }

            // do the battle
            if attack_value > defense_value {
                // attacker wins
                return FightResult::Win;
            } else if attack_value == defense_value {
                // it's a tie
                return FightResult::Tie;
            } else {
                // attacker hos lost the battle
                return FightResult::Lose;
            }
        }
// fight the opponent card and returns result
fight the opponent card and returns result
fight the opponent card and returns result
fn fight(
            attacker: Unit,
            defender: Unit,
            mut attack_value: u8,
            mut defense_value: u8,
            board: &[[Option<Card>; 5]; 4],
            attacking_player: u8,
            defending_player: u8,
        ) -> FightResult {
            match defender {
                // Warden has a defense bonus ONLY against enemies
                Unit::Warden => {
                    if attacking_player != defending_player {
                        defense_value += 1;
                    }
                }
                // Swarm gets ally bonus
                Unit::Swarm => {
                    let defending_player = (attacking_player % 2) + 1;
                    defense_value = min(
                        10,
                        defense_value + Card::swarm_count(board, defending_player),
                    );
                }
                _ => {}
            }
            match attacker {
                // Slayer uses swapped attack values
                Unit::Slayer => {
                    swap(&mut defense_value, &mut attack_value);
                }
                // Swarm gets ally bonus
                Unit::Swarm => {
                    attack_value = min(
                        10,
                        attack_value + Card::swarm_count(board, attacking_player),
                    );
                }
                _ => {}
            }
            // do the battle
            if attack_value > defense_value {
                // attacker wins
                return FightResult::Win;
            } else if attack_value == defense_value {
                // it's a tie
                return FightResult::Tie;
            } else {
                // attacker hos lost the battle
                return FightResult::Lose;
            }
        }
fn fight ( attacker : Unit , defender : Unit , mut attack_value : u8 , mut defense_value : u8 , board : & [ [ Option < Card > ; 5 ] ; 4 ] , attacking_player : u8 , defending_player : u8 , ) -> FightResult { match defender { // Warden has a defense bonus ONLY against enemies Unit :: Warden => { if attacking_player != defending_player { defense_value += 1 ; } } // Swarm gets ally bonus Unit :: Swarm => { let defending_player = ( attacking_player % 2 ) + 1 ; defense_value = min ( 10 , defense_value + Card :: swarm_count ( board , defending_player ) , ) ; } _ => { } } match attacker { // Slayer uses swapped attack values Unit :: Slayer => { swap ( & mut defense_value , & mut attack_value ) ; } // Swarm gets ally bonus Unit :: Swarm => { attack_value = min ( 10 , attack_value + Card :: swarm_count ( board , attacking_player ) , ) ; } _ => { } } // do the battle if attack_value > defense_value { // attacker wins return FightResult :: Win ; } else if attack_value == defense_value { // it's a tie return FightResult :: Tie ; } else { // attacker hos lost the battle return FightResult :: Lose ; } }
fight the opponent card and returns result
fight the opponent card and returns result
attacker
Unit
defender
Unit
attack_value
u8
defense_value
u8
board
&[[Option<Card>; 5]; 4]
attacking_player
u8
defending_player
u8