1. Homepage
  2. Programming
  3. EEEN10036 C Programming Assignment: Escape From Island

EEEN10036 C Programming Assignment: Escape From Island

Engage in a Conversation
ManchesterEEEN10036C ProgrammingEscape From IslandC

Introduction CourseNana.COM

The purposes of the coursework part of the course are:  CourseNana.COM

1.     To give a slightly longer programming exercise than that which can be undertaken in a standard lab session.  CourseNana.COM

2.     To give a more open-ended programming task. That is, a task with an overall aim and set of requirements, and then freedom for you as a programmer to devise the most appropriate solution. Depending on coding style, a complete solution likely requires 200-400 lines of code.  CourseNana.COM

3.     To provide summative feedback on your work and performance, completing the formative feedback from the labs. CourseNana.COM

Aim CourseNana.COM

Objective  CourseNana.COM

The objective of this assignment is to write a C program which estimates the probability that an explorer will safely escape from a dinosaur- and volcano-infested island ("Jurassic Island") by taking random walks across it. As well as calculating the probability of escape, the mean and standard deviation of the path lengths should be determined for each starting cell.  CourseNana.COM

Island map  CourseNana.COM

The island map is represented as a 9x9 array:   CourseNana.COM

B W W B B W B W W  CourseNana.COM

B L L V L L L L B  CourseNana.COM

W L L L L D L L B  CourseNana.COM

B L L D L L L L W  CourseNana.COM

B L D L L L L L W  CourseNana.COM

W L L L L L V L B  CourseNana.COM

W V L L L L L L W  CourseNana.COM

W L L L D L L L W  CourseNana.COM

B B W B W B B W B  CourseNana.COM

where each cell is labelled as follows:  CourseNana.COM

·       L: Land, the explorer can safely step on this cell.  CourseNana.COM

·       B: Bridge, the explorer can safely step on this cell and use it to get off the island.  CourseNana.COM

·       W: Water, the explorer will die if this cell is stepped on.  CourseNana.COM

·       D: Dinosaur, the explorer will die if this cell is stepped on.  CourseNana.COM

·       V: Volcano, the explorer will die if this cell is stepped on.   CourseNana.COM

Note that there is a space between each letter in the island map and no space at the end of the line. Also, this is not the same map as that used in the task itself.   CourseNana.COM

  CourseNana.COM

The only way to escape from the island is for the explorer to step onto a Bridge (B) cell.   CourseNana.COM

Stepping onto a Land (L) cell is safe, however if the explorer steps on a Dinosaur (D), Volcano (V), or Water (W) cell, the walk is terminated and the next random walk should be attempted.   CourseNana.COM

  CourseNana.COM

  CourseNana.COM

Task  CourseNana.COM

Each cell in the map is to be used as a starting point for walks, beginning, for example, with the B cell at the top-left corner (i.e. [0][0] in a 2D array representing the island map).   CourseNana.COM

  CourseNana.COM

For each cell on the map, the program should perform 1000 random walks where the explorer attempts to get off the island.   CourseNana.COM

  CourseNana.COM

On each attempt, the explorer can take up to, and including, 10 steps before they run out of energy and the walk terminates unsuccessfully, moving on to the next attempt.   CourseNana.COM

  CourseNana.COM

Each step on a walk is randomly chosen from one of eight directions, i.e. North (N), Northeast (NE), East (E), Southeast (SE), South (S), Southwest (SW), West (W), or Northwest (NW), with equal probability.  CourseNana.COM

  CourseNana.COM

After each step, the program should check to see if the walk:  CourseNana.COM

·       Is successful by stepping onto a Bridge cell.  CourseNana.COM

·       Has failed by stepping onto a Dinosaur, Volcano or Water cell.  CourseNana.COM

·       Continues by stepping onto a Land cell.   CourseNana.COM

·       Has failed due to the maximum number of steps being taken.  CourseNana.COM

  CourseNana.COM

For example, assuming that the explorer is near the top-left, at location [1][1] (ignoring the spaces) which is a Land (L) cell. If the next step is to the NW or E they will have stepped on a Bridge cell (B) and so will have escaped from the island successfully. If the next step is to E, SE, or S, then they have moved to another Land (L) cell and the walk should continue for another step. However, if the next step is to N, NE, or SW then the explorer lands on a Water (W) cell and the walk terminates unsuccessfully.  CourseNana.COM

Requirements CourseNana.COM

Inputs  CourseNana.COM

Your program should read a 9x9 island map from a text file, stored in the same directory as your program, called "island_map.txt".  CourseNana.COM

  CourseNana.COM

  CourseNana.COM

Input validation  CourseNana.COM

We will compile and execute your code, using unseen maps to check the behaviour. This will include passing invalid inputs to your code. You should add input validation checks to your code, anticipating the different ways in which a user may provide an incorrect input.  CourseNana.COM

  CourseNana.COM

If your code detects an error with the input it should display:  CourseNana.COM

Error!  CourseNana.COM

