DEV Community

loading...

Discussion on: Daily Challenge #43 - Boardgame Fight Resolver

Collapse
brightone profile image
Oleksii Filonenko

Rust:

enum Piece {
    Archer,
    Swordsman,
    Pikeman,
    Cavalry,
}

fn fight_resolve<'a>(attacker: &'a Piece, defender: &'a Piece) -> &'a Piece {
    use Piece::*;

    match (attacker, defender) {
        (Swordsman, Archer) | (Pikeman, Swordsman) | (Cavalry, Pikeman) | (Archer, Cavalry) => {
            defender
        }
        (attacker, _) => attacker,
    }
}