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 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 3 x 3 empty room with a tree in the middle: mapBuilder (\x -> case x of 'T' -> Left TreeA; -> Left None) example , "-T-" = (Char -> Either MapItem a)-> [String] -> Room a - (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 12 x 12 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.js which should give you a view like: Energy: Score: 0 Inventory:
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 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 3 x 3 empty room with a tree in the middle: mapBuilder (\x -> case x of 'T' -> Left TreeA; -> Left None) example , "-T-" = (Char -> Either MapItem a)-> [String] -> Room a - (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 12 x 12 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.js which should give you a view like: Energy: 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
Related questions
Question
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
Knowledge Booster
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.Recommended textbooks for you
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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education