HASKELL PROGRAMMING LANGUAGE QUESTION PLEASE   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 put comments in your code to show what 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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

HASKELL PROGRAMMING LANGUAGE QUESTION PLEASE

 

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 put comments in your code to show what 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

 

QUESTION ATTACHED AS IMAGE

- 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.
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.
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.
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 -> 10 ()
Define a recursive function play :: Integer -> Integer -> IO () 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 e 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: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. 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. 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 -> 10 () Define a recursive function play :: Integer -> Integer -> IO () 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 e 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
Unreferenced Objects
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education