Assignment 1 - Slide

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 Slide, your first major project in COMP1511. This is a game that's based on some of the classics of the Golden Age, the shooters like Space Invaders and Galaga. In this assignment you will create Slide, an array based command line game where the laser must defend against sliding stones!

If you'd like to try the game, it's available as a command on any CSE computer. The aim of the game is to destroy all of the map's sliding 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 left-most column, 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 Slide (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.

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, because we are using an array, 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 opposite to the 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 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.

There is also a laser which is not necessarily on the map but is related to it. The laser is always considered to be off the map to the left and aligned with one of the rows. The laser will eventually be able to be moved up and down as well as shoot, affecting the stones.

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 Slide reference solution and copy its behaviour. This is a complete solution to the assignment.

1511 slide_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 (slide.c) here or use this command on your CSE account to copy the file into your current directory:

cp -n /web/cs1511/21T1/activities/slide/slide.c .

slide.c is the starting point for your Slide 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 laser. 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 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 stones and place them onto the map, move the laser up and down (and print this on the screen), and fire the laser to destroy sliding STONE.

Placing Stones

The program should first ask for the number of STONEs as an integer. You can assume this number is valid. Then, the program will scan the locations of the stones as a group of three integers in the following format:

row column value

The row and column represent the location where a stone should be placed on the map. For stage 1 and 2, the third integer will always be 1 representing a STONE, however in other stages there will be other possibilities such as exploding TNT and night blocks. This number is the value which should be placed in the array itself. For example:

Command Meaning
0 0 1

Place a stone at [0][0].

6 7 1

Place a stone at [6][7].

./slide
How many blocks? 2
Enter blocks:
0 0 1
6 7 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 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

