We're a place where coders share, stay up-to-date and grow their careers.
F#:
type Piece = Archer | Swordsman | Pikeman | Cavalry let fightResolve attacker defender = match attacker, defender with | Swordsman, Archer | Pikeman, Swordsman | Cavalry, Pikeman | Archer, Cavalry -> defender | _ -> attacker
One could also turn the fight itself into a type:
type Piece = Archer | Swordsman | Pikeman | Cavalry type Fight = { Attacker : Piece Defender : Piece } let fightResolve fight = let { Attacker = attacker; Defender = defender } = fight match attacker, defender with | Swordsman, Archer | Pikeman, Swordsman | Cavalry, Pikeman | Archer, Cavalry -> defender | _ -> attacker
F#:
One could also turn the fight itself into a type: