Assignment 03 (Due: Monday, March 26, 2018, 11 : 59 : 00PM Central Time)
CSCE 322
1 Instructions
In this assignment, you will be required to write Haskell functions that simplify playing of the variation of basic train Dominoes.
1.1 Data File Specification
An example of properly formatted file is shown in Figure 1. part01test01.doc
(
[
[(9 ,11) ,(3 ,6) ,(1 ,4) ,(2 ,7) ,(7 ,8) ,(3 ,4) ,(6 ,7) ,(9 ,12) ,(7 ,10) ,(2 ,3) ,(0 ,9) ,(1 ,11) ,(5 ,12) ,(0 ,5) ,(3 ,7) ,(2 ,10) ,(4 ,11) ,(1 ,6) ,(2 ,6)
,(9,10)], [(2,5),(6,8),(4,4),(3,8),(2,8),(7,12),(5,9),(4,7),(1,12),(6,11),(1,9),(3,12),(7,9),(4,12),(0,12),(5,8),(6,12),(5,6),(2,2)
,(0,10)],
[(5 ,11) ,(3 ,5) ,(4 ,6) ,(11 ,11) ,(6 ,6) ,(5 ,5) ,(11 ,12) ,(4 ,9) ,(2 ,11) ,(0 ,7) ,(3 ,9) ,(1 ,10) ,(4 ,10) ,(3 ,10) ,(0 ,1) ,(3 ,11) ,(2 ,9) ,(6 ,10)
,(1,3) ,(1,7)],
[(10 ,11) ,(0 ,4) ,(0 ,2) ,(1 ,1) ,(0 ,11) ,(7 ,11) ,(4 ,8) ,(7 ,7) ,(0 ,8) ,(0 ,0) ,(8 ,11) ,(1 ,8) ,(0 ,6) ,(2 ,4) ,(1 ,5) ,(4 ,5) ,(3 ,3) ,(1 ,2) ,(5 ,7)
,(5,10)]
]
,
[
[(2,12) ,(12,12)], [(10,10) ,(10,12)], [(8,8) ,(8,12)], [(8,9),(9,9)]
] )
Figure 1: A properly formatted game encoding
2 One Player, One Move
The first part (onePlayerOneMove in the file csce322Homework03Part01.hs) will take in two (2) arguments (the hand and the train) and returns one (1) value (the train that is the result of the player making one move) . If the hand has already been emptied, or the train cannot be extended, the train is unchanged. Otherwise, like the JavaScript assignment, the train is extended using the following precedence rules.
1. Move from First to Last Domino in Hand
2. Place the Domino as is on the Front of the Train
3. Place the Domino flipped on the Front of the Train 4. Place the Domino as is on the Back of the Train
1
5. Place the Domino flipped on the Back of the Train
(
[
[(9 ,11) ,(3 ,6) ,(1 ,4) ,(2 ,7) ,(7 ,8) ,(3 ,4) ,(6 ,7) ,(9 ,12) ,(7 ,10) ,(2 ,3)
,(0 ,9) ,(1 ,11) ,(5 ,12) ,(0 ,5) ,(3 ,7) ,(2 ,10) ,(4 ,11) ,(1 ,6) ,(2 ,6) ,(9 ,10) ],
[(2,5),(6,8),(4,4),(3,8),(2,8),(7,12),(5,9),(4,7),(1,12),(6,11)
,(1 ,9) ,(3 ,12) ,(7 ,9) ,(4 ,12) ,(0 ,12) ,(5 ,8) ,(6 ,12) ,(5 ,6) ,(2 ,2) ,(0 ,10) ],
[(5 ,11) ,(3 ,5) ,(4 ,6) ,(11 ,11) ,(6 ,6) ,(5 ,5) ,(11 ,12) ,(4 ,9) ,(2 ,11) ,(0 ,7) ,(3 ,9) ,(1 ,10) ,(4 ,10) ,(3 ,10) ,(0 ,1) ,(3 ,11) ,(2 ,9) ,(6 ,10) ,(1 ,3) ,(1 ,7) ],
[(10 ,11) ,(0 ,4) ,(0 ,2) ,(1 ,1) ,(0 ,11) ,(7 ,11) ,(4 ,8) ,(7 ,7) ,(0 ,8) ,(0 ,0) ,(8,11) ,(1,8) ,(0,6) ,(2,4) ,(1,5) ,(4,5) ,(3,3) ,(1,2) ,(5,7) ,(5,10)]
]
,
[
[(2,12) ,(12,12)], [(10,10) ,(10,12)], [(8,8) ,(8,12)], [(8,9),(9,9)]
] )
“Result” “[7|2][2|12][12|12]” “”
Figure 2: Before onePlayerOneMove
Figure 3: After onePlayerOneMove 3 One Player, Many Moves
The second part (onePlayerManyMoves in the file csce322Homework03Part02.hs) will take in two (2) arguments (the hand and the train) and returns one (1) value (the train that is the result of the player making all of moves). If the hand has already been emptied, or the train cannot be extended, the train is unchanged. Otherwise, like the JavaScript assignment, the train is extended using the following precedence rules.
1. Move from First to Last Domino in Hand
2. Place the Domino as is on the Front of the Train
3. Place the Domino flipped on the Front of the Train
Page 2
4. Place the Domino as is on the Back of the Train
5. Place the Domino flipped on the Back of the Train
(
[
[(7,8),(3,4),(2,9),(4,9),(0,7),(1,7),(4,5),(8,9)], [(3,8),(4,8),(0,9),(0,3),(6,7),(4,7),(3,5),(1,4)], [(5,7),(6,6),(7,9),(6,9),(0,6),(1,6),(9,9),(5,6)], [(5,9),(0,2),(1,5),(0,5),(0,1),(2,8),(7,7),(6,8),(2,7),(1,3)], [(1,8),(0,8),(4,6),(0,0),(8,8),(5,8),(2,6),(3,7)]
]
,
[
[(1,2),(2,5),(5,5)],
[(1,1),(1,9),(9,3)],
[(2,2),(2,4),(4,0)],
[(4,4)],
[(2,3),(3,3),(3,6)]
]
)
Figure 4: Before onePlayerManyMoves
“Result” “[2|9][9|8][8|7][7|1][1|2][2|5][5|5][5|4][4|3]” “”
Figure 5: After onePlayerManyMoves 4 Many Players , One Move
The third part (manyPlayersOneMove in the file csce322Homework03Part03.hs) will take in two (2) arguments (the hands and the trains) and returns one (1) value (the trains that are the result of each player making a single move to extend their train). If a hand has already been emptied, or a train cannot be extended, the train is unchanged. Otherwise, like the JavaScript assignment, a train is extended using the following precedence rules.
1. Move from First to Last Domino in Hand
2. Place the Domino as is on the Front of the Train
3. Place the Domino flipped on the Front of the Train 4. Place the Domino as is on the Back of the Train
5. Place the Domino flipped on the Back of the Train
Page 3
(
[
[(4,6),(1,9),(1,8),(0,9),(2,4)], [(3,8),(5,8),(7,7),(0,6),(7,9)], [(1,7),(7,8),(1,1),(2,9),(6,7),(2,3)], [(1,4),(2,8),(5,7),(4,9),(1,5)], [(3,9),(0,5),(6,8),(1,6),(0,1)], [(5,9),(0,2),(4,7),(0,8),(3,5)], [(1,3),(1,2),(0,3),(0,0),(2,7)]
]
,
[
[(3,3),(3,6)],
[(8,9),(9,9)],
[(4,4)],
[(5,6),(6,6)],
[(2,2),(2,6)],
[(4,8),(8,8)],
[(2,5),(5,5)]
]
)
Figure 6: Before manyPlayersOneMove
“Result” “[3|3][3|6][6|4]” “[3|8][8|9][9|9]” “[4|4]” “[7|5][5|6][6|6]” “[2|2][2|6][6|1]” “[7|4][4|8][8|8]” “[1|2][2|5][5|5]” “”
Figure 7: After manyPlayersOneMove 5 Many Players , Many Moves
The fourth part (manyPlayersManyMoves in the file csce322Homework03Part04.hs) will take in two (2) arguments (the hands and the trains) and returns one (1) value (the trains that are the result of each player making as many moves as possible, one-by-one, in order, to extend their train). If a hand has already been emptied, or a train cannot be extended, the train is unchanged. Otherwise, like the JavaScript assignment, a train is extended using the following precedence rules.
1. Move from First to Last Domino in Hand
Page 4
2. Place the Domino as is on the Front of the Train
3. Place the Domino flipped on the Front of the Train 4. Place the Domino as is on the Back of the Train
5. Place the Domino flipped on the Back of the Train
(
[
[(3,7),(1,7),(2,12),(9,12),(5,9),(4,8),(3,10),(1,11)], [(1,3),(0,8),(2,8),(0,6),(8,9),(6,7),(9,11),(5,6),(1,6),(10,12)], [(7,10),(8,10),(2,5),(3,4),(3,12),(1,10),(2,10),(11,12)], [(0,7),(0,5),(4,10),(0,10),(3,6),(11,11),(7,9),(7,7)], [(0,2),(7,11),(0,9),(2,6),(0,1),(12,12),(1,8),(9,9),(4,12)], [(0,4),(5,12),(1,12),(7,12),(4,7),(0,0),(0,11),(4,9),(4,6),(5,11)], [(6,12),(3,11),(6,10),(2,7),(7,8),(8,11),(5,10),(1,9)], [(2,11),(3,9),(0,12),(6,9),(4,5),(9,10),(5,7),(2,4)]
]
,
[
[(6,6) ,(6,8) ,(8,12)],
[(4,4)],
[(2,2),(2,3),(3,8)],
[(1,1),(1,2),(2,9)],
[(3,5),(5,5)],
[(3,3)],
[(10,10) ,(10,11) ,(11,6)],
[(1,5),(5,8),(8,8)]
]
)
Figure 8: Before manyPlayersManyMoves
“Result”
“[6|6][6|8][8|12][12|2]”
“[4|4]”
“[5|2][2|2][2|3][3|8]” “[1|1][1|2][2|9][9|7][7|0]” “[3|5][5|5]”
“[3|3]” “[12|6][6|10][10|10][10|11][11|6]” “[1|5][5|8][8|8]”
“”
Figure 9: After manyPlayersManyMoves
Page 5
6 Naming Conventions
Your files should follow the naming convention of
csce322Homework03Part01.hs, csce322Homework03Part02.hs, csce322Homework03Part03.hs, and csce322Homework03Part04.hs.
6.1 Helpers.hs
A file named Helpers.hs has been provided with the functionality to read the .doc files into matrices. If a modified Helpers.hs file is not included with your submission, the default will be used in its place.
7 webgrader Note
Submissions will be tested with ghc. cse.unl.edu is currently running version 7.10.3 of ghc. If you would like to test things offline, you can load a file in ghci with the command :l filename.hs and run the main method on a given file with the command :main “/path/to/inputfile.bff”
8 Point Allocation
Component |
Points |
csce322Homework03Part01.hs Compilation Test Cases Total |
10 1×10 20 |
csce322Homework03Part02.hs Compilation Test Cases Total |
10 1×10 20 |
csce322Homework03Part03.hs Compilation Test Cases Total |
10 1×20 30 |
csce322Homework03Part04.hs Compilation Test Cases Total |
10 1×20 30 |
Total |
100 |
9 External Resources
Learn Haskell Fast and Hard
Learn You a Haskell for Great Good!
Red Bean Software
Functional Programming Fundamentals The Haskell Cheatsheet
Page 6