Assignment 1 - Freefall

There are a few different times in history when computing has had a significant effect on the world. This isn't always large scale political events, sometimes it's the capturing of an audience and setting up a culture that will reverberate for decades. The Golden Age of Arcade Games is thought to have lasted from the 1970s through to about 1983. In 1982, arcade games made more money in the USA than both their music industry and film industry combined.

Welcome to Freefall, your first major project in COMP1511. This is a game that's based on some of the classics of the Golden Age, the vertical shooters like Space Invaders and Galaga. In this assignment you will create Freefall, an array based command line game where the player must defend against falling stones!

If you'd like to try the game, it's available as command on any CSE computer. The aim of the game is to destroy all of the map's falling stones with your laser before they reach the ground. If the map is cleared of all stones, the game is won. If any stones make it past the bottom row, the game is lost.

1511 arcade solution

This assignment doesn't involve creating the full interactive terminal interface provided by arcade. The final product is a more stripped down, simplified version where the game will be controlled by a series of commands of integers entered by the user.

The starter code for Freefall (see below) is already capable of printing the map, but it will be up to you to write code so that it can first add stones to the map, then read commands and make the correct changes to the map.

At time of release of this assignment (end of Week 3), COMP1511 has not yet covered all of the techniques and topics necessary to complete this assignment. At the end of Week 3, the course has covered enough content to be able to read in a single command and process its integers, but not enough to work with two dimensional arrays like the map or be able to handle multiple commands ending in End-of-Input (Ctrl-D). We will be covering these topics in the lectures, tutorials, and labs in Week 4.

The Map

The map is a two dimensional array (an array of arrays) of integers that represents the space that the game is played in. In stage 1 and 2, the map will only store either a 0 or a 1. A 0 represents an empty square, and a 1 represents a stone. In the starter code there are #defines for both of these values, which we will reference for the remainder of this page.

The map is a fixed-size square-shaped grid and has SIZE rows, and SIZE columns. SIZE is another #define'd constant with the value 15.

Remember, both the rows and columns start at 0, not at 1.

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
0 [0][0] [0][1] [0][2] [0][3] [0][4] [0][5] [0][6] [0][7] [0][8] [0][9] [0][10] [0][11] [0][12] [0][13] [0][14]
1 [1][0] [1][1] [1][2] [1][3] [1][4] [1][5] [1][6] [1][7] [1][8] [1][9] [1][10] [1][11] [1][12] [1][13] [1][14]
2 [2][0] [2][1] [2][2] [2][3] [2][4] [2][5] [2][6] [2][7] [2][8] [2][9] [2][10] [2][11] [2][12] [2][13] [2][14]
3 [3][0] [3][1] [3][2] [3][3] [3][4] [3][5] [3][6] [3][7] [3][8] [3][9] [3][10] [3][11] [3][12] [3][13] [3][14]
4 [4][0] [4][1] [4][2] [4][3] [4][4] [4][5] [4][6] [4][7] [4][8] [4][9] [4][10] [4][11] [4][12] [4][13] [4][14]
5 [5][0] [5][1] [5][2] [5][3] [5][4] [5][5] [5][6] [5][7] [5][8] [5][9] [5][10] [5][11] [5][12] [5][13] [5][14]
6 [6][0] [6][1] [6][2] [6][3] [6][4] [6][5] [6][6] [6][7] [6][8] [6][9] [6][10] [6][11] [6][12] [6][13] [6][14]
7 [7][0] [7][1] [7][2] [7][3] [7][4] [7][5] [7][6] [7][7] [7][8] [7][9] [7][10] [7][11] [7][12] [7][13] [7][14]
8 [8][0] [8][1] [8][2] [8][3] [8][4] [8][5] [8][6] [8][7] [8][8] [8][9] [8][10] [8][11] [8][12] [8][13] [8][14]
9 [9][0] [9][1] [9][2] [9][3] [9][4] [9][5] [9][6] [9][7] [9][8] [9][9] [9][10] [9][11] [9][12] [9][13] [9][14]
10 [10][0] [10][1] [10][2] [10][3] [10][4] [10][5] [10][6] [10][7] [10][8] [10][9] [10][10] [10][11] [10][12] [10][13] [10][14]
11 [11][0] [11][1] [11][2] [11][3] [11][4] [11][5] [11][6] [11][7] [11][8] [11][9] [11][10] [11][11] [11][12] [11][13] [11][14]
12 [12][0] [12][1] [12][2] [12][3] [12][4] [12][5] [12][6] [12][7] [12][8] [12][9] [12][10] [12][11] [12][12] [12][13] [12][14]
13 [13][0] [13][1] [13][2] [13][3] [13][4] [13][5] [13][6] [13][7] [13][8] [13][9] [13][10] [13][11] [13][12] [13][13] [13][14]
14 [14][0] [14][1] [14][2] [14][3] [14][4] [14][5] [14][6] [14][7] [14][8] [14][9] [14][10] [14][11] [14][12] [14][13] [14][14]

