The first task is to create an initial version of the game configuration with an empty room. (a) Define a function to generate square empty rooms (containing just grass) of an arbitrary size. That is, for an integer parameter n, generate a value of type Room () representing a room of size nx n containing just grass, i.e., a list of length n containing lists of length n containing the map item None. The action item type here is just (), i.e., we are not giving any action items yet. (b) Define a variable init GameConfig of type GameConfig () which should contain an empty room of size 10 x 10 associated to the name "start" and a trivial actions function that always produces the Null JavaScript value, i.e., there are no actions items to compile functionality for. (c) Define a value q1 that applies output Config to your answer to (b) and with a function that just outputs the empty string for the action item names (since there aren't any yet). Evaluating q1 should generate config.js which should give you a view as follows in the game: Energy: I Score: 0 Inventory:

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Lambda Run is a game in which a plucky red panda (“Lambda”) tries to find their way home through a pleasant land of grass, trees, and rocks, but who quickly gets tired. Can Lambda make it home to Haskell the Ultimate before running out of energy? Fortunately there are tasty chocolate snacks along the way to keep Lambda going, but a number of keys need to be found to open doors, making the way yet more perilous. Can Lambda find enough chocolate to sustain their journey home to Haskell? The game is written in Haskell and JavaScript (with a little HTML/CSS for the front end). Your goal is to complete the implementation of the Haskell component which generates a JavaScript file providing the game data and JavaScript functions to implement the behaviour of various in-game items. You control the game using the arrow keys as input to navigate the map. 

Download pack.zip which provides: • frontend directory – the frontend HTML/JS/CSS parts of the game, which you do not need to look at or understand. • game.html – the entry point for playing the game. • config.js – This is the file that your Haskell code will generate to provide the remaining functionality and setup for the game. In pack.zip, a configuration is provided as generated from a model solution that you might like to try to emulate. (Since your code will re-generate config.js you will probably want to make a copy of the provided one otherwise it will be overwritten). • Two Haskell modules (Game.hs and JavaScript.hs) that give the scaffolding for your work. You should read the documentation in these files to understand what is provided. The Game module provides core data representations and functions for the game. The key types are: data MapItem = ... data KeyColor = ... type Room items = [[Either MapItem items]] type RoomId = String data GameConfig items = GameConfig { rooms :: [(RoomId, Room items)] , actions :: (items -> JSExpr) , actionItems :: [items] } - The MapItem data type represents items on the map that are largely inert (trees, rocks, etc.) which you do not need to implement the behaviour of. The KeyColor data type enumerates three colours for keys, though note that MapItem doesn’t represent keys (you will implement this later). - The Room type synonym defines a game room as a list of lists, whose elements represent squares (“cells”) of the game and are either MapItem or of some parametric type items which will be the type of action items in the game and which you will later specialise with your own data type for action items. - The name of a room is just a string, given by the type synonym RoomId. - The GameConfig data type (shown in full here) has three arguments: (i) an association list between room names and Room representations; (ii) a compilation function that maps action items to a JavaScript expression syntax tree JSExpr which describes a transformation on player data if Lambda walks over this kind of item; (iii) a list of action items that we want to compile JS functions for as given by (ii). The Game module then provides a key function which you will use in your work: outputConfig :: GameConfig items -> (items -> String) -> IO () Given a (GameConfig items) value, i.e., a game configuration with action items of type items, and a function that computes a CSS class name (as a string) for those items, then outputConfig compiles everything to JavaScript and writes config.js for the game to be played via game.html. The JavaScript module This module defines an AST representation of a subset of JavaScript code, with a representation of JavaScript expressions JSExpr, JavaScript statements JSStmt, and JavaScript code blocks JSBlock. Read the code documentation to see which data constructors are provided and what these map onto as JavaScript code. You can always generate your own AST fragements to experiment and use the corresponding compileExpr :: JSExpr -> String, compileStmt :: JSStmt -> String and compileBlock :: JSBlock -> String functions to see what JavaScript code is produced.

The first task is to create an initial version of the game configuration with an empty room.
(a) Define a function to generate square empty rooms (containing just grass) of an arbitrary size.
That is, for an integer parameter n, generate a value of type Room () representing a room of size
n x n containing just grass, i.e., a list of length n containing lists of length n containing the map
item None. The action item type here is just (), i.e., we are not giving any action items yet.
(b) Define a variable initGameConfig of type GameConfig () which should contain an empty room
of size 10 x 10 associated to the name "start" and a trivial actions function that always produces
the Null JavaScript value, i.e., there are no actions items to compile functionality for.
(c) Define a value q1 that applies output Config to your answer to (b) and with a function that just
outputs the empty string for the action item names (since there aren't any yet).
Evaluating q1 should generate config.js which should give you a view as follows in the game:
Energy: I
Score: 0
Inventory:
Transcribed Image Text:The first task is to create an initial version of the game configuration with an empty room. (a) Define a function to generate square empty rooms (containing just grass) of an arbitrary size. That is, for an integer parameter n, generate a value of type Room () representing a room of size n x n containing just grass, i.e., a list of length n containing lists of length n containing the map item None. The action item type here is just (), i.e., we are not giving any action items yet. (b) Define a variable initGameConfig of type GameConfig () which should contain an empty room of size 10 x 10 associated to the name "start" and a trivial actions function that always produces the Null JavaScript value, i.e., there are no actions items to compile functionality for. (c) Define a value q1 that applies output Config to your answer to (b) and with a function that just outputs the empty string for the action item names (since there aren't any yet). Evaluating q1 should generate config.js which should give you a view as follows in the game: Energy: I Score: 0 Inventory:
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Linked List Representation
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education