Assignment 1 - CS Ninja
Overview

CS Ninja is a small game where the player enters commands to move our ninja on the board to paint any unpainted tiles and is inspired by Ninja Painter (all trademarks are the property of their respective owners).
The aim of the game is to paint every unpainted tile without falling off the board!
We will begin by setting up the board, then add functionality to play the game and in the final stages, implement some more interesting mechanics!
Getting Started
- Create a new folder for your assignment:
mkdir ass1 cd ass1
- Fetch the starter code using the command below.
1511 fetch-activity cs_ninja
You should now have a file named cs_ninja.c
in your ass1
directory.
- Check that everything works by running the autotest:
1511 autotest cs_ninja
If you want to stop running the autotest before it finishes, press [Ctrl-C]
.
Program Structure
This is a summary of the program structure. It's included as an introduction to aid your overall understanding of the assignment. Detailed instructions will be included in later sections of the specification.
The program consists of two phases: a Setup Phase, and a Gameplay Phase.
Setup Phase
When the program starts, the Setup Phase begins, and a new game is created:
- An empty game board is initialised.
- Features (walls, ladders, unpainted tiles, paint buckets, stars) are added to the board.
- The ninja is spawned.
Gameplay Phase
When the Setup Phase is complete, the Gameplay Phase begins. In this phase, the ninja:
- Picks up paint buckets to change their paint brush.
- Paints unpainted tiles to unlock exits.
- Collects stars to earn points.
- Uses slam movements to get around the board quickly.
Reference Implementation
To help you understand the game, we've written a complete reference implementation which you can run in any CSE terminal with the command 1511 cs_ninja
. It implements every stage of the assignment. You can use this to test how your program should behave.
Try the following input in the reference implementation:
1511 cs_ninja w 6 3 l 3 6 b 5 5 1 u 1 2 1 e 7 5 s 1 2 3 7 7 w a s s s d d s s
These inputs will:
- Add a wall at
[6][3]
, a ladder at[3][6]
, a paint bucket at[5][5]
, an unpainted tile at[1][2]
and a locked exit at[7][5]
. - Spawn one star at
[2][3]
- Spawn the player at board position
[7][7]
. - Start the game.
- Move the player around the board.
You don't need to fully understand these inputs yet; they're only provided as a preview.
Starter Code and Data Structures
Starter code has been provided to help you get up and running. It contains a range of useful constants, structs, enums, and functions.
If you haven't done so already, test the 1511 cs_ninja
reference solution, then open the provided cs_ninja.c
and follow along with this introduction.
The main()
Function
A sample main()
function has been provided to get you started.
int main(void) {
printf("Welcome to CS Ninja!\n\n");
struct tile board[ROWS][COLS];
initialise_board(board);
print_board(board, NO_PLAYER, NO_PLAYER);
return 0;
}
Printing a Welcome Message
The first statement prints a welcome message followed by a blank line:
printf("Welcome to CS Ninja!\n\n");
Declaring the board
Array
The next statement declares the game board
.
struct tile board[ROWS][COLS];
This means that board
is a two-dimensional ROWS
-by-COLS
array, where each element is a struct tile
.
struct tile {
enum entity entity;
enum colour colour;
};
Each struct tile
currently contains two fields, an enum entity
and an enum colour
. This allows each element of the board
array to store a game feature (e.g. a wall, ladder, paint bucket, unpainted tiles or star) and a corresponding colour.
enum entity {
WALL,
PAINT_BUCKET,
EXIT_LOCKED,
PAINTED,
UNPAINTED,
EXIT_UNLOCKED,
LADDER,
STAR,
EMPTY
};
Each entity corresponds to a feature and a symbol that appears when the board is printed to the terminal:
Entity | Feature | Symbol |
---|---|---|
EMPTY |
Empty | |
WALL |
Wall | ||| |
LADDER |
Ladder | |=| |
PAINT_BUCKET |
Paint Bucket | \%c/ |
PAINTED |
Painted tile | %c |
UNPAINTED |
Unpainted tile | %c |
STAR |
Star | * |
EXIT_LOCKED |
Locked Exit | [X] |
EXIT_UNLOCKED |
Unlocked Exit | [ ] |
You might have noticed that in the table above that some of the symbols include %c
. This is because these entities have colours! By default, paint buckets will always be considered unpainted.
enum colour {
RED,
YELLOW,
GREEN,
BLUE,
PURPLE,
NO_COLOUR
};
Each colour corresponds to a symbol that appears when the board is printed to the terminal:
Colour | Symbol, Unpainted | Symbol, Painted |
---|---|---|
NO_COLOUR |
|
|
RED |
r |
R |
YELLOW |
y |
Y |
GREEN |
g |
G |
BLUE |
b |
B |
PURPLE |
p |
P |
Using the board
Array
We can use row and column indices to access board elements.
For example:
board[2][3]
accesses thestruct tile
at row 2 and column 3.board[2][3].entity
accesses theenum entity
of thisstruct tile
.board[2][3].colour
accesses theenum colour
of thisstruct tile
.
Similarly:
board[8][1]
accesses thestruct tile
at row 8 and column 1.board[8][1].entity
accesses theenum entity
of thisstruct tile
.board[8][1].colour
accesses theenum colour
of thisstruct tile
.
Figure 1 demonstrates how row and column indices can be used to access elements on the game board.
Initialising the board
Array
At this point, we have a board
array, but it hasn't been initialised with any values. The next statement passes the newly-declared board
array to the provided initialise_board()
function. This gives every tile entity an initial value of EMPTY
and every tile an initial colour of NO_COLOUR
:
initialise_board(board);
Printing the Game
Before exiting, main()
prints the board
in the terminal:
Welcome to CS Ninja! +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
It does this with the provided print_board()
function.
print_board(board, NO_PLAYER, NO_PLAYER);
The print_board()
function takes the following arguments:
- The
board
array. - The row position of the ninja. Since the ninja has not yet been placed on the board, we use the
#defined
constantNO_PLAYER
. - The column position of the ninja. Since the ninja has not yet been placed on the board, we use the
#defined
constantNO_PLAYER
.
You will need to know how to use print_board()
with different values. For example:
print_board(board, 2, 9)
displays the board with the ninja at the row 2, column 9.print_board(board, 0, 5)
displays the board with the ninja at the row 0, column 5.
print_board()
checks the enum entity
of each struct tile
to determine which feature to print. You don't need to understand how it works before starting the assignment.
Other Provided Functions
There are four more provided functions:
print_board_line()
is a helper function called byprint_board()
. You will not need to use it in your code.print_board_header()
is a helper function called byprint_board()
. You will not need to use it in your code.print_tile_spacer()
is a helper function called byprint_board()
. You will not need to use it in your code.print_board_statistics()
is a helper function provided to help you complete Stage 2.5.
FAQ
Q: Can I edit the provided code?
Yes! Feel free to modify/replace/discard any of the provided:
#define
constants,- enums,
- structs, and
- functions.
For example: you may wish to add fields to the provided struct tile
definition.
You are also encouraged to create your own constants, enums, structs, and helper functions.
Q: Can I use pointers?
Yes! You can use pointers, although, they're not required. It's possible to complete every stage of the assignment without using pointers.
Q: Can I use X other C feature?
For everything not taught in the course, check the Style Guide:
- If the guide says "avoid", it may incur a style mark penalty if not used correctly.
- If the guide says "illegal" or "do not use", it will result in a style mark penalty (see the Style Marking Rubric).
These rules exist to ensure that everyone develops the required foundational knowledge and to maintain a level playing field for all students.
Stages
The assignment has been divided into incremental stages.
Stage 1: Setup Phase
- Stage 1.1 - Feature Spawn (Walls, Paint Buckets, Exits, Unpainted Tiles, Ladders).
- Stage 1.2 - Add Long Ladder.
- Stage 1.3 - Handling Errors.
- Stage 1.4 - Add Stars.
- Stage 1.5 - Spawn Ninja.
Stage 2: Gameplay Phase (Ninja Turn)
- Stage 2.1 - Basic Ninja Movement.
- Stage 2.2 - Print Inventory.
- Stage 2.3 - Paint Tiles.
- Stage 2.4 - Print Points.
- Stage 2.5 - Print Board Statistics.
Stage 3: Gameplay Phase (Ninja Turn + Extra Mechanics)
- Stage 3.1 - Winning / Losing the game.
- Stage 3.2 - Ninja Slam.
- Stage 3.3 - Breakable Blocks.
- Stage 3.4 - Trampolines.
Stage 4: Gameplay Phase (Extra Mechanics)
- Stage 4.1 - Undoing Moves.
- Stage 4.2 - Hard Mode.
Extension (not for marks)
- SplashKit - Create and Share a Graphical User Interface.
Your Tasks
This assignment consists of four stages. Each stage builds on the work of the previous stage, and each stage has a higher complexity than its predecessor. You should complete the stages in order.
A video explanation to help you get started with the assignment can be found here:
Stage 1
In Stage 1, you will implement the Setup Phase of CS Ninja. This milestone has been divided into five substages:
- Stage 1.1 - Feature Spawn.
- Stage 1.2 - Spawn Long Ladder.
- Stage 1.3 - Handling Errors.
- Stage 1.4 - Spawn Stars.
- Stage 1.5 - Spawn Ninja.
Stage 1.1 - Feature Spawn
The first step of the Setup Phase is to add features to our game. By the end of this substage your program will prompt the user to add features and then display this on the game board.
The starter code:
- Prints a welcome message to CS Ninja.
- Declares the
board
array. - Initialises the board by setting every tile's entity to be
EMPTY
and every tile's colour toNO_COLOUR
. - Prints the
board
without showing the player.
A description of the starter code can be found in Starter Code and Data Structures.
Task
In this substage, you will modify the starter code to:
-
Print a heading indicating the start of the Setup Phase:
"--- Setup Phase ---\n"
. -
Implement a Setup Loop to repeatedly read-in commands and add features to the board until the stop command
s
.- Given the command
w [row] [col]
, add aWALL
to the board. - Given the command
b [row] [col] [colour]
, add aPAINT_BUCKET
to the board. - Given the command
e [row] [col]
, add anEXIT_LOCKED
to the board. - Given the command
u [row] [col] [colour]
, add anUNPAINTED
to the board. - Given the command
l [row] [col]
, add aLADDER
to the board.
- Given the command
-
When the user enters
s
.- The Setup Loop should end.
- The board should be displayed with the provided
print_board
function. - The program should exit.
Assumptions / Restrictions / Clarifications
- Input will only include valid positions until Stage 1.3.
- A position is considered valid if it is within the bounds of the board and the specified tile is empty.
- Input will only include valid colours until Stage 1.3.
- A colour is considered valid if it has a value between 0 and 4 inclusive.
For this substage and all future substages:
- The
row
andcol
entered will always be integers. - The
colour
entered will always be an integer.
Examples
Input:
w 1 1 w 5 5 w 6 2 s 0 9 9 q
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- w 1 1 w 5 5 w 6 2 s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Input:
b 3 2 0 b 5 6 3 b 7 8 2 b 0 6 1 b 1 9 4 s 0 9 9 q
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- b 3 2 0 b 5 6 3 b 7 8 2 b 0 6 1 b 1 9 4 s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + \Y/ + + + + + + + + + + + \P/ + + + + + + + + + + + + + + + + + + + + + + \R/ + + + + + + + + + + + + + + + + + + + + + + \B/ + + + + + + + + + + + + + + + + + + + + + + \G/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Input:
e 3 4 e 7 7 e 5 9 s 0 9 9 q
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- e 3 4 e 7 7 e 5 9 s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [X] + + + + + + + + + + + + + + + + + + + + + + [X] + + + + + + + + + + + + + + + + + + + + + + [X] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Input:
u 1 2 0 u 2 2 0 u 3 2 0 u 3 4 3 u 3 5 3 u 3 6 3 u 7 8 2 u 6 6 1 u 5 9 4 b 8 1 0 b 8 2 1 b 8 3 2 b 8 4 3 b 8 5 4 s 0 9 9 q
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- u 1 2 0 u 2 2 0 u 3 2 0 u 3 4 3 u 3 5 3 u 3 6 3 u 7 8 2 u 6 6 1 u 5 9 4 b 8 1 0 b 8 2 1 b 8 3 2 b 8 4 3 b 8 5 4 s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + r + + + + + + + + + + + r + + + + + + + + + + + r b b b + + + + + + + + + + + + + + + + + + + + + + p + + + + + + + + + + + y + + + + + + + + + + + g + + + + + + + + + + + \R/ \Y/ \G/ \B/ \P/ + + + + + + + + + + + + + + + + + + + + + +
Input:
l 0 0 l 7 8 l 2 3 l 3 5 s
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- l 0 0 l 7 8 l 2 3 l 3 5 s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + |=| + + + + + + + + + + + + + + + + + + + + + + |=| + + + + + + + + + + + |=| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |=| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Autotest
Stage 1.2 - Add Long Ladder
Task
In this substage, you will implement a command to add LADDER
tiles to the board as one continuous row or column.
You will need to:
Modify your Setup Loop from Stage 1.1 to handle a new L
command:
L [direction] [row] [col] [length]
This command specifies the:
- Direction of the ladder,
h
for horizontal andv
for vertical. - Start position of the ladder at
row
col
. - Length of the ladder with
length
.
After reading this command, your program should add LADDER
to every tile from the start position with the specified length.
Assumptions / Restrictions / Clarifications
- Input for direction will only be
h
orv
. - Input for
row
andcol
will only include valid positions until Stage 1.3. - Input for
length
will ensure that the long ladder is spawned within bounds until Stage 1.3. - Horizontal ladders increment towards the right.
- Vertical ladders increment towards the bottom.
Examples
Input:
L h 3 2 2 L h 3 6 2 L h 6 2 1 L h 6 7 1 L h 7 3 4 s
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- L h 3 2 2 L h 3 6 2 L h 6 2 1 L h 6 7 1 L h 7 3 4 s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |=| |=| |=| |=| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |=| |=| + + + + + + + + + + + |=| |=| |=| |=| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Input:
L v 1 2 3 L v 1 7 3 L v 4 4 2 L v 4 5 2 L v 7 3 1 L v 7 6 1 s
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- L v 1 2 3 L v 1 7 3 L v 4 4 2 L v 4 5 2 L v 7 3 1 L v 7 6 1 s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| |=| + + + + + + + + + + + |=| |=| + + + + + + + + + + + |=| |=| + + + + + + + + + + + |=| |=| + + + + + + + + + + + |=| |=| + + + + + + + + + + + + + + + + + + + + + + |=| |=| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Autotest
Stage 1.3 - Handling Errors
During the previous substages, we have ignored any invalid positions or colours provided. However, we can no longer rely on this assumption.
Task
- If the user attempts to place a feature in a position that's not on the board:
- Print
"ERROR: Invalid position, [row] [col] is out of bounds!\n"
. - Continue reading the next command.
- Print
- If the user attempts to place a feature on an occupied tile:
- Print
"ERROR: Invalid tile, [row] [col] is occupied!\n"
. - Continue reading the next command.
- Print
- If the user attempts to place an invalid colour:
- Print
"ERROR: Invalid colour!\n"
. - Continue reading the next command.
- Print
- If the user attempts to place a long ladder where the starting position is out of bounds:
- Print
"ERROR: Invalid position, [row] [col] is out of bounds!\n"
. - Continue reading the next command.
- Print
- If the user attempts to place a long ladder where part of the ladder is out of bounds:
- Print
"ERROR: Invalid position, part of the ladder is out of bounds!\n"
. - Continue reading the next command.
- Print
- If the user attempts to place a long ladder where part of the ladder is occupied by another tile:
- Print
"ERROR: Invalid tile, part of the ladder is occupied!\n"
. - Continue reading the next command.
- Print
Assumptions / Restrictions / Clarifications
- Error handling must follow the specified priority. For each command, identify and print only the first error in that order, if any.
Examples
Input:
w 10 0 l 5 10 e -1 3 l 9 -1 s
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- w 10 0 ERROR: Invalid position, 10 0 is out of bounds! l 5 10 ERROR: Invalid position, 5 10 is out of bounds! e -1 3 ERROR: Invalid position, -1 3 is out of bounds! l 9 -1 ERROR: Invalid position, 9 -1 is out of bounds! s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Input:
w 3 3 l 3 3 e 1 3 l 4 5 e 4 5 s
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- w 3 3 l 3 3 ERROR: Invalid tile, 3 3 is occupied! e 1 3 l 4 5 e 4 5 ERROR: Invalid tile, 4 5 is occupied! s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + [X] + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + |=| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Input:
b 3 4 -1 u 5 7 7 u 3 3 1 b 4 5 1 s
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- b 3 4 -1 ERROR: Invalid colour! u 5 7 7 ERROR: Invalid colour! u 3 3 1 b 4 5 1 s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + y + + + + + + + + + + + \Y/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Autotest
Stage 1.4 - Spawn Stars
We will now add stars that ninjas can collect on the board.
To complete this stage:
- Print the header
"--- Adding Stars ---\n"
. - Prompt the user for the number of stars to add:
"Enter the number of stars: "
. - Scan in the user input.
- If the user input is negative:
- Print
"ERROR: Invalid number of stars!\n"
. - Keep reading input in until
[num_stars]
is non-negative.
- Print
- If the user input is negative:
- Accept input in the format
[row] [col]
until we receive[num_stars]
pair(s) of valid input.- Handling of invalid input should follow Stage 1.3.
- Valid stars should be added to the board.
- Print the board at the conclusion of all stars being added.
Assumptions / Restrictions / Clarifications
- Nil.
Examples
Input:
s 1 1 1
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 1 1 1 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + * + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Input:
s -1 -3 1 1 1
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: -1 ERROR: Invalid number of stars! -3 ERROR: Invalid number of stars! 1 1 1 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + * + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Autotest
Stage 1.5 - Spawn Ninja
We will now spawn the ninja onto the board!
To complete this stage:
- Print the header
"--- Spawning Ninja ---\n"
. - Add a new loop to accept input in the format
[row] [col]
until we receive 1 pair of valid input.- Valid input refers to a position where the co-ordinates are within the bounds of the board and the specified tile is empty.
- Handling of invalid input should follow Stage 1.3.
- Print the board at the conclusion of the ninja being added.
Assumptions / Restrictions / Clarifications
- Nil.
Examples
Input:
s 0 0 0
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 0 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 0 0 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Input:
w 0 0 s 0 0 0 -3 1 3 -7 100 2 2 39 9 9
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- w 0 0 s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 0 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 0 0 ERROR: Invalid tile, 0 0 is occupied! -3 1 ERROR: Invalid position, -3 1 is out of bounds! 3 -7 ERROR: Invalid position, 3 -7 is out of bounds! 100 2 ERROR: Invalid position, 100 2 is out of bounds! 2 39 ERROR: Invalid position, 2 39 is out of bounds! 9 9 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + +
Autotest
Testing & Submission
Are you finished with this stage? If so, you should make sure to do the following:
- Run
1511 style
, and clean up any issues a human may have reading your code. Don't forget -- 20% of your mark in the assignment is based on style! - Autotest for this stage of the assignment by running the
autotest-stage
command as shown below. - Remember -- give early, and give often. Only your last submission counts, but why not be safe and submit right now?
1511 style cs_ninja.c 1511 autotest-stage 01 cs_ninja give cs1511 ass1_cs_ninja cs_ninja.c
Stage 2
In Stage 2, you will begin implementing the Gameplay Phase of CS Ninja. This milestone has been divided into five substages:
- Stage 2.1 - Basic Ninja Movement.
- Stage 2.2 - Print Inventory.
- Stage 2.3 - Paint Tiles.
- Stage 2.4 - Points.
- Stage 2.5 - Statistics.
Stage 2.1: Basic Ninja Movement
The first step of the Gameplay Phase is to introduce ninja movements. By the end of this substage, your program will allow the user to control the ninja and guide them around the game board.
Task
In this substage, you will need to:
-
Start the Gameplay Phase:
- Print
"--- Gameplay Phase ---\n"
. This indicates that the Setup Phase is complete, and the user can now start playing the game.
- Print
-
Implement a Gameplay Loop to repeatedly read-in and handle user commands:
- The first command to add to the Gameplay Loop is
q
to quit. - When the
q
command is entered by the user, the program should immediately:- Print
"--- Quitting Game ---\n"
. - Exit without any other outputs.
- Print
- The first command to add to the Gameplay Loop is
-
Begin the Ninja Turn:
- The next Gameplay Loop commands are ninja movements:
w
moves the ninja up.a
moves the ninja left.s
moves the ninja down.d
moves the ninja right.
- When the user enters one of these commands, if it is a valid destination, move the ninja one tile in the corresponding direction.
- A destination is considered invalid if it meets any of the following conditions:
- The tile contains a
WALL
.
- The tile contains a
- The next Gameplay Loop commands are ninja movements:
-
End the Ninja Turn and finish the round:
- Display the board with the provided
print_board()
function. This completes the round. - Reminder: this is a Gameplay Loop. After each command is processed/handled, the program should continue to read and handle the next user command until
q
is pressed.
- Display the board with the provided
Assumptions / Restrictions / Clarifications
When your code is tested in this substage:
- No movement command will attempt to move the ninja off the board.
Examples
Input:
s 0 5 5 w a s d q
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 0 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 5 5 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Gameplay Phase --- w +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + d +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + q --- Quitting Game ---
Input:
s 0 5 5 q
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 0 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 5 5 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Gameplay Phase --- q --- Quitting Game ---
Input:
w 4 4 s 0 5 5 w a a w a s s a s d d s q
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- w 4 4 s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 0 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 5 5 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Gameplay Phase --- w +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + w +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + d +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + d +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + q --- Quitting Game ---
Input:
w 4 4 l 3 3 b 3 5 2 u 6 7 2 s 0 5 5 w w a a s d s s d d d d s q
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- w 4 4 l 3 3 b 3 5 2 u 6 7 2 s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |=| \G/ + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + g + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 0 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |=| \G/ + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + g + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 5 5 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |=| \G/ + + + + + + + + + + + ||| + + + + + + + + + + + ^_^ + + + + + + + + + + + g + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Gameplay Phase --- w +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |=| \G/ + + + + + + + + + + + ||| ^_^ + + + + + + + + + + + + + + + + + + + + + + g + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + w +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |=| ^_^ + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + g + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |=| ^_^ \G/ + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + g + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ \G/ + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + g + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |=| \G/ + + + + + + + + + + + ^_^ ||| + + + + + + + + + + + + + + + + + + + + + + g + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + d +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |=| \G/ + + + + + + + + + + + ^_^ ||| + + + + + + + + + + + + + + + + + + + + + + g + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |=| \G/ + + + + + + + + + + + ||| + + + + + + + + + + + ^_^ + + + + + + + + + + + g + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |=| \G/ + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + ^_^ g + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + d +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |=| \G/ + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + ^_^ g + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + d +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |=| \G/ + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + ^_^ g + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + d +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |=| \G/ + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + ^_^ g + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + d +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |=| \G/ + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |=| \G/ + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + G + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + q --- Quitting Game ---
Autotest
Stage 2.2: Print Inventory
In this substage, you will need to:
-
Implement the Collection mechanic to collect paint buckets.
- If the ninja moves onto a tile containing a
PAINT_BUCKET
, the ninja's paintbrush now has the same colour as the paint bucket.
- If the ninja moves onto a tile containing a
-
Modify the Gameplay Loop to handle a new
i
command that prints the ninja's inventory:- When the
i
command is entered, print"Holding [colour] paintbrush!\n"
where[colour]
is the string representation of the colour of the paintbrush.- If the ninja is holding the
NO_COLOUR
paintbrush, print the stringNO COLOUR
. - If the ninja is holding the
RED
paintbrush, print the stringRED
. - If the ninja is holding the
YELLOW
paintbrush, print the stringYELLOW
. - If the ninja is holding the
GREEN
paintbrush, print the stringGREEN
. - If the ninja is holding the
BLUE
paintbrush, print the stringBLUE
. - If the ninja is holding the
PURPLE
paintbrush, print the stringPURPLE
.
- If the ninja is holding the
- When the
Assumptions / Restrictions / Clarifications
- A ninja can only have one paintbrush.
- A ninja starts with having
NO_COLOUR
on their paintbrush.
Examples
Input:
s 0 3 4 i q
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 0 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 3 4 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Gameplay Phase --- i Holding NO COLOUR paintbrush! q --- Quitting Game ---
Input:
b 3 3 0 s 0 3 4 i a i a i q
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- b 3 3 0 s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \R/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 0 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \R/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 3 4 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \R/ ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Gameplay Phase --- i Holding NO COLOUR paintbrush! a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + i Holding RED paintbrush! a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ \R/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + i Holding RED paintbrush! q --- Quitting Game ---
Autotest
Stage 2.3: Paint Tiles
In this substage, you will need to:
- Modify your Ninja Movement mechanic to include painting tiles.
- If the ninja moves onto a
UNPAINTED
tile AND the ninja is holding the associated paintbrush, mark the tile asPAINTED
.
- If the ninja moves onto a
- Update every
EXIT_LOCKED
tile to beEXIT_UNLOCKED
if and only if all tiles are painted.- If there are no unpainted tiles on the board, then all
EXIT_LOCKED
tiles should be updated toEXIT_UNLOCKED
before entering the Gameplay loop.
- If there are no unpainted tiles on the board, then all
Assumptions / Restrictions / Clarifications
- Ninjas can move onto a painted tile.
Examples
Input:
b 3 3 0 e 2 2 u 1 2 0 u 1 1 0 u 1 3 0 e 2 3 s 0 3 4 a w w a a a q
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- b 3 3 0 e 2 2 u 1 2 0 u 1 1 0 u 1 3 0 e 2 3 s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + r r r + + + + + + + + + + + [X] [X] + + + + + + + + + + + \R/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 0 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + r r r + + + + + + + + + + + [X] [X] + + + + + + + + + + + \R/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 3 4 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + r r r + + + + + + + + + + + [X] [X] + + + + + + + + + + + \R/ ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Gameplay Phase --- a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + r r r + + + + + + + + + + + [X] [X] + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + w +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + r r r + + + + + + + + + + + [X] ^_^ + + + + + + + + + + + \R/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + w +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + r r ^_^ + + + + + + + + + + + [X] [X] + + + + + + + + + + + \R/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + r ^_^ R + + + + + + + + + + + [X] [X] + + + + + + + + + + + \R/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + ^_^ R R + + + + + + + + + + + [ ] [ ] + + + + + + + + + + + \R/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + ^_^ R R R + + + + + + + + + + + [ ] [ ] + + + + + + + + + + + \R/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + q --- Quitting Game ---
Input:
b 3 3 1 u 5 5 1 b 4 5 0 s 0 7 7 w w w a a i s s q
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- b 3 3 1 u 5 5 1 b 4 5 0 s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \Y/ + + + + + + + + + + + \R/ + + + + + + + + + + + y + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 0 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \Y/ + + + + + + + + + + + \R/ + + + + + + + + + + + y + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 7 7 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \Y/ + + + + + + + + + + + \R/ + + + + + + + + + + + y + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Gameplay Phase --- w +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \Y/ + + + + + + + + + + + \R/ + + + + + + + + + + + y + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + w +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \Y/ + + + + + + + + + + + \R/ + + + + + + + + + + + y ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + w +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \Y/ + + + + + + + + + + + \R/ ^_^ + + + + + + + + + + + y + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \Y/ + + + + + + + + + + + \R/ ^_^ + + + + + + + + + + + y + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \Y/ + + + + + + + + + + + ^_^ + + + + + + + + + + + y + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + i Holding RED paintbrush! s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \Y/ + + + + + + + + + + + \R/ + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \Y/ + + + + + + + + + + + \R/ + + + + + + + + + + + y + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + q --- Quitting Game ---
Input:
b 3 3 1 u 5 5 1 u 4 5 1 b 3 5 0 u 2 3 0 w 3 2 l 1 5 s 0 7 7 w w w w a a a a s d d s i w w w i w a a s a q
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- b 3 3 1 u 5 5 1 u 4 5 1 b 3 5 0 u 2 3 0 w 3 2 l 1 5 s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| + + + + + + + + + + + r + + + + + + + + + + + ||| \Y/ \R/ + + + + + + + + + + + y + + + + + + + + + + + y + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 0 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| + + + + + + + + + + + r + + + + + + + + + + + ||| \Y/ \R/ + + + + + + + + + + + y + + + + + + + + + + + y + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 7 7 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| + + + + + + + + + + + r + + + + + + + + + + + ||| \Y/ \R/ + + + + + + + + + + + y + + + + + + + + + + + y + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Gameplay Phase --- w +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| + + + + + + + + + + + r + + + + + + + + + + + ||| \Y/ \R/ + + + + + + + + + + + y + + + + + + + + + + + y + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + w +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| + + + + + + + + + + + r + + + + + + + + + + + ||| \Y/ \R/ + + + + + + + + + + + y + + + + + + + + + + + y ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + w +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| + + + + + + + + + + + r + + + + + + + + + + + ||| \Y/ \R/ + + + + + + + + + + + y ^_^ + + + + + + + + + + + y + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + w +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| + + + + + + + + + + + r + + + + + + + + + + + ||| \Y/ \R/ ^_^ + + + + + + + + + + + y + + + + + + + + + + + y + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| + + + + + + + + + + + r + + + + + + + + + + + ||| \Y/ \R/ ^_^ + + + + + + + + + + + y + + + + + + + + + + + y + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| + + + + + + + + + + + r + + + + + + + + + + + ||| \Y/ ^_^ + + + + + + + + + + + y + + + + + + + + + + + y + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| + + + + + + + + + + + r + + + + + + + + + + + ||| \Y/ ^_^ \R/ + + + + + + + + + + + y + + + + + + + + + + + y + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| + + + + + + + + + + + r + + + + + + + + + + + ||| ^_^ \R/ + + + + + + + + + + + y + + + + + + + + + + + y + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| + + + + + + + + + + + r + + + + + + + + + + + ||| \Y/ \R/ + + + + + + + + + + + ^_^ y + + + + + + + + + + + y + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + d +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| + + + + + + + + + + + r + + + + + + + + + + + ||| \Y/ \R/ + + + + + + + + + + + ^_^ y + + + + + + + + + + + y + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + d +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| + + + + + + + + + + + r + + + + + + + + + + + ||| \Y/ \R/ + + + + + + + + + + + ^_^ + + + + + + + + + + + y + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| + + + + + + + + + + + r + + + + + + + + + + + ||| \Y/ \R/ + + + + + + + + + + + Y + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + i Holding YELLOW paintbrush! w +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| + + + + + + + + + + + r + + + + + + + + + + + ||| \Y/ \R/ + + + + + + + + + + + ^_^ + + + + + + + + + + + Y + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + w +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| + + + + + + + + + + + r + + + + + + + + + + + ||| \Y/ ^_^ + + + + + + + + + + + Y + + + + + + + + + + + Y + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + w +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| + + + + + + + + + + + r ^_^ + + + + + + + + + + + ||| \Y/ \R/ + + + + + + + + + + + Y + + + + + + + + + + + Y + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + i Holding RED paintbrush! w +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + r + + + + + + + + + + + ||| \Y/ \R/ + + + + + + + + + + + Y + + + + + + + + + + + Y + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + ^_^ |=| + + + + + + + + + + + r + + + + + + + + + + + ||| \Y/ \R/ + + + + + + + + + + + Y + + + + + + + + + + + Y + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + ^_^ |=| + + + + + + + + + + + r + + + + + + + + + + + ||| \Y/ \R/ + + + + + + + + + + + Y + + + + + + + + + + + Y + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| + + + + + + + + + + + ^_^ + + + + + + + + + + + ||| \Y/ \R/ + + + + + + + + + + + Y + + + + + + + + + + + Y + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| + + + + + + + + + + + ^_^ R + + + + + + + + + + + ||| \Y/ \R/ + + + + + + + + + + + Y + + + + + + + + + + + Y + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + q --- Quitting Game ---
Autotest
Stage 2.4: Points
- Implement a Points mechanic to keep track of points:
- If the ninja paints an unpainted tile:
- Add
1
point to the ninja's score.
- Add
- If the ninja moves onto a tile containing
STAR
:- Remove the
STAR
from the tile by assigning its entity toEMPTY
. - Add
20
points to the ninja's score.
- Remove the
- If the ninja paints an unpainted tile:
- Modify the Gameplay Loop to handle a new
p
command that prints the ninja's current score:- When the
p
command is entered, print"You have [score] point(s)!\n"
where[score]
is the ninja's score.
- When the
Assumptions / Restrictions / Clarifications
- The ninja starts the game with
0
points.
Examples
Input:
s 0 4 4 p q
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 0 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 4 4 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Gameplay Phase --- p You have 0 point(s)! q --- Quitting Game ---
Input:
b 3 3 0 u 1 2 0 u 1 1 0 u 1 3 0 s 0 3 4 a w p w p a p a p a p q
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- b 3 3 0 u 1 2 0 u 1 1 0 u 1 3 0 s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + r r r + + + + + + + + + + + + + + + + + + + + + + \R/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 0 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + r r r + + + + + + + + + + + + + + + + + + + + + + \R/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 3 4 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + r r r + + + + + + + + + + + + + + + + + + + + + + \R/ ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Gameplay Phase --- a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + r r r + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + w +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + r r r + + + + + + + + + + + ^_^ + + + + + + + + + + + \R/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + p You have 0 point(s)! w +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + r r ^_^ + + + + + + + + + + + + + + + + + + + + + + \R/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + p You have 1 point(s)! a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + r ^_^ R + + + + + + + + + + + + + + + + + + + + + + \R/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + p You have 2 point(s)! a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + ^_^ R R + + + + + + + + + + + + + + + + + + + + + + \R/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + p You have 3 point(s)! a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + ^_^ R R R + + + + + + + + + + + + + + + + + + + + + + \R/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + p You have 3 point(s)! q --- Quitting Game ---
Input:
s 1 3 4 4 4 p w p s p q
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 1 3 4 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + * + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 4 4 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + * + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Gameplay Phase --- p You have 0 point(s)! w +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + p You have 20 point(s)! s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + p You have 20 point(s)! q --- Quitting Game ---
Autotest
Stage 2.5 - Statistics
In previous substages, the ninja collected stars and earned points. It's expected that many in the CS Ninja community will enjoy keeping track of their accomplishments. By the end of this stage, your program will allow the user to display a concise table of stats to monitor their progress toward completing the level.
Task
In this substage, you will need to:
-
Modify the Gameplay Loop to handle a new
m
command that prints board statistics. When them
command is entered, the program will need to check the game board and:-
Count the number of unpainted tiles, grouped by colour.
-
Calculate the "collectible completion" percentage. This is the proportion of painted tiles on the board. It is defined by the following formula:
completion_percentage = 100.0 * num_painted / num_total_paintable
Where:
num_painted
is the number of painted tiles.num_total_paintable
is the number of tiles that could be painted by the ninja when the game starts.
-
Calculate the maximum number of points remaining. This is the number of additional points that could be scored by the ninja if they paint all remaining
UNPAINTED
tiles and collect allSTAR
tiles from the board. -
Call the provided
print_board_statistics()
function to display this information to the ninja.
-
Assumptions / Restrictions / Clarifications
- If there are no unpainted tiles to start with, the completion status is 100%.
Examples
Input:
s 1 3 4 4 4 m q
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 1 3 4 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + * + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 4 4 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + * + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Gameplay Phase --- m ========= Board Statistics ========= Unpainted Tiles Remaining by Colour: - RED: 0 - YELLOW: 0 - GREEN: 0 - BLUE: 0 - PURPLE: 0 Completion Status: - Paint Status: 100.0% - Maximum Points Remaining: 20 ================================== q --- Quitting Game ---
Input:
b 3 3 0 u 1 2 0 u 1 1 0 u 1 3 0 s 1 3 4 4 4 m w a w m w m a m a m a m q
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- b 3 3 0 u 1 2 0 u 1 1 0 u 1 3 0 s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + r r r + + + + + + + + + + + + + + + + + + + + + + \R/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 1 3 4 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + r r r + + + + + + + + + + + + + + + + + + + + + + \R/ * + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 4 4 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + r r r + + + + + + + + + + + + + + + + + + + + + + \R/ * + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Gameplay Phase --- m ========= Board Statistics ========= Unpainted Tiles Remaining by Colour: - RED: 3 - YELLOW: 0 - GREEN: 0 - BLUE: 0 - PURPLE: 0 Completion Status: - Paint Status: 0.0% - Maximum Points Remaining: 23 ================================== w +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + r r r + + + + + + + + + + + + + + + + + + + + + + \R/ ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + r r r + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + w +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + r r r + + + + + + + + + + + ^_^ + + + + + + + + + + + \R/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + m ========= Board Statistics ========= Unpainted Tiles Remaining by Colour: - RED: 3 - YELLOW: 0 - GREEN: 0 - BLUE: 0 - PURPLE: 0 Completion Status: - Paint Status: 0.0% - Maximum Points Remaining: 3 ================================== w +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + r r ^_^ + + + + + + + + + + + + + + + + + + + + + + \R/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + m ========= Board Statistics ========= Unpainted Tiles Remaining by Colour: - RED: 2 - YELLOW: 0 - GREEN: 0 - BLUE: 0 - PURPLE: 0 Completion Status: - Paint Status: 33.3% - Maximum Points Remaining: 2 ================================== a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + r ^_^ R + + + + + + + + + + + + + + + + + + + + + + \R/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + m ========= Board Statistics ========= Unpainted Tiles Remaining by Colour: - RED: 1 - YELLOW: 0 - GREEN: 0 - BLUE: 0 - PURPLE: 0 Completion Status: - Paint Status: 66.7% - Maximum Points Remaining: 1 ================================== a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + ^_^ R R + + + + + + + + + + + + + + + + + + + + + + \R/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + m ========= Board Statistics ========= Unpainted Tiles Remaining by Colour: - RED: 0 - YELLOW: 0 - GREEN: 0 - BLUE: 0 - PURPLE: 0 Completion Status: - Paint Status: 100.0% - Maximum Points Remaining: 0 ================================== a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + ^_^ R R R + + + + + + + + + + + + + + + + + + + + + + \R/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + m ========= Board Statistics ========= Unpainted Tiles Remaining by Colour: - RED: 0 - YELLOW: 0 - GREEN: 0 - BLUE: 0 - PURPLE: 0 Completion Status: - Paint Status: 100.0% - Maximum Points Remaining: 0 ================================== q --- Quitting Game ---
Autotest
Testing & Submission
Are you finished with this stage? If so, you should make sure to do the following:
- Run
1511 style
, and clean up any issues a human may have reading your code. Don't forget -- 20% of your mark in the assignment is based on style! - Autotest for this stage of the assignment by running the
autotest-stage
command as shown below. - Remember -- give early, and give often. Only your last submission counts, but why not be safe and submit right now?
1511 style cs_ninja.c 1511 autotest-stage 02 cs_ninja give cs1511 ass1_cs_ninja cs_ninja.c
Stage 3
In Stage 3, you will continue implementing the Gameplay Phase of CS Ninja. This milestone has been divided into four substages:
- Stage 3.1 - Winning / Losing the game.
- Stage 3.2 - Ninja Slam.
- Stage 3.3 - Breakable Blocks.
- Stage 3.4 - Trampolines.
By the end of this stage, you will have brought the core features of CS Ninja to life, allowing it to stand on its own while still leaving room for additional features!
Stage 3.1 - Winning / Losing the game
Task
In this substage, you will need to:
-
Handle when the ninja wins.
- A ninja wins when they stand on an unlocked exit.
- Print
"--- Game Over ---\n"
. - Print
"Congratulations!\n"
. - Exit the program.
-
Handle when the ninja loses.
- A ninja loses when they fall off the board, i.e. they have moved to a tile that is not located on the board.
- Print the updated board without the ninja.
- Print
"--- Game Over ---\n"
. - Print
"You lost!\n"
. - Print board statistics, as per Stage 2.5.
- Exit the program.
Assumptions / Restrictions / Clarifications
- Nil.
Examples
Input:
e 5 5 s 0 6 6 w a
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- e 5 5 s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [X] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 0 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [X] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 6 6 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [X] + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Gameplay Phase --- w +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [ ] ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Game Over --- Congratulations!
Input:
s 0 0 0 w
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 0 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 0 0 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Gameplay Phase --- w +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Game Over --- You lost! ========= Board Statistics ========= Unpainted Tiles Remaining by Colour: - RED: 0 - YELLOW: 0 - GREEN: 0 - BLUE: 0 - PURPLE: 0 Completion Status: - Paint Status: 100.0% - Maximum Points Remaining: 0 ==================================
Input:
w 6 5 u 3 5 4 b 2 5 4 e 5 5 s 1 4 5 0 5 s s i s p s m s
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- w 6 5 u 3 5 4 b 2 5 4 e 5 5 s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \P/ + + + + + + + + + + + p + + + + + + + + + + + + + + + + + + + + + + [X] + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 1 4 5 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \P/ + + + + + + + + + + + p + + + + + + + + + + + * + + + + + + + + + + + [X] + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 0 5 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + \P/ + + + + + + + + + + + p + + + + + + + + + + + * + + + + + + + + + + + [X] + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Gameplay Phase --- s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + \P/ + + + + + + + + + + + p + + + + + + + + + + + * + + + + + + + + + + + [X] + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + p + + + + + + + + + + + * + + + + + + + + + + + [X] + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + i Holding PURPLE paintbrush! s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \P/ + + + + + + + + + + + ^_^ + + + + + + + + + + + * + + + + + + + + + + + [ ] + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + p You have 1 point(s)! s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \P/ + + + + + + + + + + + P + + + + + + + + + + + ^_^ + + + + + + + + + + + [ ] + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + m ========= Board Statistics ========= Unpainted Tiles Remaining by Colour: - RED: 0 - YELLOW: 0 - GREEN: 0 - BLUE: 0 - PURPLE: 0 Completion Status: - Paint Status: 100.0% - Maximum Points Remaining: 0 ================================== s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \P/ + + + + + + + + + + + P + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Game Over --- Congratulations!
Autotest
Stage 3.2 - Ninja Slam
Users have noted that moving one tile at a time is too slow! So we will implement some advance movement in the form of slams.
Task
In this substage, you will need to:
- Modify the Gameplay Loop to handle four commands:
W
slams the ninja up.A
slams the ninja left.S
slams the ninja down.D
slams the ninja right.
- When the user enters one of these commands, move the ninja in the corresponding direction until the ninja encounters a:
WALL
tile, which will stop the ninja one tile prior to the wall.LADDER
tile, which will stop the ninja on the ladder.
Assumptions / Restrictions / Clarifications
- Slamming between two adjacent ladders is equivalent to conducting one basic movement.
- Ninjas will still paint tiles, collect paint buckets and collect stars during a slam movement.
- Exits can unlock during a slam movement.
- Slamming into an unlocked exit results in a win.
Examples
Input:
w 4 8 L h 1 5 3 s 0 4 3 D W A a q
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- w 4 8 L h 1 5 3 s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| |=| |=| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 0 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| |=| |=| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 4 3 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| |=| |=| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Gameplay Phase --- D +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| |=| |=| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + W +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| |=| ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + A +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| ^_^ |=| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + ^_^ |=| |=| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + q --- Quitting Game ---
Input:
w 4 8 L h 1 5 3 s 0 4 3 D S
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- w 4 8 L h 1 5 3 s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| |=| |=| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 0 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| |=| |=| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 4 3 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| |=| |=| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Gameplay Phase --- D +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| |=| |=| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + S +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + |=| |=| |=| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Game Over --- You lost! ========= Board Statistics ========= Unpainted Tiles Remaining by Colour: - RED: 0 - YELLOW: 0 - GREEN: 0 - BLUE: 0 - PURPLE: 0 Completion Status: - Paint Status: 100.0% - Maximum Points Remaining: 0 ==================================
Input:
b 4 1 3 u 4 2 3 u 4 3 3 u 4 4 3 u 4 5 3 u 4 6 3 u 4 7 3 e 4 8 s 0 4 0 D
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- b 4 1 3 u 4 2 3 u 4 3 3 u 4 4 3 u 4 5 3 u 4 6 3 u 4 7 3 e 4 8 s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \B/ b b b b b b [X] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 0 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \B/ b b b b b b [X] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 4 0 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ \B/ b b b b b b [X] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Gameplay Phase --- D +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \B/ B B B B B B ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Game Over --- Congratulations!
Autotest
Stage 3.3 - Breakable Blocks
Task
In this substage, you will need to:
- Modify your Setup loop to add
GLASS
g [row] [col]
. - Modify your ninja movement to handle interaction with glass.
- Glass has a durability of one and will break when:
- The ninja walks into the glass, with the ninja stopping one tile prior to the glass.
- The ninja slams into the glass, with the ninja stopping one tile prior to the glass.
- If glass is broken, it should be removed from the board and updated to
EMPTY
.
- Glass has a durability of one and will break when:
- Update the
print_board()
function to handle the printing ofGLASS
which is represented by|
.
Assumptions / Restrictions / Clarifications
- Nil.
Examples
Input:
g 1 1 g 3 19 g 4 -4 g 5 5 g -1 3 w 3 3 g 3 3 s 0 7 7 q
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- g 1 1 g 3 19 ERROR: Invalid position, 3 19 is out of bounds! g 4 -4 ERROR: Invalid position, 4 -4 is out of bounds! g 5 5 g -1 3 ERROR: Invalid position, -1 3 is out of bounds! w 3 3 g 3 3 ERROR: Invalid tile, 3 3 is occupied! s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + | + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 0 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + | + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 7 7 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + | + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + | + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Gameplay Phase --- q --- Quitting Game ---
Input:
w 3 3 g 3 5 g 4 4 l 6 4 s 0 3 7 A A s S q
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- w 3 3 g 3 5 g 4 4 l 6 4 s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| | + + + + + + + + + + + | + + + + + + + + + + + + + + + + + + + + + + |=| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 0 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| | + + + + + + + + + + + | + + + + + + + + + + + + + + + + + + + + + + |=| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 3 7 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| | ^_^ + + + + + + + + + + + | + + + + + + + + + + + + + + + + + + + + + + |=| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Gameplay Phase --- A +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| ^_^ + + + + + + + + + + + | + + + + + + + + + + + + + + + + + + + + + + |=| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + A +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| ^_^ + + + + + + + + + + + | + + + + + + + + + + + + + + + + + + + + + + |=| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |=| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + S +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + q --- Quitting Game ---
Autotest
Stage 3.4 - Trampolines
We will now introduce an advanced movement to allow players to navigate around the board faster than ever. Ninjas can use trampolines to leverage rebound movements to get around the board.
Task
In this substage, you will need to:
-
Modify your Setup loop to add
TRAMPOLINE
t [row] [col] [direction1] [direction2]
.direction1
anddirection2
are provided as integers.0
representsNORTH
, which is upwards,1
representsEAST
, which is to the right.2
representsSOUTH
, which is downward.3
representsWEST
, which is to the left.- For example, for the following command
t 8 9 0 1
represents a trampoline at position(8, 9)
with directionsNORTH
andEAST
. - Directions can be provided in any order. i.e. a
t 8 9 0 1
trampoline is the same ast 8 9 1 0
. - Follow any error handling as per Stage 1.3.
-
Modify your Ninja Movement to handle interaction with trampolines:
-
A ninja can use the trampoline if they approach the trampoline in the opposite direction of the trampoline's provided directions, i.e. trampolines are two-way.
-
Using the above example of the
t 8 9 0 1
trampoline:- If a ninja is moving in a
SOUTH
direction and hits the trampoline, the ninja well be redirected towards theEAST
.
- If a ninja is moving in a
WEST
direction and hits the trampoline, the ninja well be redirected towards theNORTH
.
- If a ninja is moving in a
-
-
If the ninja travels in the same direction as the trampoline's provided directions, the behaviour is the same of a
WALL
, i.e. the ninja is stopped.-
Again, using our above example of the
t 8 9 0 1
trampoline:- If a ninja is moving in a
NORTH
direction and hits the trampoline, the ninja stops moving. - If a ninja is moving in an
EAST
direction and hits the trampoline, the ninja stops moving.
- If a ninja is moving in a
-
-
-
Modify the provided
print_board()
function to print trampolines.- There are only four valid trampolines.
- Trampolines are represented with three characters:
- A
NORTH
EAST
trampoline is represented by:|_\
- A
NORTH
WEST
trampoline is represented by:/_|
- A
SOUTH
EAST
trampoline is represented by:|*/
- A
SOUTH
WEST
trampoline is represented by:\*|
- A
Assumptions / Restrictions / Clarifications
- The maximum number of trampolines a ninja can take in one move is three. After three rebounds, stop one tile before the trampoline.
- Valid trampoline commands have one vertical (
NORTH
orSOUTH
) direction and one horizontal (EAST
orWEST
) direction. - You will only get provided valid trampoline directions.
- If a ninja slams into a trampoline, the slam movement continues in the new direction.
- If a
WALL
orGLASS
immediately blocks the rebound path of the ninja after using a trampoline, the ninja uses the trampoline and immediately rebounds back upon hitting the obstacle. See Example 3.4.4.
Examples
Input:
t 2 2 1 2 t 6 2 0 1 t 6 7 3 0 t 2 7 2 3 s 0 2 5 q
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- t 2 2 1 2 t 6 2 0 1 t 6 7 3 0 t 2 7 2 3 s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ \*| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |_\ /_| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 0 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ \*| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |_\ /_| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 2 5 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ ^_^ \*| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |_\ /_| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Gameplay Phase --- q --- Quitting Game ---
Input:
t 2 2 1 2 w 6 2 s 0 2 5 A q
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- t 2 2 1 2 w 6 2 s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 0 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 2 5 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Gameplay Phase --- A +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + q --- Quitting Game ---
Input:
t 2 2 1 2 t 6 2 0 1 t 6 7 3 0 t 2 7 2 3 s 0 2 5 A W q
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- t 2 2 1 2 t 6 2 0 1 t 6 7 3 0 t 2 7 2 3 s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ \*| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |_\ /_| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 0 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ \*| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |_\ /_| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 2 5 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ ^_^ \*| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |_\ /_| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Gameplay Phase --- A +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ \*| + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |_\ /_| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + W +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ \*| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |_\ ^_^ /_| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + q --- Quitting Game ---
Input:
t 2 2 1 2 g 3 2 t 6 2 0 1 w 6 3 t 6 7 3 0 s 0 2 5 A A W
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- t 2 2 1 2 g 3 2 t 6 2 0 1 w 6 3 t 6 7 3 0 s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ + + + + + + + + + + + | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |_\ ||| /_| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 0 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ + + + + + + + + + + + | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |_\ ||| /_| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 2 5 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ ^_^ + + + + + + + + + + + | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |_\ ||| /_| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Gameplay Phase --- A +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |_\ ||| /_| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + A +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + |_\ ||| /_| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + W +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |_\ ||| /_| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Game Over --- You lost! ========= Board Statistics ========= Unpainted Tiles Remaining by Colour: - RED: 0 - YELLOW: 0 - GREEN: 0 - BLUE: 0 - PURPLE: 0 Completion Status: - Paint Status: 100.0% - Maximum Points Remaining: 0 ==================================
Autotest
Testing & Submission
Are you finished with this stage? If so, you should make sure to do the following:
- Run
1511 style
, and clean up any issues a human may have reading your code. Don't forget -- 20% of your mark in the assignment is based on style! - Autotest for this stage of the assignment by running the
autotest-stage
command as shown below. - Remember -- give early, and give often. Only your last submission counts, but why not be safe and submit right now?
1511 style cs_ninja.c 1511 autotest-stage 03 cs_ninja give cs1511 ass1_cs_ninja cs_ninja.c
Stage 4
Welcome to Stage 4! In this stage you will have to opportunity to extend the core functionality of CS Ninja with some advanced features. This milestone consists of two substages:
- Stage 4.1 - Undoing Moves.
- Stage 4.2 - Hard Mode.
Stage 4.1 - Undoing Moves
Sometimes in CS Ninja, you make a move which puts you in an unfavourable position. To give users more flexibility, we are introducing an undo command!
Task
In this substage, you will need to:
- Add the
u
command to the Gameplay loop. - Undo the most recent valid move by returning the state of the game to before that action was taken.
- If there are no valid moves to undo, print
"ERROR: No previous turns to undo!\n"
- Otherwise, print the updated board.
- If there are no valid moves to undo, print
Assumptions / Restrictions / Clarifications
- Multiple undos are possible.
- We will only test for the first 1000 valid moves in any given game.
- After undo-ing, you don't need to save those states (aka: for redos or undo tree behaviour).
- Undo-ing at the initial state does nothing.
Examples
Input:
t 2 2 1 2 t 6 2 0 1 t 6 7 3 0 t 2 7 2 3 s 0 2 5 u q
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- t 2 2 1 2 t 6 2 0 1 t 6 7 3 0 t 2 7 2 3 s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ \*| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |_\ /_| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 0 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ \*| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |_\ /_| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 2 5 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ ^_^ \*| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |_\ /_| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Gameplay Phase --- u ERROR: No previous turns to undo! q --- Quitting Game ---
Input:
t 2 2 1 2 t 6 2 0 1 t 6 7 3 0 t 2 7 2 3 s 0 2 5 A p u p D u p q
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- t 2 2 1 2 t 6 2 0 1 t 6 7 3 0 t 2 7 2 3 s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ \*| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |_\ /_| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 0 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ \*| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |_\ /_| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 2 5 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ ^_^ \*| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |_\ /_| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Gameplay Phase --- A +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ \*| + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |_\ /_| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + p You have 0 points! u +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ ^_^ \*| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |_\ /_| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + p You have 0 points! D +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ \*| + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |_\ /_| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + u +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ ^_^ \*| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |_\ /_| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + p You have 0 points! q --- Quitting Game ---
Autotest
Stage 4.2 - Hard Mode
Some players have said that CS Ninja is too simple! So we have come up with a hard mode to challenge even the most skilled players.
Task
To complete this substage:
- Add the
h [row] [col]
command to the Gameplay loop.- This will activate hard mode.
- At
[row] [col]
, spawn a new ninja.- Follow the error handling as per Stage 1.3.
- If the
[row] [col]
is occupied by another ninja, print"ERROR: Invalid tile, [row] [col] is occupied by another ninja!\n"
. - If there are already 4 ninjas on the board, print
"ERROR: Maximum number of ninjas reached!\n"
- Otherwise, print the board.
- Implement Hard Mode.
- Every command is now implemented for all ninjas.
- You only need one ninja to enter the exit to win.
- If any of the ninjas fall off the board, you lose the game.
- Update print_board() function to handle printing of multiple ninjas.
- Update your print inventory logic (Stage 2.2) to handle printing of multiple ninja inventories.
- Print the inventory for each ninja in order of creation.
Assumptions / Restrictions / Clarifications
- You can assume that hard mode will only be activated at most 3 times (i.e. 4 ninjas on the board at one time).
- The ninja with the longest lifetime has priority in movement.
- When executing ninja movement, move one tile at a time in turn, rather than completing their full movement individually. This process continues in order until all movement steps are completed or cannot proceed.
- Ninjas cannot occupy the same space at any given point in time:
- If two or more ninjas collide with each other, in a basic movement, they will just stop their movement.
- If two or more ninjas collide with each other, in a slam movement, they will execute the slam movement until the moment of collision.
Examples
Input:
w 4 4 w 8 7 e 5 8 s 1 5 7 2 4 a h 4 6 u d S p u p s D
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- w 4 4 w 8 7 e 5 8 s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + [X] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 1 5 7 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + * [X] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 2 4 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + * [X] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + --- Gameplay Phase --- a +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + * [ ] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + h 4 6 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + ||| ^_^ + + + + + + + + + + + * [ ] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + u ERROR: No previous turns to undo! d +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + ||| ^_^ + + + + + + + + + + + * [ ] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + S +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + ||| + + + + + + + + + + + [ ] + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + p You have 20 point(s)! u +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + ||| ^_^ + + + + + + + + + + + * [ ] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + p You have 0 point(s)! s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + ||| + + + + + + + + + + + ^_^ [ ] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + D +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ^_^ + + + + + + + + + + + ||| + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ||| + + + + + + + + + + + + + + + + + + + + + + --- Game Over --- Congratulations!
Input:
t 2 2 1 2 t 6 2 0 1 t 6 7 3 0 t 2 7 2 3 s 0 2 5 h 2 5 h 3 5 h 4 5 h 5 5 h 6 5 q
Input and Output:
dcc cs_ninja.c -o cs_ninja ./cs_ninja Welcome to CS Ninja! --- Setup Phase --- t 2 2 1 2 t 6 2 0 1 t 6 7 3 0 t 2 7 2 3 s +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ \*| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |_\ /_| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Adding Stars --- Enter the number of stars: 0 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ \*| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |_\ /_| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Spawning Ninja --- 2 5 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ ^_^ \*| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |_\ /_| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- Gameplay Phase --- h 2 5 ERROR: Invalid tile, 2 5 is occupied by another ninja! h 3 5 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ ^_^ \*| + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |_\ /_| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + h 4 5 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ ^_^ \*| + + + + + + + + + + + ^_^ + + + + + + + + + + + ^_^ + + + + + + + + + + + + + + + + + + + + + + |_\ /_| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + h 5 5 +---+---+---+---+---+---+---+---+---+---+ | N I N J A | +---+---+---+---+---+---+---+---+---+---+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |*/ ^_^ \*| + + + + + + + + + + + ^_^ + + + + + + + + + + + ^_^ + + + + + + + + + + + ^_^ + + + + + + + + + + + |_\ /_| + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + h 6 5 ERROR: Maximum number of ninjas reached! q --- Quitting Game ---
Autotest
Testing & Submission
Are you finished with this stage? If so, you should make sure to do the following:
- Run
1511 style
, and clean up any issues a human may have reading your code. Don't forget -- 20% of your mark in the assignment is based on style! - Autotest for this stage of the assignment by running the
autotest-stage
command as shown below. - Remember -- give early, and give often. Only your last submission counts, but why not be safe and submit right now?
1511 style cs_ninja.c 1511 autotest-stage 04 cs_ninja give cs1511 ass1_cs_ninja cs_ninja.c
Tools
Creating Levels in Separate Files
If you are getting sick of typing in your inputs for a level every single time you run CS Ninja, you might want to store your input in a separate file. This allows you to see the result of the Setup Phase or to play your level straight away.
1. Create a file for your input.
First, let's create a file to store in the input for a level that you have created. This isn't a .c
file, it's just a regular plain text file, and the file extension .in
works nicely for this!
Let's put it in the same directory as your cs_ninja.c
code.
ls cs_ninja.c cs_ninja my_level.in
2. Add your input to the file
Inside of this file, add the input for the level. Don't add in any of the 'wasd' movement commands as those will come from the terminal (from substage 2.1 onwards).
Your file could look a bit like this:
4 8 w 1 5 b 2 3 g 4 2 s
3. Run the code with your file
Next, instead of just running ./cs_ninja
, lets tell the computer to first read from the file we created.
If you have completed substage 2.1 then use the following:
cat my_level.in - | ./cs_ninja
Otherwise, use the following:
cat my_level.in | ./cs_ninja
The dash tells your program that you want to enter more input after what's in the file, allowing you to play the level!
Community Levels
If you want to create your own levels, we encourage you to share them on the Course Forum.
Extension
Extension activities are NOT worth any marks, nor are there any autotests. They are just for fun!
Getting Started
To get started with SplashKit, complete the SplashKit activities.
Sample Code
First, navigate to your SplashKit directory.
cd splashkit
Create a new directory for your project and cd
into it.
mkdir cs_ninja cd cs_ninja
Set up your directory for SplashKit with:
1511 setup-splashkit-directory
Run this cp
command to retrieve the sample code.
cp -n /web/cs1511/25T2/activities/cs_ninja/splashkit_example.c .
This should add the splashkit_example.c
sample code to your current directory.
Check that SplashKit Works
Let's check that SplashKit works by running a test file. It should display a white square with a grid inside.
skm clang++ splashkit_example.c -o splashkit_example ./splashkit_example
Have a look inside of splashkit_example.c
and note that:
- At the very top, the the SplashKit library
"splashkit.h"
is included. If you see an error here, check SplashKit #1 - Getting Started for a solution to set up your VS Code project. - In the
main()
function:open_window("SplashKit Example", 600, 400)
creates a 600×400 window for displaying graphics.- The
while (!window_close_requested(w))
loop keeps running until the user closes the window. Within this loop:process_events()
handles input or window-related actions (like closing the window).refresh_screen()
updates the window so any graphical changes (like drawing a rectangle) are displayed to the user.
Running Your SplashKit Code
When creating your SplashKit program, give it a distinctive name like splashkit_cs_ninja.c
.
To compile and run your program, use:
skm clang++ splashkit_cs_ninja.c -o splashkit_cs_ninja ./splashkit_cs_ninja
Writing Your SplashKit Program
Now that you've seen how the sample code works, it’s time to create your own SplashKit program.
If you're not sure where to begin, start by researching the SplashKit Library. The goal at first is not to understand and memorise the entire library. Rather, it's better to skim through the pages to build a broad understanding of the capabilities that SplashKit can bring to your creations.
The Graphics page is a good place to start, and the following sections will be useful:
- Windows for opening, closing, and controlling the size of windows.
- Color for using different colours.
- Graphics for drawing shapes, images, and text.
- Geometry for handling shapes such as rectangles, circles, lines, and points.
- Input for capturing and handling user input such as keyboard and mouse events.
Sample Assets
If you wish to use assets similar to the demo project, copy them to your current directory with:
cp -rn /web/cs1511/25T2/activities/cs_ninja/splashkit_assets .
SplashKit Gallery
Have you built something fun or interesting using SplashKit? Show it off and inspire your classmates!
Share any screenshots or short videos of your running program in the SplashKit Gallery on the Course Forum. Feel free to add a brief description or reflect on how you made it, so we can all learn from your mistakes journey 😅.
Assessment
Assignment Conditions
Joint work is not permitted on this assignment.
This is an individual assignment.
The work you submit must be entirely your own work. Submission of any work even partly written by any other person is not permitted.
Except, you may use small amounts (< 10 lines) of general purpose code (not specific to the assignment) obtained from a site such as Stack Overflow or other publicly available resources. You should attribute clearly the source of this code in an accompanying comment.
Assignment submissions will be examined, both automatically and manually for work written by others.
Do not request help from anyone other than the teaching staff of COMP1511, e.g. in the course forum & help sessions.
Do not post your assignment code to the course forum - the teaching staff can view assignment code you have recently autotested or submitted with give.
Rationale: this assignment is designed to develop the individual skills needed to produce an entire working program. Using code written by or taken from other people will stop you learning these skills. Other CSE courses focus on the skill needed for work in a team.
The use of code-synthesis tools, such as GitHub Copilot, is not permitted on this assignment.
The use of Generative AI to generate code solutions is not permitted on this assignment.
Rationale: this assignment is intended to develop your understanding of basic concepts. Using synthesis tools will stop you learning these fundamental concepts.
Sharing, publishing, distributing your assignment work is not permitted.
Do not provide or show your assignment work to any other person other than the teaching staff of COMP1511. For example, do not message your work to friends.
Do not publish your assignment code via the internet. For example, do not place your assignment in a public GitHub repository.
Rationale: by publishing or sharing your work you are facilitating other students using your work which is not permitted. If they submit your work, you may become involved in an academic integrity investigation.
Sharing, publishing, distributing your assignment work after the completion of COMP1511 is not permitted.
For example, do not place your assignment in a public GitHub repository after COMP1511 is over.
Rationale: COMP1511 sometimes reuses assignment themes using similar concepts and content. Students in future terms find your code and use it which is not permitted and you may become involved in an academic integrity investigation.
Violation of the above conditions may result in an academic integrity investigation with possible penalties, up to and including a mark of 0 in COMP1511 and exclusion from UNSW.
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.
For more information, read the UNSW Student Code, or contact the course account. 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. |
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 'cs_ninja.c'.
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_cs_ninja cs_ninja.c
Assessment Scheme
This assignment will contribute 20% to your final mark.
80% of the marks for this assignment will be based on the performance
of the code you write in cs_ninja.c
20% of the marks for this assignment will come from manual marking of the readability of the C you have written. The manual marking will involve checking your code for clarity, and readability, which includes the use of functions and efficient use of loops and if statements.
Marks for your performance will be allocated roughly according to the below scheme.
100% for Performance | Completely Working Implementation, which exactly follows the spec (Stage 1, 2, 3 and 4). |
85% for Performance | Completely working implementation of Stage 1, 2 and 3. |
65% for Performance | Completely working implementation of Stage 1 and Stage 2. |
35% for Performance | Completely working implementation of Stage 1. |
The Challenge stage of the assignment is NOT worth any marks, but is something fun for you to work on getting to know a new library and building something more visual!
Style Marking Rubric
0 | 1 | 2 | 3 | 4 | |
Formatting (/5) | |||||
Indentation (/2) - Should use a consistent indentation scheme. | Multiple instances throughout code of inconsistent/bad indentation | Code is mostly correctly indented | Code is consistently indented throughout the program | ||
Whitespace (/1) - Should use consistent whitespace (for example, 3 + 3 not 3+ 3) | Many whitespace errors | No whitespace errors | |||
Vertical Whitespace (/1) - Should use consistent whitespace (for example, vertical whitespace between sections of code) | Code has no consideration for use of vertical whitespace | Code consistently uses reasonable vertical whitespace | |||
Line Length (/1) - Lines should be max. 80 characters long | Many lines over 80 characters | No lines over 80 characters | |||
Documentation (/5) | |||||
Comments (incl. header comment) (/3) - Comments have been used throughout the code above code sections and functions to explain their purpose. A header comment (with name, zID and a program description) has been included | No comments provided throughout code | Few comments provided throughout code | Comments are provided as needed, but some details or explanations may be missing causing the code to be difficult to follow | Comments have been used throughout the code above code sections and functions to explain their purpose. A header comment (with name, zID and a program description) has been included | |
Function/variable/constant naming (/2) - Functions/variables/constants names all follow naming conventions in style guide and help in understanding the code | Functions/variables/constants names do not follow naming conventions in style guide and help in understanding the code | Functions/variables/constants names somewhat follow naming conventions in style guide and help in understanding the code | Functions/variables/constants names all follow naming conventions in style guide and help in understanding the code | ||
Organisation (/5) | |||||
Function Usage (/4) - Code has been decomposed into appropriate functions separating functionalities | No functions are present, code is one main function | Some code has been moved to functions | Some code has been moved to sensible/thought out functions, and/or many functions exceed 50 lines (incl. main function) | Most code has been moved to sensible/thought out functions, and/or some functions exceed 50 lines (incl. main function) | All code has been meaningfully decomposed into functions of a maximum of 50 lines (incl. The main function) |
Function Prototypes (/1) - Function Prototypes have been used to declare functions above main | Functions are used but have not been prototyped | All functions have a prototype above the main function or no functions are used | |||
Elegance (/5) | |||||
Overdeep nesting (/2) - You should not have too many levels of nesting in your code (nesting which is 5 or more levels deep) | Many instances of overdeep nesting | <= 3 instances of overdeep nesting | No instances of overdeep nesting | ||
Code Repetition (/2) - Potential repetition of code has been dealt with via the use of functions or loops | Many instances of repeated code sections | <= 3 instances of repeated code sections | Potential repetition of code has been dealt with via the use of functions or loops | ||
Constant Usage (/1) - Any magic numbers are #defined | None of the constants used throughout program are #defined | All constants used are #defined and are used consistently in the code | |||
Illegal elements | |||||
Illegal elements - Presence of any illegal elements indicated in the style guide | CAP MARK AT 16/20 |
Allowed C Features
In this assignment, there are no restrictions on C Features, except for those in the style guide. 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. Features that the Style Guide identifies as illegal will result in a penalty during marking. You can find the style marking rubric above.
Due Date
This assignment is due 14 July 2025 17:00:00. For each day after that time, the maximum mark it can achieve will be reduced by 5% (off the ceiling).- For instance, at 1 day past the due date, the maximum mark you can get is 95%.
- For instance, at 3 days past the due date, the maximum mark you can get is 85%.
- For instance, at 5 days past the due date, the maximum mark you can get is 75%.
Change Log
-
Version 1.0
(2025-06-23 13:00) -
- Assignment released