pub type Move { Rock Paper Scissors } type GameResult { Player1Wins(throw: Move, beat: Move) Player2Wins(throw: Move, beat: Move) Draw(Move) } pub fn play(player_1_move: Move, player_2_move: Move) { case player_1_move, player_2_move { Rock, Scissors -> Player1Wins(Rock, Scissors) Rock, Paper -> Player2Wins(Paper, Rock) Paper, Rock -> Player1Wins(Rock, Paper) Paper, Scissors -> Player2Wins(Scissors, Paper) Scissors, Rock -> Player2Wins(Rock, Scissors) Scissors, Paper -> Player1Wins(Scissors, Paper) _, _ -> Draw(player_1_move) } |> game_result_to_string } fn move_to_string(move: Move) { case move { Rock -> "Rock" Paper -> "Paper" Scissors -> "Scissors" } } fn game_result_to_string(result) { case result { Player1Wins(threw, beat) -> "Player 1 won - " <> move_to_string(threw) <> " beats " <> move_to_string(beat) Player2Wins(threw, beat) -> "Player 2 won - " <> move_to_string(threw) <> " beats " <> move_to_string(beat) Draw(move) -> "Draw! Both players chose " <> move_to_string(move) <> "s" } }