Question: Haskell question. (3 marks) 1. As a warmup (and a useful function for later) define a function opposite which computes a direction's opposite, e.g., opposite

Haskell question.

Haskell question. (3 marks) 1. As a warmup (and a useful function

(3 marks) 1. As a warmup (and a useful function for later) define a function opposite which computes a direction's opposite, e.g., opposite North = South. Include the type signature. (3 marks) 2. In order to construct a Room an "action" value is needed which describes how a player can use an item in a room, possibly changing the game state. This is represented by function of type Item -> GameState -> Next GameState. Define a simple such function which can be used for a room's actions field, of type: noActions :: Item -> GameState -> Next GameState to represent a lack of actions in a room. Thus noActions should return a Same value with a message that there is nothing that can be done with the item given (you can use show on an Item 3. Define a winning room (has isWinRoom value as True) which requires a key to enter, has (4 marks) no items or monster or further doors, and no actions (use the function you defined above). 4. Define a starting room for your player from which the winRoom can be accessed and which (5 marks) has a spoon as one of its items (and no actions). This starting room should lead off to another room defined in the next question. 5. Define a room leading from the previous containing a wood troll with health 10 who holds a (12 marks) Key. Implement an "action" function which on a Spoon input checks if the room (provided by the GameState parameter) has a monster: If no monster, indicate (via Same) that we stay in the same state, giving an appro- priate message. If there is a monster, we will attack it with the spoon (which deals 5 damage). If the monster has health less than or equal to 5 before we attack then this action will kill it, so return a next game state where the monster is no longer present (not in the list) and the item it was holding is now put into the room's items. If the monster has > 5 health, update the monster's health in the room to be 5 less. Include appropriate messages. 6. Define game as an initial GameState pointing to your start room and with a player who (3 marks) has an empty inventory. (3 marks) 1. As a warmup (and a useful function for later) define a function opposite which computes a direction's opposite, e.g., opposite North = South. Include the type signature. (3 marks) 2. In order to construct a Room an "action" value is needed which describes how a player can use an item in a room, possibly changing the game state. This is represented by function of type Item -> GameState -> Next GameState. Define a simple such function which can be used for a room's actions field, of type: noActions :: Item -> GameState -> Next GameState to represent a lack of actions in a room. Thus noActions should return a Same value with a message that there is nothing that can be done with the item given (you can use show on an Item 3. Define a winning room (has isWinRoom value as True) which requires a key to enter, has (4 marks) no items or monster or further doors, and no actions (use the function you defined above). 4. Define a starting room for your player from which the winRoom can be accessed and which (5 marks) has a spoon as one of its items (and no actions). This starting room should lead off to another room defined in the next question. 5. Define a room leading from the previous containing a wood troll with health 10 who holds a (12 marks) Key. Implement an "action" function which on a Spoon input checks if the room (provided by the GameState parameter) has a monster: If no monster, indicate (via Same) that we stay in the same state, giving an appro- priate message. If there is a monster, we will attack it with the spoon (which deals 5 damage). If the monster has health less than or equal to 5 before we attack then this action will kill it, so return a next game state where the monster is no longer present (not in the list) and the item it was holding is now put into the room's items. If the monster has > 5 health, update the monster's health in the room to be 5 less. Include appropriate messages. 6. Define game as an initial GameState pointing to your start room and with a player who (3 marks) has an empty inventory

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!