Starting from:
$30

$24

Assignment 02 Solution

Instructions



In this assignment, you will be required to write Haskell functions that simplify playing of the variation of Connect Four.




1.1 Data File Speci cation




An example of properly formatted le is shown in Figure 1.




test03.cnf




(




[




- - - - - -" ,



- - - - - -" ,



- - - - - -" ,



- - - - - -" ,



- - - - - -" ,



- - - - - -" ,



- - - - - -" ,



- - - - -2" ,



-12 - -3" ,



-132 -2"



]




,




[1 ,4 ,4 ,3 ,4 ,5 ,3 ,6 ,5 ,2 ,4 ,5 ,5 ,2 ,4 ,3 ,6 ,2 ,6 ,1 ,1 ,1 ,5 ,4 ,3 ,5 ,6 ,3 ,6 ,6 ,2 ,3 ,4 ,4 ,4 ,6 ,1 ,5 ,4 ,




)




Figure 1: A properly formatted encoding




One Player, One Move



The rst part (onePlayerOneMove in the le csce322assignment03part01.hs) will take in two




arguments (a game and a move) and returns the game that is the result of Player 1 dropping a 1 into the column of the game denoted by the move. The 1 should fall (move down through the -'s in the column) until it reaches a space that is not - or reaches the last row in the game. An example is provided below



1



test03.cnf




(




[




- - - - - -" ,



- - - - - -" ,



- - - - - -" ,



- - - - - -" ,



- - - - - -" ,



- - - - - -" ,



- - - - - -" ,



- - - - -2" ,



-12 - -3" ,



-132 -2"



]




,




[1 ,4 ,4 ,3 ,4 ,5 ,3 ,6 ,5 ,2 ,4 ,5 ,5 ,2 ,4 ,3 ,6 ,2 ,6 ,1 ,1 ,1 ,5 ,4 ,3 ,5 ,6 ,3 ,6 ,6 ,2 ,3 ,4 ,4 ,4 ,6 ,1 ,5 ,4 ,




)




test03.onePlayerOneMove.solution




" Result "




" - - - - - -"




" - - - - - -"




" - - - - - -"




" - - - - - -"




" - - - - - -"




" - - - - - -"




" - - - - - -"




- - - - -2"



-12 - -3" "1132 -2"



""







One Player, Many Moves



The second part (onePlayerManyMoves in the le csce322assignment03part02.hs) will take in two (2) arguments (a game and a list of moves) and returns the game that is the result of Player 1 playing each move in succession (following the rules of onePlayerOneMove) until all of the moves in the array have been played, or Player 1 has placed four (4) 1's in a row horizontally, vertically, or diagonally.




test03.cnf




(




[




- - - - - -" ,



- - - - - -" ,



- - - - - -" ,






Page 2



- - - - - -" ,



- - - - - -" ,



- - - - - -" ,



- - - - - -" ,



- - - - -2" ,



-12 - -3" ,



-132 -2"



]




,




[1 ,4 ,4 ,3 ,4 ,5 ,3 ,6 ,5 ,2 ,4 ,5 ,5 ,2 ,4 ,3 ,6 ,2 ,6 ,1 ,1 ,1 ,5 ,4 ,3 ,5 ,6 ,3 ,6 ,6 ,2 ,3 ,4 ,4 ,4 ,6 ,1 ,5 ,4 ,




)




test03.onePlayerManyMoves.solution




" Result "




" - - -
- - -"
" - - -
- - -"
" - - -
- - -"
" - - -
- - -"
" - - -
- - -"
" - - -
- - -"
" - - -
1 - -"



- -11 -2"



-121 -3" "1132 -2"



""







Many Players , One Move



The third part (manyPlayersOneMove in the le csce322assignment03part03.hs) will take in two




arguments (a game and a list of moves) and returns the game that is the result of each player in the game making exactly one move until each player has completed a move or a player has won the game (placed four of their pieces vertically, horizontally, or diagonally). Player 1 places 1s, Player 2 places 2s, etc. (you may assume the highest number in the provided game is the number of players in the game). The moves are made in the order they appear in the moves array.



test03.cnf




(




[




- - - - - -" ,



- - - - - -" ,



- - - - - -" ,



- - - - - -" ,



- - - - - -" ,



- - - - - -" ,



- - - - - -" ,



- - - - -2" ,






Page 3



-12 - -3" ,



-132 -2"



]




,




[1 ,4 ,4 ,3 ,4 ,5 ,3 ,6 ,5 ,2 ,4 ,5 ,5 ,2 ,4 ,3 ,6 ,2 ,6 ,1 ,1 ,1 ,5 ,4 ,3 ,5 ,6 ,3 ,6 ,6 ,2 ,3 ,4 ,4 ,4 ,6 ,1 ,5 ,4 ,




)




test03.manyPlayersOneMove.solution




" Result "




" - - - - - -"




" - - - - - -"




" - - - - - -"




" - - - - - -"




" - - - - - -"




" - - - - - -"




" - - - - - -"




- - -3 -2"



-122 -3" "1132 -2"



""







Many Players , Many Moves



The fourth part (manyPlayersManyMoves in the le csce322assignment03part04.hs) will take in two (2) arguments (a game and a list of moves) and returns the game that is the result of each player in the game taking turns making a move until all of the moves in the array have been exhausted or a player has won the game (placed four of their pieces vertically, horizontally, or diagonally). Player 1 places 1s, Player 2 places 2s, etc. (you may assume the highest number in the provided game is the number of players in the game).




test03.cnf




(




[




- - - - - -" ,



- - - - - -" ,



- - - - - -" ,



- - - - - -" ,



- - - - - -" ,



- - - - - -" ,



- - - - - -" ,



- - - - -2" ,



-12 - -3" ,



-132 -2"



]




,













Page 4



[1 ,4 ,4 ,3 ,4 ,5 ,3 ,6 ,5 ,2 ,4 ,5 ,5 ,2 ,4 ,3 ,6 ,2 ,6 ,1 ,1 ,1 ,5 ,4 ,3 ,5 ,6 ,3 ,6 ,6 ,2 ,3 ,4 ,4 ,4 ,6 ,1 ,5 ,4 ,




)




test03.manyPlayersManyMoves.solution




" Result "




" - - -
- - -"
" - - -
- - -"
" - - -
- - -"
" - - -
3 - -"



- -13 -1"



-31222" "121212" "311332" "212233" "113232"



""







Extra Credit (10%)



Games will contain an arbitrary number of players.




Naming Conventions



Your les should follow the naming convention of




csce322assignment03part01.hs, csce322assignment03part02.hs, csce322assignment03part03.hs, and csce322assignment03part04.hs.




7.1 Helpers.hs




A le named Helpers.hs has been provided with the functionality to read the .cnf les into lists. If a modi ed Helpers.hs le is not included with your submission, the default will be used in its place.










webgrader Note



Submissions will be tested with ghc. cse.unl.edu is currently running version 8:0:2 of ghc.




Point Allocation



10 External Resources




Learn Haskell Fast and Hard




Learn You a Haskell for Great Good!




Red Bean Software




Functional Programming Fundamentals The Haskell Cheatsheet










Page 5

























































Component
Points








csce322assignment03part01.hs


Compilation
10
Test Cases
1 10
Total
20




csce322assignment03part02.hs


Compilation
10
Test Cases
1 10
Total
20




csce322assignment03part03.hs


Compilation
10
Test Cases
1 20
Total
30




csce322assignment03part04.hs


Compilation
10
Test Cases
1 20
Total
30








Total
100






































































Page 6

More products