and exit, with an exit status of 1. No other output should be displayed, and the text above must be exact. You can use:  CourseNana.COM

printf("Error!");  CourseNana.COM

to display the required text.  CourseNana.COM

  CourseNana.COM

  CourseNana.COM

Starting conditions  CourseNana.COM

You should analyse walk paths starting from each of the 81 possible starting cells in a 9x9 island map. If the starting cell is a Bridge (B), no steps are needed and so the path length should be recorded as 0. If the starting cell is Water (W), Dinosaur (D), or Volcano (V), the explore will die immediately and so the path length should be recorded as 0.  CourseNana.COM

  CourseNana.COM

  CourseNana.COM

Coding scheme  CourseNana.COM

To perform the random movement you must use the rand() function (see below). You should map each move to an integer value as follows:   CourseNana.COM

·       0 represents move N.  CourseNana.COM

·       1 represents move NE.  CourseNana.COM

·       2 represents move E.  CourseNana.COM

·       3 represents move SE.  CourseNana.COM

·       4 represents move S.  CourseNana.COM

·       5 represents move SW.  CourseNana.COM

·       6 represents move W.  CourseNana.COM

·       7 represents move NW.  CourseNana.COM

This coding scheme is shown on the diagram below.  CourseNana.COM

CourseNana.COM

Generating random movements  CourseNana.COM

You are required to use the rand() function to randomly move in one of eight possible directions.   CourseNana.COM

  CourseNana.COM

rand(), which is part of the C standard library stdlib.h, returns a pseudo-random integer uniformly distributed within the interval given by [0, RAND_MAX], where RAND_MAX typically has a value of 32767.   CourseNana.COM

  CourseNana.COM

You should constrain the range of random numbers that rand() generates by using the modulus (remainder) operator introduced in Topic 3.   CourseNana.COM

  CourseNana.COM

Note that rand() must be seeded with a value before it is first called. For this purpose you must use srand() as:  CourseNana.COM

srand(123456);  CourseNana.COM

