ock-paper-scissors is a game for two players. Each player chooses an action without knowledge of the other’s choice. If the players choose the same action then there is a draw. Otherwise the winner is determined by the following rules: paper beats rock, rock beats scissors, and scissors beats paper. you are going to make a playable Rock-Paper-Scissors game and consider multiplayer tournaments. • Please make it a single Haskell file  • Please put comments in your code to show which question you are answering with each piece of code.  • You may create auxiliary functions if you like. You may use library functions from Haskell’s standard library. • Please limit your line lengths to 100 characters max. Please use the following two data types which you can copy-and-paste into your code. data Action = Rock | Paper | Scissors deriving (Eq, Show) data Outcome = Player1Win | Player2Win | Draw deriving Show Action represents a player’s chosen action and Outcome represents the outcome of playing a game

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter13: Overloading And Templates
Section: Chapter Questions
Problem 15SA
icon
Related questions
Question

Rock-paper-scissors is a game for two players. Each player chooses an action without knowledge of
the other’s choice. If the players choose the same action then there is a draw. Otherwise the winner
is determined by the following rules: paper beats rock, rock beats scissors, and scissors beats paper. you are going to make a playable Rock-Paper-Scissors game and consider multiplayer tournaments.



• Please make it a single Haskell file 
• Please put comments in your code to show which question you are answering with each piece of
code. 
• You may create auxiliary functions if you like. You may use library functions from Haskell’s
standard library.
• Please limit your line lengths to 100 characters max.
Please use the following two data types which you can copy-and-paste into your code.
data Action = Rock | Paper | Scissors deriving (Eq, Show)
data Outcome = Player1Win | Player2Win | Draw deriving Show
Action represents a player’s chosen action and Outcome represents the outcome of playing a game

- If the input is invalid then print out the outcome of the whole game (see above).
-If the input is valid then check to find out who is the winner and print an appropriate
message, then recurse with the updated tally of player 1 and player 2 wins.
Transcribed Image Text:- If the input is invalid then print out the outcome of the whole game (see above). -If the input is valid then check to find out who is the winner and print an appropriate message, then recurse with the updated tally of player 1 and player 2 wins.
1. Define a function check :: Action -> Action -> Outcome which calculates the outcome of a
game where the first argument is the action of player 1 and the second argument is the action of
player 2.
For example, check Rock Paper
Player2Win and check Paper Paper = Draw.
2. Define a function parse :: String -> Maybe Action which will be used to parse user input for
the choice of an action. Return Nothing if the input string is not valid, otherwise parse strings
into actions based solely on the first letter, e.g., parse "P" = Just Paper.
=
3. Recall the I/O functions in Haskell for inputting a string from the user and outputting a string to
the console:
getLine :: IO String
putStrLn :: String -> IO ()
Define a recursive function play :: Integer -> Integer -> 10 () which takes two inputs:
the number of wins so far for player 1 and the number of wins so far for player 2. The game should
proceed as follows:
• Print a message asking player 1 to make an action;
• Read input from the user and parse it;
• If the input is invalid according to the parser, print out the outcome of the game, i.e., who had
the most wins and is therefore the overall winner, or whether overall it is a draw, and then
return.
• If the input is valid then:
- Print a message asking player 2 to make an action;
Read input from the user and parse it;
Transcribed Image Text:1. Define a function check :: Action -> Action -> Outcome which calculates the outcome of a game where the first argument is the action of player 1 and the second argument is the action of player 2. For example, check Rock Paper Player2Win and check Paper Paper = Draw. 2. Define a function parse :: String -> Maybe Action which will be used to parse user input for the choice of an action. Return Nothing if the input string is not valid, otherwise parse strings into actions based solely on the first letter, e.g., parse "P" = Just Paper. = 3. Recall the I/O functions in Haskell for inputting a string from the user and outputting a string to the console: getLine :: IO String putStrLn :: String -> IO () Define a recursive function play :: Integer -> Integer -> 10 () which takes two inputs: the number of wins so far for player 1 and the number of wins so far for player 2. The game should proceed as follows: • Print a message asking player 1 to make an action; • Read input from the user and parse it; • If the input is invalid according to the parser, print out the outcome of the game, i.e., who had the most wins and is therefore the overall winner, or whether overall it is a draw, and then return. • If the input is valid then: - Print a message asking player 2 to make an action; Read input from the user and parse it;
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Constants and Variables
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning