Assignment No. 7 EECS 368 Programming Language Paradigms

Original price was: $35.00.Current price is: $30.00.

5/5 - (2 votes)

Assignment No. 7
EECS 368
Programming Language Paradigms

Submit deliverables in a single zip file to Canvas
Name of the zip file: FirstnameLastname_Assignment7 (with your first and last name)
Name of the Assignment folder within the zip file: FirstnameLastname_Assignment7
1. Copy of Rubric7.docx with your name and ID filled out (do not submit a PDF)
2. Haskell script file(s).
3. Screen print of playing nim one time. It doesn’t matter which player wins. (Copy
and paste the output to a Word document and PDF it).
• Implement the game of nim in Haskell, where the rules of the game are as
o The initial board comprises five rows of stars:
o Two players take turns removing one or more stars from the end of a
single row.
o The winner is the player who removes the last star or stars from the board.
• Define:
type Board = [Int]
initial :: Board
initial = [5,4,3,2,1]
• Implement a recursive main game loop which takes the current board and player
number as arguments: play :: Board -> Int -> IO()
• The main game loop should:
o First display the board.
o Then check if the game is finished
o If so, then display the other player as the winner as they are the one who
made the board empty.
o Otherwise, prompt the current player for the move they wish to make with
the following prompts:
Player – followed by the player number
Enter a row number:
Stars to remove:
o If the move is valid, update the board accordingly, display it, and then
continue the game with next player.
1: * * * * *
2: * * * *
3: * * *
4: * *
5: *
o Otherwise display an error message, re-display the board, and re-prompt
the current player to enter a valid move.
o Each board display, player prompts display, and winner display should be
proceeded by a newline. For example:
> nim
1: * * * * *
2: * * * *
3: * * *
4: * *
5: *
Player 1
Enter a row number: 1
Stars to remove: 4
1: *
2: * * * *
3: * * *
4: * *
5: *
Player 2
Enter a row number: 6
Stars to remove: 1
ERROR: Invalid move (This can be any error message, not this one
• Invoke the game nim itself by invoking the game loop with the initial board and
player number:
nim :: IO ()
nim = play initial 1
• Hint: do all the IO in the main “play” function; segregate purely IO functions
(e.g., putChar) from purely functional functions (e.g., check validity of board).
• Provide comments for the Haskell code that explain what each line of code is
doing. See rubric below.
Rubric for Program Comments
Exceeds Expectations
Meets Expectations
Software is adequately
commented with prologue
comments, comments
summarizing major blocks of
code, and comments on every
Prologue comments are present
but missing some items or some
major blocks of code are not
commented or there are
inadequate comments on each
Prologue comments are missing
all together or there are no
comments on major blocks of
code or there are very few
comments on each line.
Adequate Prologue Comments:
• Name of program contained in the file (e.g., EECS 368 Assignment 6 – replicate)
• Brief description of the program, e.g.:
o Haskell function for replicate
• Inputs,e.g.,:
o Number of replications
o Element to replicate
• Output, e.g.,
o List of replicated elements
• Author’s full name
• Creation date: The date you first create the file, i.e., the date you write this
Adequate comments summarizing major blocks of code and comments on every line:
• Provide comments that explain what each line of code is doing.
• You may comment each line of code (e.g., using –) and/or provide a multi-line
comment (e.g., using {- and -}) that explains what a group of lines does.
• Multi-line comments should be detailed enough that it is clear what each line of
code is doing.
• Your Programming Assignments are individual-effort.
• You can brainstorm with other students and help them work through problems in
their programs, but everyone should have their own unique assignment programs.

Scroll to Top