I got some help from my tutor, which didn't help that much. Perhaps you can help explain it?
---------------------------------------
> Let's say for the newGame function...you've got:
>
> newGame pls ans = CdG pls ans
>
> What am I meant to put to finish the function off? As in, what am I meant
> to be doing exactly?
First of all, you will need to set up your 'CludeoGame' data type.
Somewhere in your code, you will have something like:
data CludeoGame = CdG (???)
First of all, notice the name "CdG". It is useless. Replace it with
something more usefull. ("CludeoGameADT", perhaps?)
After the name of your data-type, you must specify what information you
need to store between turns. By default, you have:
data CluedoGame = CdG [(Player,[Card])] Triple
This means you are specifying that your CludeGame data-type will store a
list of players and the cards the are holding, as well as the solution.
You may wish to store other information as well, such as whose turn it
currently is and/or perhaps what happened in the last turn.
For debugging purposes, you will also certainly want to add the line:
data CluedoGame = CdG [(Player,[Card])] Triple
deriving (Show, Eq, Read)
'newGame' basically just sets up your CludeoGame data type, and returns
it to 'Cludeo.hs'. Cludeo.hs will then repeatably call 'step', giving
'step' your data-type, and getting a new one.
newGame :: [(Player,[Card])] -> Triple -> CluedoGame
newGame pls ans = CdG pls ans
All 'newGame' in its current format does is get the list of players and
cards, get the solution, and shove them into the default (insufficient)
CludeoGame data type.
So the code is basically saying:
newGame pls ans = CdG pls ans
^ ^ ^
| | |
| | +-- Create a new data-type 'CdG' (which is a
| | CludeoGame) and set its values to 'pls' and
| | 'ans'.
| |
| +---- Save the answer in the variable 'ans'
|
|
+-------- Save the players in the variable 'pls'
> What am I meant to put to finish the function off? As in, what am I meant
> to be doing exactly?
So, to answer your question, you must:
1. Define your own CludeoGame data-type. (Or just modify the current
one)
2. Change 'newGame' so it sets up and returns your CludeoGame data-type
in a state ready to given to 'step'.
> So basically what I need to do for newGame is to store all the details for
> all the players? e.g. Roland has cards K17,David,Mouse,Matthews,BFG
> and Kheng has cards Sara,Keyboard,Clancy etc... ?
Correct. As well as any other information you need to keep the game
running. (For example, you might want to remember that player "Bob" made
an accusation and was wrong, so he is out of the game, and that it is
Alice's turn next.)
> newGame :: [(Player,[Card])] -> Triple -> CluedoGame
This is the function signature. It is written in the spec. You can not
change it.
> newGame pls ans = CluedoGameADT pls ans
This is the line of code you need to rewrite.
Perhaps an example is in order.
Lets say I have a data-type 'Car':
type NumberPlate = String
type KilometersTravelled = Int
type CarAccidents = Int
type PedestriansHit = Int
data Car = CarADT NumberPlate KilometersTravelled CarAccidents PedestriansHit
I could then write a function, 'newCar':
newCar :: NumberPlate -> Car
newCar plateNumber
= CarADT plateNumber 0 0 0
I could then write some functions to do things to my car:
getNumberPlate :: Car -> NumberPlate
getNumberPlayer (CarADT plateNumber _ _ _)
= plateNumber
hitPedestrian :: Car -> Car
hitPedestrian (CarADT plateNumber kmTravelled accidents pedestriansHit)
= (CarADT plateNumber kmTravelled accidents (pedestriansHit + 1))
(And so on)
Basically, all 'newCar' does is creates a Car data-type which can then
be used in my other functions.
All 'newGame' does is creates a 'CludeoGame' data-type which can then
be used in Cludeo's other functions, such as 'step'.
-------------------------------------------------------------