Mix.install([
{:jason, "~> 1.4"},
{:kino, "~> 0.9", override: true},
{:youtube, github: "brooklinjazz/youtube"},
{:hidden_cell, github: "brooklinjazz/hidden_cell"}
])
YouTube.new("https://www.youtube.com/watch?v=_PUEoDYpUyQ")
You're going to create a Rock Paper Scissors Lizard Spock game. Rock Paper Scissors Lizard Spock is a more complex adaptation of Rock Paper Scissors.
The rules start the same as normal rock paper scissors.
- Rock beats Scissors.
- Paper beats Rock.
- Scissors beats Paper.
Then we add the following extra rules
- Rock beats Lizard.
- Lizard beats Spock.
- Spock beats Scissors.
- Scissors beats Lizard.
- Lizard beats Paper.
- Paper beats Spock.
- Spock beats Rock.
We'll represent these choices as atoms :rock, :paper, :scissors, :lizard, :spock
.
- Create a
beats?/2
function which determines if once choice beats another.
RockPaperScissorsLizardSpock.beats?(:rock, :lizard) # true
- Create a
play/2
function which determines if player 1 or player 2 won the game.
RockPaperScissorsLizardSpock.play(:rock, :lizard) # "Player 1 Wins!"
RockPaperScissorsLizardSpock.play(:lizard, :rock) # "Player 1 Wins!"
RockPaperScissorsLizardSpock.play(:lizard, :lizard) # "Draw!"
Example Solution
def beats?(guess1, guess2) do
case {guess1, guess2} do
{:rock, :scissors} -> true
{:rock, :lizard} -> true
{:paper, :rock} -> true
{:paper, :spock} -> true
{:scissors, :paper} -> true
{:scissors, :lizard} -> true
{:lizard, :spock} -> true
{:lizard, :paper} -> true
{:spock, :scissors} -> true
{:spock, :rock} -> true
_answer -> false
end
end
def play(player1, player2) do
cond do
beats?(player1, player2) -> "Player 1 Wins!"
beats?(player2, player1) -> "Player 2 Wins!"
true -> "Draw"
end
end
Implement the RockPaperScissorsLizardSpock
module below.
@doc
syntax runs tests on your code to provide feedback. However, be aware that for the sake of conciseness we do not always write fully comprehensive tests. You solution may pass tests, but be incomplete. You may press the dropdown button to hide the@doc
documentation/tests.
defmodule RockPaperScissorsLizardSpock do
@doc """
## Examples
iex> RockPaperScissorsLizardSpock.beats?(:lizard, :spock)
true
iex> RockPaperScissorsLizardSpock.beats?(:lizard, :paper)
true
iex> RockPaperScissorsLizardSpock.beats?(:spock, :scissors)
true
iex> RockPaperScissorsLizardSpock.beats?(:spock, :rock)
true
iex> RockPaperScissorsLizardSpock.beats?(:spock, :paper)
false
"""
def beats?(guess1, guess2) do
end
@doc """
## Examples
iex> "Player 1 Wins!" = RockPaperScissorsLizardSpock.play(:rock, :lizard)
iex> "Player 2 Wins!" = RockPaperScissorsLizardSpock.play(:lizard, :rock)
iex> "Draw!" = RockPaperScissorsLizardSpock.play(:lizard, :lizard)
"""
def play(player1, player2) do
end
end
DockYard Academy now recommends you use the latest Release rather than forking or cloning our repository.
Run git status
to ensure there are no undesirable changes.
Then run the following in your command line from the curriculum
folder to commit your progress.
$ git add .
$ git commit -m "finish Rock Paper Scissors Lizard Spock exercise"
$ git push
We're proud to offer our open-source curriculum free of charge for anyone to learn from at their own pace.
We also offer a paid course where you can learn from an instructor alongside a cohort of your peers. We will accept applications for the June-August 2023 cohort soon.