The top left corner of the grid is [0][0] and the bottom right corner of the grid is [SIZE - 1][SIZE - 1]. Note that, like the array itself, we are using rows as the first coordinate in pairs of coordinates. This is the opposite order you might be used to in maths.

For example, if in a command we are given an input pair of coordinates 5 6, we will use that to find a particular square in our map by accessing the individual element in the array: map[5][6]. This represents the square in the 6th row and the 7th column (remember arrays start counting at 0).

When the program begins, all of the squares in the map should have the value EMPTY. The starter code does this part for you. You must then populate the map with stones (i.e., STONE) by scanning the locations of horizontal lines of stones (more detail on this later). After this, you must scan in commands until EOF, making the appropriate changes to the map. The format of the inputted commands and changes to the map required are specified in this page.

If you ever have a question in the form of "What should my program do if it is given these inputs?" you can run the Freefall reference solution and copy its behaviour. This is a complete solution to the assignment which does not use the interactive terminal interface of 1511 arcade.

1511 freefall_reference

Allowed C Features

In this assignment, there are no restrictions on C features, except for those in the Style Guide.

We strongly encourage you to complete the assessment using only features taught in lectures up to and including Week 4. The only C features you will need to get full marks in the assignment are:

  • int (and possibly double) variables;
  • if statements, including all relational and logical operators;
  • while loops;
  • int arrays, including two dimensional arrays;
  • printf and scanf; and
  • functions.

Using any other features will not increase your marks (and may make it more likely to make style mistakes that cost you marks).

If you choose to disregard this advice, you must still follow the Style Guide. You also may be unable to get help from course staff if you use features not taught in COMP1511.

Starter Code

Download the starter code (freefall.c) here or use this command on your CSE account to copy the file into your current directory:

cp -n /web/cs1511/20T2/activities/freefall/freefall.c .

freefall.c is the starting point for your Freefall program. We've provided you with some constants and some starter code to display the map as basic integers on the screen; you'll be completing the rest of the program.

Inputs and Validity

All of the inputs to your program will be in the form of a sequence of integers on standard input.

After scanning in all of the inputs relating to the rows of stone to place on the map, you will need to scan commands until EOF. In these commands, the first number specifies the type of command, for instance, if the first number is 1 then this represents a command to move the player. Commands may optionally have additional so-called "argument" integers after the initial one.

You can be guaranteed that the first integer of any command will be valid. You can assume that the correct number of integers will be given for any particular command. In many other places, you may be given invalid input, such as negative numbers where you don't expect them. This includes any of the argument integers after the first integer of each command, and also includes the first part of scanning lines of stone in to the map. The ways in which commands might be invalid will be specified in each relevant section for you.

Throughout this assignment we encourage you to think like a hacker. What inputs would break your code? If you find any inputs which break the reference solution, please let us know!

Stage 1

Stage 1 implements the ability to read in lines of stone and place them onto the map, move the player to the left and right (and print this on the screen), and fire the laser to destroy falling STONE.

Placing Stone

The program should first ask for the number of lines of STONEs as an integer. Then, the program will scan the locations of the lines as a group of four integers in the following format:

row column length value

The row and column represent the left-most block of a horizontal line of blocks to the placed on the map. The length tells you how many stones should be in this horizontal line. For stage 1 and 2, the fourth integer will always be 1 representing a stone, however in other stages there will be other possibilities such as exploding TNT and marching blocks. This number is the value which should be placed in the array itself to make up the specified line. For example:

Command Meaning
0 0 5 1

