Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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,

image text in transcribedimage text in transcribed

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? Fortumately 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. Provided code and scaffolding Download pack. zip from the Moodle 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: - 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 Roon 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 RoonId. - The GameConf1g 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: 2 Map builder (25 marks) The second task is to build some helper functions to make it easier to create interesting rooms in the game. The idea will be that you can define a map via a list of strings with characters standing in for items in the game, and then having a function translate this into the Room representation. (a) Define a function of polymorphic type: mapBuilder : (Char Either MapItem a) [String] Room a that takes as input a function for mapping characters into the representation of either a map item or an action item a, and takes a further input which is a list of strings to then convert into a Room, using the first function, e.g., each string in the list defines a row of the room map. For example, the following would generate a 33 empty room with a tree in the middle: example = mapBuilder (\x case x of ' T ' Left TreeA ; - Left None ) [ "---" ,"-T-" ,"--"] (b) Define a function converting characters to MapItem values for each possible data constructor, with suitable choices of character for each. For doors, you can construct doors with no target and no requirements. (c) This generates maps that can get quite dense so we will define a function for "dilating" a map by doubling its size by adding empty columns and rows. (i) Define a function a [a][a] that produces a list double the size of the input list by inserting the first input after every element, e.g. expand '-' "HDT" "H-D-T-". Define this using foldr for full marks (otherwise max 3 marks). (ii) Using your answer to the above, define a function dilate : : Room a Room a that insert an empty cell between each cell and an empty row between each row such that the output room is twice as wide and twice as high as the input room. (d) Putting this all together, define a new map of size 1212 by using dilate and mapBuilder with your answer to (b). Include a good selection of trees and rocks of different types, and a "home" square in the top-left. You need not include any doors yet. Define q2 to generate an output configuration from your new map (where, as in q1, you can use a function that just outputs Null for action compilation and a function that just outputs empty string for action item class names since we haven't specified any yet). Evaluating q2 should generate config. j s which should give you a view like

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 1 Lnai 9284

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Carlos Soares ,Joao Gama ,Alipio Jorge

1st Edition

3319235273, 978-3319235271

More Books

Students also viewed these Databases questions