After scanning in the inputs relating to placing stones on the map, the program should then call print_map 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. (Your program's behaviour should match the behaviour of the reference solution; when Ctrl + D is pressed, your program should end.) After processing each command, your program should call print_map 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 is possible for the first two integers (row column) to result in location outside of the map. If this is the case, you should ignore this stone completely and not make any changes to the map.
  • The third integer can be assumed to be valid. For this stage it will always be 1 (you don't have to check this).

Moving the Laser

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

Move the laser downwards once.

1 -1

Move the laser upwards once.

1 2

Invalid. Don't make any changes.

For the next part of stage 1, you will implement a command to move the laser up or down the screen.

The first integer of any move laser command will always be a 1. The second integer represents the direction. -1 means to move the laser upwards and 1 means to move the laser downwards.

Information about the laser's current position is given to the print_map function, so it is recommended to update the laser_y variable in the main function when this command is received. This will have the effect of changing the position of the > symbol printed by print_map the next time it is called.

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

./slide
How many blocks? 1
Enter blocks:
4 5 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 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 
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 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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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 0 0 
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

Invalid Input and Assumptions

  • The second integer of a move laser 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 laser commands which would theoretically move the laser off the map. Ensure the laser is always next to a row of the map. If the laser is on an edge row (the top or bottom row) and a move laser 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 rightwards.

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

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 laser's current position. The laser will destroy at most 4 stones. Destroying a stone can be done by changing the value in the array from STONE to EMPTY.

A laser will only destroy directly to the right of it's current position. It can destroy a maximum of four blocks. The blocks it destroys do not need to be next to eachother.

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.

./slide
How many blocks? 23
Enter blocks:
5 5 1
5 6 1
5 7 1
6 5 1
6 6 1
6 7 1
7 5 1
7 6 1
7 7 1
7 8 1
8 5 1
8 6 1
8 7 1
8 8 1
8 9 1
8 10 1
9 5 1
9 6 1
9 7 1
9 8 1
9 9 1
9 10 1
9 11 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 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 1 0 0 0 0 0 0 
  0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 
  0 0 0 0 0 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 
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 1 1 1 0 0 0 0 0 0 0 
  0 0 0 0 0 1 1 1 0 0 0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0 0 0 1 1 0 0 0 0 
  0 0 0 0 0 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 

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 laser's current row, 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 slide

Stage 2

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

Shift Everything Left

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

Move everything on the map left one position.

For the first part of stage 2, you will need to shift all items in the array left 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 left, the integers which were in the left-most column will disappear, and the integers in the right-most column will all become EMPTY.

Invalid Input and Assumptions

  • Since this command only has one number, there is no possibility for invalid input.
./slide
How many blocks? 13
Enter blocks:
7 3 1
6 4 1
5 5 1
4 6 1
8 4 1
9 5 1
10 6 1
7 4 1
7 5 1
7 6 1
7 7 1
7 8 1
7 9 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 1 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 1 0 0 0 0 0 0 0 0 0 0 
> 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 
  0 0 0 0 1 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 
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 1 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 1 0 0 0 0 0 0 0 0 0 0 0 0 0 
> 1 1 1 1 1 1 1 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 1 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 

End Conditions

There are two ways to complete a game of Slide:

  • The game is won if the entire map is EMPTY.
  • The game is lost if there is any STONE on the left-most column as a 3 (shift everything left) command is given. The game cannot be lost if the entire left column of the map is EMPTY prior to shifting everything left.

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 map are shifted left. If the game is lost, the program should not shift the grid left, 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.
./slide
How many blocks? 4
Enter blocks:
7 7 1
7 8 1
7 9 1
7 10 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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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 
Game Lost!

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

1511 autotest-stage 02 slide

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

1511 arcade slide.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 Slide to rotate the map and also adding support for TNT.

Rotate Map

Summary: Rotate Map Command
Command Name "Rotate Map"
Command Number 4
Inputs direction
Examples
Command Meaning
4 1

Rotate the map clockwise by 90 degrees.

4 2

Rotate the map counter-clockwise by 90 degrees.

4 100

Invalid. Do not change the map.

For the first part of stage 3, you will implement the rotate map command. The rotate map command is the number 4. It has one argument which specifies the direction of rotation. If the direction argument is 1, the rotation should be 90 degrees clockwise. If the direction argument is 2, the rotation should be 90 degrees counter-clockwise. If the direction argument is any other number, it is invalid and no changes should be made to the map.

This command can be used strategically in gameplay to cause the map to be rotated. This means that if blocks are mostly on the bottom of the map, a counter-clockwise rotation would be advantageous for the player.

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

./slide
How many blocks? 5
Enter blocks:
0 0 1
1 1 1
14 3 1
14 13 1
13 13 1
  1 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 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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 1 0 0 0 0 0 
  0 0 0 0 0 1 1 1 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 1 0 0 0 0 
  0 0 0 0 0 1 1 1 0 0 1 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

Invalid Input and Assumptions

  • It is possible for the second number of this command to be invalid if it is not either 1 or 2. In this case you should not change the map.
  • Even if the first rotate map command is invalid, it still counts as using the rotate map commands. Other rotate map commands after should not change the map.

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 4-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 4 to 9. TNT blocks slide 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 of the TNT block in the range 4-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 4 blocks of STONE. Now, if the laser destroys a TNT block, the TNT block will explode, potentially destroying many more blocks.

Only the laser causes TNT to explode, so 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.

In other words, if a TNT block is hit by the laser, it should explode. Explosions "use up" all the strength of a laser -- even if the laser could hit other blocks behind the TNT, it doesn't. If a TNT block is destroyed by another TNT block, it should not explode.

(Text in red edited after assignment release)

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

    The location of the TNT block may be in any of the four squares which are destroyed by firing the laser. For simplicity, you can assume that there will always be at most only one TNT block in those four squares.
./slide
How many blocks? 121
Enter blocks:
2 2 1  2 3 1  2 4 1  2 5 1  2 6 1  2 7 1  2 8 1  2 9 1  2 10 1  2 11 1  2 12 1
3 2 1  3 3 1  3 4 1  3 5 1  3 6 1  3 7 1  3 8 1  3 9 1  3 10 1  3 11 1  3 12 1
4 2 1  4 3 1  4 4 1  4 5 1  4 6 1  4 7 1  4 8 1  4 9 1  4 10 1  4 11 1  4 12 1
5 2 1  5 3 1  5 4 1  5 5 1  5 6 1  5 7 1  5 8 1  5 9 1  5 10 1  5 11 1  5 12 1
6 2 1  6 3 1  6 4 1  6 5 1  6 6 1  6 7 1  6 8 1  6 9 1  6 10 1  6 11 1  6 12 1
7 2 1  7 3 1  7 4 1  7 5 1  7 6 1  7 7 5  7 8 1  7 9 1  7 10 1  7 11 1  7 12 1
8 2 1  8 3 1  8 4 1  8 5 1  8 6 1  8 7 1  8 8 1  8 9 1  8 10 1  8 11 1  8 12 1
9 2 1  9 3 1  9 4 1  9 5 1  9 6 1  9 7 1  9 8 1  9 9 1  9 10 1  9 11 1  9 12 1
10 2 1  10 3 1  10 4 1  10 5 1  10 6 1  10 7 1  10 8 1  10 9 1  10 10 1  10 11 1  10 12 1
11 2 1  11 3 1  11 4 1  11 5 1  11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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 
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 1 1 1 1 1 1 1 1 1 1 1 0 0 
  0 0 1 1 1 0 0 0 0 0 1 1 1 0 0 
  0 0 1 1 0 0 0 0 0 0 0 1 1 0 0 
  0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 
  0 0 1 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 1 0 0 0 0 0 0 0 0 0 1 0 0 
  0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 
  0 0 1 1 0 0 0 0 0 0 0 1 1 0 0 
  0 0 1 1 1 0 0 0 0 0 1 1 1 0 0 
  0 0 1 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

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

1511 autotest-stage 03 slide

Extension Work

Assignment 1 involves an Extension activity for students who have completed Stages 1 through 3. The extension will be worth marks that will affect your overall course mark, but it is considered work that is not necessary to prove your knowledge of the core principles and techniques taught in the course.

Marc's Note: If we'd wanted to, we could have called the Extension "Stage 4 and 5" of the Assignment (and we have done this in previous terms). However, we don't believe that what is in these stages is as important as what is in the first three stages. That's why they've been separated and there's a suggestion that it's not necessary to complete this part of the assignment. It's also why the Extension is worth so little marks compared to how much work it takes (and also compared to the rest of the Assignment).

In previous terms, less than half the course attempted these later stages of the assignment, but there was an implied pressure that people "should" somehow have to complete the entire Assignment, which was unnecessarily discouraging. In general, a mark of a Credit (65) in COMP1511 is enough to show that a student has understood enough of what is being taught to be able to continue happily in Computer Science, which means that full marks in any particular assessment is not necessary.

Once you have completed Stage 3 of Assignment 1, you can submit the following Extension Work. Before you do, you should ensure that the following is true:

  • Your code should have at least five functions you have written yourself.
  • None of your functions should be longer than 100 lines.
  • Your code should pass 1511 style with no issues. If it has any issues, you should discuss them with a tutor before proceeding.
  • All your normal labs should be complete.
  • While not essential, you should make sure that other Uni work you have is prioritized over this work.

COMP1511 reserves the right to disqualify your extension work if you do not meet the above requirements. Working on extension work is not an excuse for failure to submit your regular assignment, nor is it grounds for extension. Plagiarism of extension work will be particularly penalized.

The intent of extension work is to expose you to different parts of the software development experience. The major differences between regular work and extension work are:

  1. Extension work does not provide you a detailed specification -- we expect you to determine what the correct behaviour is from the sample solution.
  2. Extension work also requires you to test and document your own work -- this is very similar to how software developers at companies are expected to act.

While it is extension work, you must still follow the COMP1511 style guide, and your program must compile and run on CSE machines, using dcc.

To get setup for the extension, you will need to follow these instructions:

First, download this documentation file or use this command on your CSE account to copy the file into your current directory:

 cp -n /web/cs1511/21T1/activities/slide_ext/slide_docs.txt . 

You will use this file to submit your tests and documentation

Then, copy your slide.c file, like so:
cp -n slide.c slide_ext.c
Ensure you copy your slide.c file into a slide_ext.c file -- you must keep a copy of your non-extension work.

There are two extensions provided for this assignment. Each extension asks you to implement more complicated functionality. The second extension is more complicated than the first. The two extensions will not be tested at the same time (i.e you don't need to implement night mirror blocks). We require you to submit three things:

  1. For each extension you complete, a description of the work you have done, around 100 words long.
  2. For each extension you complete, two test cases which you have written to test the functionality of your extension work.
  3. One .c file which contains the code for both the regular stages, and the extension activities.

Extension activities will be marked in three stages:

Qualification Stage: Before the due date, you must ensure your extension work "qualifies" to be marked. To "qualify", you must:

  1. For each extension you complete, have at least 100 words to explain what changes you have made to your regular submission.
  2. For each extension you complete, you must have written two test cases. These test cases will be given as input to both your program and the sample solution. Each of your test cases must produce the same output from the sample solution as from your code.
  3. For each extension you complete, your code must pass the two given "qualification tests". These tests will be run when you submit your code, so you will know if you pass them before the due date.

Peer-Testing Stage: At this stage, after the due date, a subset of student tests will be run against every qualified extension submission. Marks will be awarded based on the percentage of tests you pass. In other words, other student's tests will be run against your own code.

Test Evaluation Stage: At this stage, after the due date, every test will be run against a subset of qualified extension submissions. If you didn't get full marks during Peer-Testing, you can make up for it by writing tests that other students do not pass. In other words, even if you fail some other tests, if you write a test that catches other people out, you can still get full marks!

Extension 1: Night Realm

Beware, There now exists a night realm! Blocks added to the night realm using a negative blocktype ie -1 will add its positive equivalent block to the night realm. For example, -1 is a BLOCK in the night realm, and -4 is a night-realm TNT of size 4.

Each time the user shifts left, the map is inverted (from day to night, or night to day) and that map is then shifted left.

You cannot create a map with only blocks in the night realm - as then the initial map is empty - which is against earlier clarifications in the spec.

This description does not contain all the details you need to implement night blocks -- you will need to use the reference solution to test further.

You can access the reference solution that has night blocks by running:

1511 slide_ext_night

An example slide_docs.txt

[COMP1511 Extension Work]

Write a summary of how you made the changes that you did:

[E1:Summary] {{{
The changes which I have implemented allow me to rotate between day and night mode.
I did this by changing my `main` function to support scanning in negative
numbers, making sure to change the if statements on line 123 to not
consider this invalid input.

I then changed line 700 to use a different mechanism, which let me print
out day-time and night-time mode. I had to make sure that my `use_laser`
function worked with night-time mode as well.

I then wrote two tests, which test for:
 - Winning against night time blocks; as well as
 - Losing against night time blocks
}}}

Write two tests to test your implementation of Extension 1 ("Night Realm").

[E1:Test 1] {{{
2
7 7 1
7 7 -1
2
3
}}}
[E1:Test 2] {{{
2
7 7 -1
7 7 1
7 8 -1
2
3
}}}

===========================================================================
...
New:

Extension work is submitted differently to regular work. To test your extension work, run:

 1511 autotest ass1_slide_ext slide_ext.c slide_docs.txt 

To submit your work, run:

 give cs1511 ass1_slide_ext slide_ext.c slide_docs.txt 

Extension 2: Mirror Blocks

What's better than one laser? Two lasers! This extension allows you to create "mirror" blocks, which split and redirect lasers perpendicular to the direction they started in, with half the strength they had before.

Mirror blocks have the value 2, as opposed to normal blocks (where their value is 1) or TNT (where their value is 4 to 9). When a laser hits a mirror block, it destroys it, and then the resulting laser shoots in both directions, perpendicular to the direction of the laser beforehand.

This description does not contain all the details you need to implement mirror blocks -- you will need to use the reference solution to test further.

You can access the reference solution that has mirror blocks by running:

1511 slide_ext_mirror
New:

Extension work is submitted differently to regular work. To test your extension work, run:

 1511 autotest ass1_slide_ext slide_ext.c slide_docs.txt 

To submit your work, run:

 give cs1511 ass1_slide_ext slide_ext.c slide_docs.txt 

Frequently Asked Questions

  • Can I share my test cases? You are welcome to discuss ways of breaking the reference solution; but you should not share the two test cases you submit with other people, or submit copies of other people's tests. If you want to submit tests with a similar idea, that's fine.
  • What about inputs of blocks that cause an integer overflow (i.e. entering more than a billion blocks)? We guarantee that you will not be tested of inputs more than a billion blocks.

Other Important Notes

Style

As with all programs you write, style is an important part of your Slide 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
slide.c
1511 style slide.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
slide.c        test1.in
dcc -o slide slide.c
./slide < 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
6 7 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 slide

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 slide_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 left" 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.

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 should submit intermediate versions of your assignment. Every time you autotest or submit, a copy will be saved as a backup. You can find those backups here, by logging in, and choosing the yellow button next to 'ass1_slide'.

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_slide slide.c

Assessment Scheme

This assignment will contribute 15% to your final mark.

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

15% 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. The utility 1511 style can help with this!

20% of the marks for this assignment will be based on the performance of any code or tests you write for the Extension component.

This is summarised in the table below:

Extension Core
Mirror Night Performance Style
10% 10% 65% 15%
Worth 15% of course mark

Marks for your performance will be allocated roughly according to the below scheme.

100% for Performance Completely working implementation of Stages 1-3
80% for Performance Completely working implementation of Stages 1 and 2
65% for Performance Completely working implementation of Stage 1
50% for Performance Partially working implementation of Stage 1 -- drawing a board and moving the laser

Marks for your style will be allocated roughly according to the scheme below

100% for Style Perfect style
90% for Style Great style, almost all style characteristics perfect.
80% for Style Good style, one or two style characteristics not well done.
70% for Style Good style, a few style characteristics not well done.
60% for Style OK style, an attempt at most style characteristics.
<= 50% for Style An attempt at style.

For the extension, your work Must Qualify to receive marks. If it does not qualify (i.e. it does not pass the autotests for that extension activity) it will not receive marks. If it does qualify, it will be marked based on the percentage of other students' tests it passes. If you pass all other students' night-realm tests, you will receive 10 marks. If you pass all other students' mirror block tests, you will receive 10 marks. You will receive extra marks based on how many other sample solutions your tests break. The scaling of the marks for those code-breaking tests will be determined after the due date.

Note that the following penalties apply to your total mark for plagiarism:
0 for the assignment Knowingly providing your work to anyone and it is subsequently submitted (by anyone).
0 for the assignment Submitting any other person's work. This includes joint work.
0 FL for COMP1511 Paying another person to complete work. Submitting another person's work without their consent.

The following is an indicative list of characteristics of your program that will be assessed, though your program will be assessed wholistically so other charactersitics may be assessed too:

  • Header Commenting.
  • Consistent, sensible indenting.
  • Using Blank Lines & Whitespace.
  • Using constants.
  • Decomposing code into functions where relevent (especially after Stage 2).
  • Using comments effectively (at least at top of functions, and not containing irrelevant info).

The course staff 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 29 March 2021 20: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
(2021-03-08 22:00)
  • Released first assignment version.
Version 1.0.1
(2021-03-10 10:30)
  • Clarified how TNT works.
Version 1.0.2
(2021-03-11 01:15)
  • Clarified EOF. Fixed output bug in TNT example.
Version 1.1.0
(2021-03-11 01:15)
  • Clarified Extension Marking. Updated release date for extension work.
Version 1.2.0
(2021-03-18 01:15)
  • Released Extension Submission.
  • Clarified purpose of extension work.
Version 1.2.1
(2021-03-20 20:15)
  • Clarified integer overflow in extension tests.