Place a line of stone starting at [0][0] and ending at [0][4]. All 5 squares in the line will be set to 1 (STONE).

6 7 1 1

Place a line of stone starting at [6][7] and ending at [6][7]. The 1 square in the line will be set to 1 (STONE).

5 0 15 1

Place a line of stone starting at [5][0] and ending at [5][14]. All 15 squares in the line will be set to 1 (STONE).

./freefall
How many lines of stone? 3
Enter lines of stone:
0 0 5 1
6 7 1 1
5 0 15 1
1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
              P

After scanning in the inputs relating to placing lines of stone on the map, the program should then call printMap to display the map on the screen. The line of code to do this is already in the starter code. After printing the map, the program should start to scan in commands until EOF. After processing each command, your program should call printMap once again to show the changes made to the map. Details of each command that your program must implement are shown below.

In the starter code, the program currently initialises every square in the map to EMPTY then prints the map as a grid of integers.

Invalid Input and Assumptions

  • The first number scanned in (i.e. the number of coordinate pairs specified) will always be valid. It will always be a number greater than zero.
  • It is possible for the first three integers (row column length) to result in a line which is partially or wholly outside of the map. If this is the case, you should ignore this line completely and not make any changes to the map.
  • You can assume the third integer (length) will always be positive.
  • The fourth integer can be assumed to be valid. For this stage it will always be 1 (you don't have to check this).

Moving the Player

Summary: Move Player Command
Command Name "Move Player"
Command Number 1
Inputs direction
Examples
Command Meaning
1 -1

Move the player once to the left.

1 1

Move the player once to the right.

1 2

Invalid. Don't make any changes.

For the next part of stage 1, you will implement a command to move the player to the left or right on the screen.

The first integer of any move player command will always be a 1. The second integer represents the direction. -1 means to move the player to the left and 1 means to move the player to the right.

Information about the player's current position is given to the printMap function, so it is recommended to update the playerX variable in the main function when this command is received. This will have the effect of changing the position of the P printed by printMap the next time it is called.

Note that after each command has been scanned in and processed the map is printed once again.

./freefall
How many lines of stone? 1
Enter lines of stone:
0 3 10 1
0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 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of stone? 1
Enter lines of stone:
1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
              P
1 5
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
              P

Invalid Input and Assumptions

  • The second integer of a move player command may be something else other than -1 or 1. In this case, your program should print out the map unchanged.
  • Your program may be given a sequence of move player commands which would theoretically move the player off the map. Ensure the player is always below a column of the map. If the player is on an edge column and a move player command is received which would push it over the edge, your program should print out the map unchanged.

Firing the Laser

Summary: Fire Laser Command
Command Name "Fire Laser"
Command Number 2
Inputs (none)
Examples
Command Meaning
2

Fire the laser upwards.

For the final part of stage 1, you will implement a command to fire the laser and destroy some blocks directly above the player.

This time the first integer of this command will always be a 2. There will not be any additional integers after this.

This command means to fire the laser at the player's current column. The laser will destroy at most 3 stones above the player. Destroying a stone can be done by changing the value in the array from STONE to EMPTY.

If there are more than three stones in the player's current column, the closest three stones should be destroyed only.

Hint: Even though you are looping through a 2D array, only one while loop is required to complete this command as you are looping through a straight line in the array.

./freefall
How many lines of stone? 4
Enter lines of stone:
0 6 3 1
1 6 3 1
2 6 3 1
3 6 3 1
0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 
0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 
0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 
0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
              P
2
0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 
0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 
0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 
0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 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0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
            P
2
0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
            P

Invalid Input and Assumptions

  • Since there is only one number in this command, there are no invalid input possibilities.
  • Note that there may be no stones in the player's current column, in which case no changes should be made.

It is possible to score a passing mark in this assignment with the completion of stage 1 only.

You can run the autotests for stage 1 by running the following command:

1511 autotest-stage 01 freefall

Stage 2

In stage 2, you will be implementing a command to shift everything in the map down by one position, and you will be implementing functionality to determine whether the game has been won or lost.

Shift Everything Down

Summary: Shift Everything Down Command
Command Name "Shift Everything Down"
Command Number 3
Inputs (none)
Examples
Command Meaning
3

Move everything on the map down one position.

For the first part of stage 2, you will need to shift all items in the array down by one position. This should occur whenever the program reads in a command of: 3.

There are no arguments after this command, it is another single integer command.

When your program shifts the contents of the array down, the integers which were in the bottom row will disappear, and the integers in the top row will all become EMPTY.

Invalid Input and Assumptions

  • Since this command only has one number, there is no possibility for invalid input.
./freefall
How many lines of stone? 2
Enter lines of stone:
1 1 2 1
5 5 5 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
              P
3
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
              P

End Conditions

There are two ways to complete a game of Freefall:

  • The game is won if the entire map is EMPTY.
  • The game is lost if there is any STONE on the last row as a 3 (shift everything down) command is given. The only case in which the game is not lost when the shift everything down command is given, is when the entire bottom row of the map is EMPTY.

In stage 2 you must add code to check for these conditions. The win conditions should be checked after every fire laser command. If the game is won, the program should print the map once and then print "Game Won!" and end.

The lose condition should be checked before the contents of the array are shifted down. If the game is lost, the program should not shift the grid down, but should still print the map once and then print "Game Lost!" and end.

Invalid Input and Assumptions

  • You can assume that there will always be at least one non-EMPTY block on the map when the game starts.
./freefall
How many lines of stone? 1
Enter lines of stone:
0 7 1 1
0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
              P
2
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0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0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 
              P
3
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 
              P
Game Lost!

You can run the autotests for stage 2 by running the following command:

1511 autotest-stage 02 freefall

If you've passed all of the autotests for stage 2, you should be able to "plug" your freefall implementation into the arcade player like this:

1511 arcade freefall.c

Please note that if your program is not passing tests, or does not behave in the way 1511 arcade expects, this may not work. 1511 arcade should not be used as a debugging tool. It is not designed to provide helpful information about your code.

Stage 3

For stage 3, you will be adding a special ability to Freefall to flip the map and also adding support for TNT.

Vertical Flip

Summary: Vertical Flip Command
Command Name "Vertical Flip"
Command Number 4
Inputs (none)
Examples
Command Meaning
4

Flip the entire map vertically.

For the first part of stage 3, you will implement the vertical flip command. The vertical flip command is the number 4 and does not contain any additional arguments.

What is a Vertical Flip?

Move your mouse over this box...

That was a vertical flip!

Now imagine this happening to the map...

This command can be used strategically in gameplay to cause the map to be flipped vertically. This means that blocks in the top and bottom row of the map will be swapped. Blocks in the second and second-bottom row will also be swapped, and so on. This simulates a vertical flip, rather like if you pulled bottom row "out" of your screen and pushed the top row "in" to your screen, rotating the map 180 degrees along a horizontal axis.

The column that a block is in should not change, but the row will.

The vertical flip command should only work once. If the user types a vertical flip command again, it should not make any changes to the map.

./freefall
How many lines of stone? 2
Enter lines of stone:
1 1 2 1
12 7 5 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
              P
4
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
              P
4
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
              P

Invalid Input and Assumptions

  • Since this command doesn't have any arguments, there is no possibility for invalid input.

TNT Blocks

In this part of the assignment, you will learn how computers create circles.

Up until now our map array could only contain two values: STONE and EMPTY. We are now going to add support for other values in the array.

If the value is in the range 3-9 (inclusive), that block is considered a TNT block. TNT blocks are added to the map in the same way in which STONE is added at the beginning of the program, except the number in the array is a number from 3 to 9. TNT blocks fall just like STONE but when they are destroyed with the laser, they will destroy any other blocks in a circle shape. The radius of the circle is given by the value in the range 3-9.

TNT blocks are destroyed with the laser using the same "Fire Laser" command that STONE blocks are destroyed with.

Previously, the laser will have destroyed at most 3 blocks of STONE. Once the laser causes a TNT explosion, there is no need to continue destroying blocks in the path of the laser.

If there is another TNT block within the explosion radius of an exploding TNT block, it does not explode in a chain reaction. It is simply removed in the same way as STONE.

If the laser destroys a value of 5 at the array at position map[3][4], then any values strictly within the circle at centre [3][4] and radius 5 will be converted to EMPTY. This would include the value at map[3][3] for instance, but would not include the value at map[6][8] which lies on the circumference of the circle.

Using the distance formula below, you can calculate the euclidean distance between any two points in the array. If the calculated distance is less than the value of the TNT block, then it should be converted to EMPTY.

Distance Formula

For example, if the TNT block with value 4 is located at map[5][7], you might want to find whether the position [6][2] is included in this circle.

In this case:

  • x2 = 2
  • x1 = 7
  • y2 = 6
  • y1 = 5

After substituting these values into the formula you will be able to calculate the distance to be the square root of 26 or roughly 5.099. In this case, the position at [6][2] would be outside of the circle of radius 4 with center at map[5][7].

You can use any functions from math.h to complete this part of the assignment.

Invalid Input and Assumptions

  • There is no command/arguments associated with this functionality so there is no possiblity for invalid input.
./freefall
How many lines of stone? 12
Enter lines of stone:
2 2 11 1
3 2 11 1
4 2 11 1
5 2 11 1
6 2 11 1
7 2 11 1
8 2 11 1
9 2 11 1
10 2 11 1
11 2 11 1
12 2 11 1
7 7 1 5
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
0 0 1 1 1 1 1 5 1 1 1 1 1 0 0 
0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 
0 0 0 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est-stage 03 freefall

Stage 4

Stage 4 consists of three parts: creating marching blocks, placing blocks above the map, and another strategic command for gameplay: gravity storms.

Marching Blocks

In this section we will give functionality to blocks known as marching blocks which contain the value 2. These blocks should behave similarly to STONE but instead of shifting down in every 3 command, they alternate their direction.

The first time in the program's life the 3 command is given, these blocks should be moved down as normal, but on the second time they should move to the right. Then on the third time they should move down, then left on the fourth time. This pattern repeats. From the beginning of execution, these marching blocks should go down, right, down, left, down, right, down, left, down, right, down, left, and so on...

This will result in the marching blocks following a snake-like pattern down the map. The following animated diagram shows how a marching block travels, starting at [7][7].

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14

If a marching block's movement to the left or right would result in it being off the map, do not move that marching block.

There may be some situations where a marching block collides with a regularly falling STONE block or a TNT block. In this case, the STONE block or TNT block is destroyed and the marching block continues.

There may be some situations where a marching block collides with another marching block. In this case, the two marching blocks collide and become one marching block from that point onwards.

./freefall
How many lines of stone? 3
Enter lines of stone:
0 0 1 2
0 14 1 2
1 13 2 2
2 0 0 0 0 0 0 0 0 0 0 0 0 0 2 
0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
              P
3
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
2 0 0 0 0 0 0 0 0 0 0 0 0 0 2 
0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
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0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
              P
3
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
2 0 0 0 0 0 0 0 0 0 0 0 0 2 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
              P

Invalid Input and Assumptions

  • There is no new commands in this section, so there is no possibility for invalid input.

Blocks Above the Map

In this section, blocks can now be placed above the map using a negative y coordinate in the first part of your program where you scan in lines of blocks.

You can assume that blocks will never be placed above the y coordinate -150.

Each time a 3 command is given, the top row of the map will be filled in with values from the blocks above the map. For instance if a row of blocks is placed with -2 5 3 1 then this row will appear on the top row of the map after the second 3 command.

The fire laser command should only destroy blocks on the original SIZE × SIZE map. The laser does not continue above the map, it should not destroy blocks above the map.

The blocks above the map do not count towards the win condition. The game is won if the original SIZE × SIZE is completely EMPTY. The player can still win even if there are blocks above the map which haven't yet fallen on to the map.

The special path marching blocks take does not apply to marching blocks above the map. All blocks above the map should be shifted down only every 3 command. Once a marching block appears on the map, they will begin to follow the special path defined previously. The direction a marching block takes upon entering the map is the same direction all other marching blocks are taking at that moment. To further clarify, marching blocks, no matter where they originated from, will always march in the same direction for any particular 3 command.

The way you choose to implement this functionality, and the arrays you choose you use, are both completely up to you.

./freefall
How many lines of stone? 2
Enter lines of stone:
1 1 3 1
-1 3 10 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
              P
3
0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
              P

Invalid Input and Assumption

  • Previously a negative y coordinate for placing rows of blocks would have been considered invalid input. Now the coordinate is only invalid if it is less than -150.
  • Negative x coordinates are still considered invalid.
  • If the input is invalid, the program should not make any changes.

Gravity Storm

Summary: Gravity Storm Command
Command Name "Gravity Storm"
Command Number 5
Inputs direction
Examples
Command Meaning
5 1

All blocks fall towards the left until they hit an edge or another block.

5 2

All blocks fall towards the top-left until they hit an edge or another block.

5 3

All blocks fall towards the top-right until they hit an edge or another block.

5 4

All blocks fall towards the right until they hit an edge or another block.

5 5

Invalid. Don't make any changes.

For the last section of this assignment, you will be implementing command number 5, known as a gravity storm. Like the vertical flip command, this command will only work the first time. Successive attempts to give a gravity storm command should not make and changes.

The gravity storm command will always include one additional integer argument which specifies the direction.

  • If the direction argument is 1, the gravity storm is towards the left.
  • If the direction argument is 2, the gravity storm is towards the top-left.
  • If the direction argument is 3, the gravity storm is towards the top-right.
  • If the direction argument is 4, the gravity storm is towards the right.

The gravity storm causes all blocks on the map to "fall" towards the direction specified and stack up against the edge/corner of the map. A gravity storm should not cause any blocks to be removed from the map.

A gravity storm only applies to blocks which are in the map. It does not apply to blocks which are above the map.

  • After a left gravity storm, there should be no EMPTY blocks with non-EMPTY values directly to the right of them.
  • After a top-left gravity storm, there should be no EMPTY blocks with non-EMPTY values directly to the bottom-right of them.
  • After a top-right gravity storm, there should be no EMPTY blocks with non-EMPTY values directly to the bottom-left of them.
  • After a right gravity storm, there should be no EMPTY blocks with non-EMPTY values directly to the left of them.
./freefall
How many lines of stone? 4
Enter lines of stone:
0 0 2 1
3 3 2 1
3 8 2 1
6 10 4 1
1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 1 1 0 0 0 1 1 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 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0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 5 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
              P
5 3
0 0 0 0 2 2 0 0 0 0 0 0 1 1 1 
0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
              P

Invalid Input and Assumptions

  • If the direction argument is anything other than 1, 2, 3 or 4, no changes should be made.
  • If the first gravity storm command is invalid, it will still count as a gravity storm and the user will be unable to give a gravity storm command again.

You can run the autotests for stage 4 by running the following command:

1511 autotest-stage 04 freefall

Other Important Notes

Style

As with all programs you write, style is an important part of your Freefall code. You will receive feedback on your style as part of the marking of this assessment. For an indication of how your style is going, use the 1511 style command. Or feel free to ask for a style review from your tutors or on the forum.

ls
freefall.c
1511 style freefall.c
[style feedback]

Your code will be style marked by a human, so in addition to fixing issues presented by 1511 style, you should also consider your code's readability, variable naming, and other factors that could make your code easier or harder for a human to understand.

Testing

It is important to test your code to make sure that your program can perform all the tasks correctly.

There are a few different ways to test (that are described in detail below):

  • Typing in your own commands. You can use the commands shown above as examples, or work out your own.
  • Testing from a series of commands written in a file (example below).
  • Using autotests to run through all of our test files at once.
  • Running the reference implementation that we have created for you to determine expected output.

Testing Your Code

You can test your code by either typing commands directly into a terminal or you can type the commands into a file, and then run your program like this:

ls
freefall.c        test1.in
dcc -o freefall freefall.c
./freefall < test1.in
[the output of running the commands in test_file1.in]

If you are using an input file, your file should only contain the commands which would be typed into the terminal. It should not contain any output which the program produces. For example:

cat test1.in
1
3 6 1 1
1 -1
2

Automated Testing

On CSE computers (including via VLAB), our automated tests can be checked at once using the command:

1511 autotest freefall

If you wish to test only one stage at a time, the instructions for testing individual stages are shown alongside the stages themselves above.

Reference Implementation

If you have questions about what behaviour your program should exhibit, we have provided a sample solution for you to refer to.

You can use it by running the following command on CSE Computers or via VLAB:

1511 freefall_reference

The Arcade Player

Please note that the arcade player should not be used as a tool to debug your program. It is intended to be used only once you are passing the autotests for at least stage 1 and 2. It may fail in strange and unexpected ways if your program differs from the reference implementation.

There are a variety of options you can give to the arcade player as command line arguments. It is possible to prevent the arcade player from regularly giving a "shift everything down" command. It is possible to print numbers instead of blocks to the screen. For a full list of these options and what they do, run the command 1511 arcade --help.

1511 Arcade Map Submission

Have you created a really cool map that you want to share with the course? Email us at cs1511.freefall_maps@cse.unsw.edu.au with your map, and if we like it, we will add it to the arcade player.

A map file is the first part of input into the freefall program. An example of a map file is this:

3
1 1 5 2
4 3 1 1
6 5 1 7

Assessment

Attribution of Work

This is an individual assignment. The work you submit must be your own work and only your work apart from exceptions below. Joint work is not permitted. At no point should a student read or have a copy of another student's assignment code.

You may use small amounts (< 10 lines) of general purpose code (not specific to the assignment) obtained from sites such as Stack Overflow or other publicly available resources. You should attribute clearly the source of this code in a comment with it.

You are not permitted to request help with the assignment apart from in the course forum, help sessions or from course lecturers or tutors.

Do not provide or show your assignment work to any other person ( including by posting it on the forum) apart from the teaching staff of COMP1511. When posting on the course forum, teaching staff will be able to view the assignment code you have recently autotested or submitted with give.

The work you submit must otherwise be entirely your own work. Submission of work partially or completely derived from any other person or jointly written with any other person is not permitted. The penalties for such an offence may include negative marks, automatic failure of the course and possibly other academic discipline. Assignment submissions will be examined both automatically and manually for such issues.

Relevant scholarship authorities will be informed if students holding scholarships are involved in an incident of plagiarism or other misconduct. If you knowingly provide or show your assignment work to another person for any reason, and work derived from it is submitted you may be penalised, even if the work was submitted without your knowledge or consent. This may apply even if your work is submitted by a third party unknown to you.

Note, you will not be penalised if your work is taken without your consent or knowledge.

Submission of Work

You are required to submit intermediate versions of your assignment.

Every time you work on the assignment and make some progress you should copy your work to your CSE account and submit it using the give command below.

It is fine if intermediate versions do not compile or otherwise fail submission tests.

Only the final submitted version of your assignment will be marked.

You submit your work like this:

give cs1511 ass1_freefall freefall.c

Assessment Scheme

This assignment will contribute 15% to your final mark.

80% of the marks for this assignment will be based on the performance of the code you write in freefall.c

20% of the marks for this assignment will come from hand marking of the readability of the C you have written. These marks will be awarded on the basis of clarity, commenting, elegance and style. In other words, your tutor will assess how easy it is for a human to read and understand your program.

Here is an indicative marking scheme.

HD (85-100%)Successfully implements all of stages 1, 2, and 3, with beautiful C code.
Higher-grade High Distinctions will be awarded for the correctness and style of stage 4.
DN (75+%)Successfully implements all of stages 1 and 2, with readable C code.
Solutions that partially implement stage 3 with stylistic C code will be awarded higher-grade Distinctions.
CR (65+%)Successfully implements all of stage 1 with readable C code.
Solutions that partially implement stage 2 will be awarded higher-grade Credits.
PS (50+%)Reasonably readable C code that can scan in input and make some changes to the map as well as being able to fire the laser.
Solutions that reject invalid input with stylistic C code will be awarded higher-grade Passes.
40-50%A substantial attempt at part of stage 1.
-70%Knowingly providing your work to anyone and it is subsequently submitted (by anyone).
-70%Submitting any other person's work. This includes joint work.
0 FL for COMP1511Paying another person to complete work. Submitting another person's work without their consent.

The lecturer may vary the assessment scheme after inspecting the assignment submissions but it will remain broadly similar to the description above.

Due Date

This assignment is due Sunday 12 July 2020 18:00:00

If your assignment is submitted after this date, each hour it is late reduces the maximum mark it can achieve by 1%. For example if an assignment worth 74% was submitted 10 hours late, the late submission would have no effect. If the same assignment was submitted 30 hours late it would be awarded 70%, the maximum mark it can achieve at that time.

Change Log

Version 1.0
(2020-06-21 17:00)
  • Released first assignment version.