You should only call srand() once, near the start of your program in int main(). (Aside: Random numbers. CourseNana.COM

  CourseNana.COM

If on an edge cell, and a random move would take the explorer outside the edge of the map, then the explorer should stay put in that direction. For example:  CourseNana.COM

·       If they are on the bottom row, and try and move South, they will stay on the same cell. (As a move South would take them out of the map.)  CourseNana.COM

·       If they are on the bottom row and try and move South East they will move East, but stay on the same row.  CourseNana.COM

·       If they are on the bottom row, in the bottom right corner, and move South East they will stay on the same cell. (As a move South would take them out of the map, and a move to the East would take them out of map.)  CourseNana.COM

All of these cases still count as a step, and so the step counter should be incremented.  CourseNana.COM

  CourseNana.COM

Note that the explorer can take up to 10 steps on each try. 0 and 10 are thus valid numbers of steps to take.  CourseNana.COM

  CourseNana.COM

  CourseNana.COM

Standard deviation  CourseNana.COM

The standard deviation is defined as  CourseNana.COM

𝜎=∑i(xi−𝜇)2N‾‾‾‾‾‾‾‾‾‾‾‾√ CourseNana.COM

  CourseNana.COM

where  CourseNana.COM

xi CourseNana.COM

 is element number  CourseNana.COM

i CourseNana.COM

 in array  CourseNana.COM

x CourseNana.COM

CourseNana.COM

𝜇 CourseNana.COM

 is the mean of array  CourseNana.COM

x CourseNana.COM

, and  CourseNana.COM

N CourseNana.COM

 is the number of elements in array  CourseNana.COM

x CourseNana.COM

. Note that the demonimator is N.   CourseNana.COM

  CourseNana.COM

If checking your standard deviation function in another programming language, note that the above equation is implemented by (for an example array containing 1 to 10):  CourseNana.COM

·       Matlab: std([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],1)  CourseNana.COM

·       Python with numpy: np.std(a,ddof=0)  CourseNana.COM

Just say, just:  CourseNana.COM

·       Matlab: std([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])  CourseNana.COM

implements a different definition of the standard deviation (where the denominator is N-1.)  CourseNana.COM

  CourseNana.COM

  CourseNana.COM

Other standard libraries  CourseNana.COM

You can use other built-in C libraries as you wish, provided that all of your code is contained in the one coursework.c file. In particular, you may wish to use the sqrt() function included in math.h.  CourseNana.COM

  CourseNana.COM

You are not allowed to include your own custom headers. These will not be used by the marking system.   CourseNana.COM

  CourseNana.COM

  CourseNana.COM

Outputs  CourseNana.COM

For every cell on the island map your program should display (to two decimal places when suitable):  CourseNana.COM

·       A copy of the input map.  CourseNana.COM

·       The probability of successfully escaping from the island, displayed as a percentage. That is, how many of the random walks made it to a Bridge (B) cell.  CourseNana.COM

·       The mean path length (i.e. number of steps) of successful walks.   CourseNana.COM

·       The standard deviation of path lengths of successful walks.   CourseNana.COM

Invalid starting cells have 0.00 for the above numerical items. The values should be displayed to the terminal.   CourseNana.COM

  CourseNana.COM

An example output is shown on the following page. The output displayed must be formatted correctly:  CourseNana.COM

·       Use the headings (e.g. "Map:") exactly as shown on the example.  CourseNana.COM

·       Numbers on the same row should be separated by spaces.  CourseNana.COM

·       Suitable format specifiers should be used to set the precision and field width, to keep information in each table aligned.   CourseNana.COM

·       Include a blank line in between each of the output blocks (the map display, probability display, and so on). There is no blank line between rows in a table.  CourseNana.COM

  CourseNana.COM

  CourseNana.COM

Use of functions  CourseNana.COM

Although you can complete a suitable program without them, we suggest that you use your own custom functions to keep your code compact and avoid repetitive code for common actions. You might like to use the following (incomplete) function prototypes:   CourseNana.COM

·       void random_step(…);   CourseNana.COM

·       int calculate_status(…);   CourseNana.COM

where:  CourseNana.COM

·       random_step calculates the next random step.  CourseNana.COM

·       status returns the status of the next step:  CourseNana.COM

o   0 Failure   CourseNana.COM

o   1 Successfully made it to a bridge cell  CourseNana.COM

o   2 Walk continuing  CourseNana.COM

  CourseNana.COM

  CourseNana.COM

Planning and testing  CourseNana.COM

We suggest that you plan your code, before you start typing it in. Think about the main steps your code has to go through - getting data, processing the data, and outputting the results.   CourseNana.COM

  CourseNana.COM

You should also think about your test strategy. How will you check that your code does what you want it to do? How will you check that any functions you write in your code do what you want them to do? Feel free to make your own maps and use these to test your code.  CourseNana.COM

  CourseNana.COM

  CourseNana.COM

Coding style and quality  CourseNana.COM

We will check your code for common programming issues, including the number of comments used. You will lose marks if, for example, warnings are generated by the compiler, or there are issues with overflowing arrays. CourseNana.COM

Aside: Random numbers  CourseNana.COM

Getting computers to generate truly random numbers is in fact really hard (but important, lots of encryption schemes rely on using random numbers).  CourseNana.COM

  CourseNana.COM

In general, computers actually generate pseudo-random numbers. That is, they look random if you look at the probability distribution, but are in fact following a fixed pre-determined sequence. If you know where in this fixed sequence the program is starting from, known as the seed, you will get the same random numbers each time.   CourseNana.COM

  CourseNana.COM

srand() sets the starting position in the number sequence. Using  CourseNana.COM

srand(123456);  CourseNana.COM

ensures you use the same random numbers each time the code is run, making your code easier to debug and to mark. If you run your code multiple times, you should find you get exactly the same output (which isn't what you would expect if the explorer was taking truly random walks).   CourseNana.COM

  CourseNana.COM

This is the behaviour that we want in this coursework, but it probably isn't the behaviour that you want while programming more generally. Usually, you would use srand() more like:  CourseNana.COM

srand(time(NULL));  CourseNana.COM

time() is provided by the time.h header, and time(NULL) returns the current time. (In milliseconds since 00:00:00 1st January 1970, which is a format known as Unix time.) Thus, the seed to srand() is set based upon the current time, and so you will get different random numbers each time the program is run.  CourseNana.COM

  CourseNana.COM

Note that even with the above seed rand() in general only produces approximately random numbers, and shouldn't be relied upon in situations where truly random numbers are important. There are other C libraries, beyond the scope of this course, that you can investigate for use in (for example) cryptography applications.  CourseNana.COM

  CourseNana.COM

The implementation of rand() is also platform dependent. That is, the algorithm used to generate random numbers is different on Windows, macOS, and Linux. This means that the random numbers generated by the same function are different, even when using the same seed. The marking system uses Linux and will automatically convert for you whichever platform you develop your code on. The marking system will display what you should see if developing your code on Windows or macOS, in addition to what it sees when running the code on Linux.   CourseNana.COM

  CourseNana.COM

  CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
Manchester代写,EEEN10036代写,C Programming代写,Escape From Island代写,C代写,Manchester代编,EEEN10036代编,C Programming代编,Escape From Island代编,C代编,Manchester代考,EEEN10036代考,C Programming代考,Escape From Island代考,C代考,Manchesterhelp,EEEN10036help,C Programminghelp,Escape From Islandhelp,Chelp,Manchester作业代写,EEEN10036作业代写,C Programming作业代写,Escape From Island作业代写,C作业代写,Manchester编程代写,EEEN10036编程代写,C Programming编程代写,Escape From Island编程代写,C编程代写,Manchesterprogramming help,EEEN10036programming help,C Programmingprogramming help,Escape From Islandprogramming help,Cprogramming help,Manchesterassignment help,EEEN10036assignment help,C Programmingassignment help,Escape From Islandassignment help,Cassignment help,Manchestersolution,EEEN10036solution,C Programmingsolution,Escape From Islandsolution,Csolution,