Assignment 1 - CS Submarine
Overview
CS Submarine is a game where the player enters commands to pilot a Submarine around a grid of ocean. Somewhere below are sunken Treasures worth diving for, and the way out is locked until the last of them is gone. The deeper you go the less you can see, the faster your air runs out, and the more things down there want to sink you.
The aim of the game is to clear the ocean of Treasure and escape through an Exit before your oxygen runs out.
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_submarine
You should now have a file named cs_submarine.c in your ass1 directory.
- Check that everything works by running the autotest:
1511 autotest cs_submarine
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 ocean is initialised.
- The Submarine is spawned.
- Entities (Treasure, Air Pockets, Mines, Exits, Seaweed, Anglerfish, Jellyfish, Currents and Seeking Mines) are added to the board.
Gameplay Phase
When the Setup Phase is complete, the Gameplay Phase begins. In this phase, the Submarine:
- Moves around the ocean, wrapping around its left and right edges.
- Collects Treasure and refills its oxygen at Air Pockets.
- Fires torpedoes at whatever is in its way.
- Is hunted by Jellyfish, Anglerfish, Mines and Seeking Mines.
- Escapes through an Exit once the ocean is clear of Treasure, or runs out of air trying.
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_submarine. 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_submarine x 0 0 t 5 8 o 5 2 m 5 7 s 3 4 h 3 e 5 5 p f d r d d d p q
These inputs will:
- Add a locked Exit at
[0][0], Treasure at[5][8], an Air Pocket at[5][2], a Mine at[5][7], and a run of Seaweed across row3. - End the Setup Phase and spawn the Submarine at board position
[5][5]. - Start the game and print the Submarine's information.
- Fire a torpedo east, which detonates the Mine and clears the way.
- Swim east to collect the Treasure, unlocking the Exit.
- Quit the game.
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_submarine reference solution, then open the provided cs_submarine.c and follow along with this introduction.
The main() Function
A sample main() function has been provided to get you started.
int main(void) {
print_welcome();
struct tile board[ROWS][COLS];
initialise_board(board);
print_board(board, NO_SUBMARINE, NO_SUBMARINE);
return 0;
}
Printing a Welcome Message
The first statement calls a function which prints a welcome message followed by a blank line:
print_welcome();
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;
};
Each struct tile currently contains a single field, an enum entity. This allows each element of the board array to store one feature of the ocean, for example, a Treasure, a Mine, a patch of Seaweed, and so on. You are welcome to modify the provided data structures and encouraged to create your own!
enum entity {
OCEAN,
SEAWEED,
TREASURE,
EXIT_LOCKED,
EXIT_UNLOCKED,
AIR_POCKET,
JELLYFISH,
ANGLERFISH,
MINE,
HIDDEN,
SEEKING_MINE,
CURRENT_UP,
CURRENT_DOWN,
CURRENT_LEFT,
CURRENT_RIGHT,
TORPEDO
};
Each entity corresponds to a feature and a symbol that appears when the board is printed to the terminal:
| Entity | Symbol |
|---|---|
OCEAN |
|
TREASURE |
[$] |
AIR_POCKET |
oOo |
MINE |
(*) |
EXIT_LOCKED |
[X] |
SEAWEED |
)|( |
EXIT_UNLOCKED |
[^] |
ANGLERFISH |
><> |
JELLYFISH |
(~) |
TORPEDO |
-*- |
HIDDEN |
### |
CURRENT_UP |
^^^ |
CURRENT_DOWN |
vvv |
CURRENT_LEFT |
<<< |
CURRENT_RIGHT |
>>> |
SEEKING_MINE |
{*} |
The Submarine itself prints as [o>. It is not an enum entity, and it is never stored in the board array. You will need to keep track of where it is yourself, and it is drawn on top of whatever tile it happens to be on.
Using the board Array
We can use row and column indices to access board elements.
For example:
board[2][3]accesses thestruct tileat row 2 and column 3.board[2][3].entityaccesses theenum entityof thisstruct tile.
Similarly:
board[8][1]accesses thestruct tileat row 8 and column 1.board[8][1].entityaccesses theenum entityof thisstruct tile.
Row 0 is the surface of the ocean, and row ROWS - 1 is the tile just above the seafloor.
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 OCEAN:
initialise_board(board);
Printing the Game
Before exiting, main() prints the board in the terminal:
+===+===+===+===+===+===+===+===+===+===+ |*** >> C S S U B M A R I N E << ***| +===+===+===+===+===+===+===+===+===+===+ +---+---+---+---+---+---+---+---+---+---+ | | | | | | | | | | | +---+---+---+---+---+---+---+---+---+---+ | | | | | | | | | | | +---+---+---+---+---+---+---+---+---+---+ | | | | | | | | | | | +---+---+---+---+---+---+---+---+---+---+ | | | | | | | | | | | +---+---+---+---+---+---+---+---+---+---+ | | | | | | | | | | | +---+---+---+---+---+---+---+---+---+---+ | | | | | | | | | | | +---+---+---+---+---+---+---+---+---+---+ | | | | | | | | | | | +---+---+---+---+---+---+---+---+---+---+ | | | | | | | | | | | +---+---+---+---+---+---+---+---+---+---+ | | | | | | | | | | | +---+---+---+---+---+---+---+---+---+---+ | | | | | | | | | | | +===+===+===+===+===+===+===+===+===+===+
It does this with the provided print_board() function.
print_board(board, NO_SUBMARINE, NO_SUBMARINE);
The print_board() function takes the following arguments:
- The
boardarray. - The row position of the Submarine. Since the Submarine has not yet been placed on the board, we use the
#define'd constantNO_SUBMARINE. - The column position of the Submarine. Since the Submarine has not yet been placed on the board, we use the
#define'd constantNO_SUBMARINE.
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 Submarine at row 2, column 9.print_board(board, 0, 5)displays the board with the Submarine at 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
The remaining provided functions fall into two groups.
You will need to call these yourself:
print_submarine_stats()prints the Submarine's oxygen, treasure, turns taken and torpedoes remaining. You will first need it in Stage 2.3.print_map_statistics()prints a count of what is on the board. It takes seven separate counts, so working those counts out is your job. You will first need it in Stage 2.4.print_win_message()is called when the game is won. You will first need it in Stage 2.5.print_oxygen_loss_message()is called when the Submarine runs out of air. You will first need it in Stage 2.5.print_loss_message()is called when the Submarine is sunk, and takes theenum entitythat sank it. You will first need it in Stage 2.5.
You will not need to call these:
print_board_line(),print_board_header()andprint_tile_spacer()are helpers called byprint_board().get_name_from_type()converts anenum entityinto a readable string, and is called byprint_loss_message().
FAQ
Q: Can I edit the provided code?
Yes! Feel free to modify/replace/discard any of the provided:
#defineconstants,- enums,
- structs, and
- functions.
For example: you may wish to add fields to the provided struct tile definition. Later stages of this assignment assume that you have.
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 - Add Simple Entities (Treasure, Air Pockets, Mines & Exits).
- Stage 1.2 - Validate Entity Placement.
- Stage 1.3 - End Setup and Spawn the Submarine.
- Stage 1.4 - Validate the Submarine's Spawn.
- Stage 1.5 - Add Seaweed.
Stage 2: Gameplay Phase (Submarine Turn)
- Stage 2.1 - Submarine Movement.
- Stage 2.2 - Validate Submarine Movement.
- Stage 2.3 - Collect Treasure & Print Submarine Information.
- Stage 2.4 - Print Map Statistics.
- Stage 2.5 - Winning & Losing.
Stage 3: Gameplay Phase (The Ocean Fights Back)
- Stage 3.1 - Anglerfish.
- Stage 3.2 - The Deep Sea.
- Stage 3.3 - Jellyfish.
- Stage 3.4 - Undo.
- Stage 3.5 - Ocean Currents.
Stage 4: Gameplay Phase (Extra Mechanics)
- Stage 4.1 - Torpedoes.
- Stage 4.2 - Seeking Mines.
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 build the ocean the game is played in. This milestone has been divided into five substages:
- Stage 1.1 - Add Simple Entities.
- Stage 1.2 - Validate Entity Placement.
- Stage 1.3 - End Setup and Spawn the Submarine.
- Stage 1.4 - Validate the Submarine's Spawn.
- Stage 1.5 - Add Seaweed.
Stage 1.1 - Add Simple Entities
Task
An empty ocean is not much of a game. This substage will allow you to fill the ocean, reading commands from the user and placing entities onto the board.
Commands
t [row] [col] o [row] [col] m [row] [col] x [row] [col]
Description
In this substage, you will modify the starter code to:
- Print the Setup Phase heading,
"============== Setup Phase ==============\n". - Print
"Enter setup commands:\n". - Read setup commands in a loop until
[Ctrl-D]is pressed, and place entities on the board. Each command is a character followed by a row and a column:
| Command | Entity | Art |
|---|---|---|
t [row] [col] | TREASURE | [$] |
o [row] [col] | AIR_POCKET | oOo |
m [row] [col] | MINE | (*) |
x [row] [col] | EXIT_LOCKED | [X] |
- Print the board once the input ends, using the provided
print_board()function.
The Submarine is not on the board yet. Pass NO_SUBMARINE into print_board() for both its row and its column, exactly as the starter's main() already does.
Assumptions / Restrictions / Clarifications
- Every command will be one of the four above. You do not need to handle anything else yet.
[row]and[col]are always integers, and in this substage you can assume they will be on the board. Checking invalid placements is in Stage 1.2.- Placing an entity on a tile that already has one is also Stage 1.2.
- Only one board is printed, at the very end. Nothing is printed as each command is read.
Examples
Input:
t 5 5 [CTRL+D]
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
t 5 5
[CTRL+D]
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[$]| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+===+===+===+===+===+===+===+===+===+===+
Input:
t 5 5 o 2 7 m 8 1 x 0 0 [CTRL+D]
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
t 5 5
o 2 7
m 8 1
x 0 0
[CTRL+D]
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | |oOo| | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[$]| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| |(*)| | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+===+===+===+===+===+===+===+===+===+===+
Autotest
Stage 1.2 - Validate Entity Placement
Task
So far any row and column is accepted, including ones that are not on the board. This substage will validate input to determine whether entities should be placed or not.
Description
In this substage, you will:
- Reject a placement that is not on the board. Print
"Invalid location: position is not on the board!\n"and carry on reading commands. - Reject a placement onto a tile that already holds an entity. Print
"Invalid location: tile is occupied!\n"and carry on reading commands.
Assumptions / Restrictions / Clarifications
- A row is on the board when it is between
0andROWS - 1, and a column when it is between0andCOLS - 1. - Only one message is printed per rejected command.
Examples
Input:
t 10 5 o 3 -1 m 99 99 x 0 0 [CTRL+D]
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
t 10 5
Invalid location: position is not on the board!
o 3 -1
Invalid location: position is not on the board!
m 99 99
Invalid location: position is not on the board!
x 0 0
[CTRL+D]
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+===+===+===+===+===+===+===+===+===+===+
Input:
x 0 0 t 5 5 m 5 5 o 5 5 t 4 4 [CTRL+D]
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 0 0
t 5 5
m 5 5
Invalid location: tile is occupied!
o 5 5
Invalid location: tile is occupied!
t 4 4
[CTRL+D]
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | |[$]| | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[$]| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+===+===+===+===+===+===+===+===+===+===+
Autotest
Stage 1.3 - End Setup and Spawn the Submarine
Task
The Setup Phase currently ends only when [Ctrl-D] is pressed. This substage adds a command to end it deliberately, and place the Submarine in the ocean.
Commands
e
Description
In this substage, you will:
- Handle the new Setup Phase command
e, which ends the Setup Phase. - Refuse to end setup until at least one
EXIT_LOCKEDhas been placed. Ifeis given and no Exit is on the board, print"Cannot end setup until an EXIT_LOCKED has been placed\n"and carry on reading commands. - Once setup ends with
e, spawn the Submarine:- Print
"Enter the Submarine's starting position: ". - Scan a row and a column.
- Place the Submarine there.
- Print
- Print the board with the Submarine on it, drawn as
[o>. - Print
"============= Gameplay Phase ============\n", announcing that setup is over and the game is about to begin.
Assumptions / Restrictions / Clarifications
- The Submarine is not an entity and is never stored in the
boardarray. Keep track of its row and column and pass them toprint_board(). - The starting position given in this substage will always be valid. Rejecting a bad position is Stage 1.4.
- There are two ways for the Setup Phase to end, and they do different things.
eends setup and goes on to spawn the Submarine.[Ctrl-D]prints the board and ends the program, with no starting position prompt and no Gameplay Phase heading. [Ctrl-D]always ends the program, whether or not an Exit has been placed.
Examples
Input:
t 5 5 x 0 0 e 7 7 [CTRL+D]
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
t 5 5
x 0 0
e
Enter the Submarine's starting position: 7 7
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[$]| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | |[o>| | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
[CTRL+D]
Input:
t 5 5 e o 2 2 e x 0 0 e 7 7 [CTRL+D]
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
t 5 5
e
Cannot end setup until an EXIT_LOCKED has been placed
o 2 2
e
Cannot end setup until an EXIT_LOCKED has been placed
x 0 0
e
Enter the Submarine's starting position: 7 7
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | |oOo| | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[$]| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | |[o>| | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
[CTRL+D]
Autotest
Stage 1.4 - Validate the Submarine's Spawn
Task
The Submarine currently starts wherever it is told to, including on top of a Mine or off the edge of the ocean. This substage will validate the Submarine's starting position.
Description
In this substage, you will:
- Reject a starting position that is not on the board. A row is on the board when it is between
0andROWS - 1, and a column when it is between0andCOLS - 1. - Reject a starting position on a tile that is not an
OCEANentity. - For either, print
"The Submarine cannot start here!\n"and prompt again with"Enter the Submarine's starting position: ". - Keep prompting until a valid position is given.
- Print the board.
- Print
"============= Gameplay Phase ============\n", announcing that setup is over and the game is about to begin.
Examples
Input:
x 0 0 e 10 10 -1 4 5 5 [CTRL+D]
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 0 0
e
Enter the Submarine's starting position: 10 10
The Submarine cannot start here!
Enter the Submarine's starting position: -1 4
The Submarine cannot start here!
Enter the Submarine's starting position: 5 5
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
[CTRL+D]
Input:
x 0 0 m 4 4 t 3 3 e 4 4 3 3 7 7 [CTRL+D]
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 0 0
m 4 4
t 3 3
e
Enter the Submarine's starting position: 4 4
The Submarine cannot start here!
Enter the Submarine's starting position: 3 3
The Submarine cannot start here!
Enter the Submarine's starting position: 7 7
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | |[$]| | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | |(*)| | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | |[o>| | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
[CTRL+D]
Autotest
Stage 1.5 - Add Seaweed
Task
Every entity so far occupies a single tile. Seaweed grows in runs, and needs a command that places several tiles at once.
Commands
s [row] [col] [direction] [length]
Description
In this substage, you will:
- Handle the new Setup Phase command
s [row] [col] [direction] [length], which places a run ofSEAWEED, printed as)|(. - Grow the run from
[row][col]for[length]tiles. The[direction]can be:hgrows right, along the row.vgrows up, towards the surface.
- If any tile is off the board, print
"Invalid location: position is not on the board!\n". If any tile is occupied, print"Invalid location: tile is occupied!\n". If both errors occur, print"Invalid location: position is not on the board!\n". - The
SEAWEEDis only placed when every tile on the path is valid.
Assumptions / Restrictions / Clarifications
[direction]is alwayshorv. No other direction will be tested.[length]is always at least1.- A run of length
1is a single tile of Seaweed, and behaves like any other placement. - Seaweed does not wrap around the board.
Examples
Input:
x 0 0 s 5 3 h 4 e 1 1 [CTRL+D]
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 0 0
s 5 3 h 4
e
Enter the Submarine's starting position: 1 1
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| |[o>| | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | |)|(|)|(|)|(|)|(| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
[CTRL+D]
Input:
x 0 0 s 8 6 v 3 e 1 1 [CTRL+D]
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 0 0
s 8 6 v 3
e
Enter the Submarine's starting position: 1 1
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| |[o>| | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | |)|(| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | |)|(| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | |)|(| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
[CTRL+D]
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-stagecommand 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_submarine.c 1511 autotest-stage 01 cs_submarine give cs1511 ass1_cs_submarine cs_submarine.c
Stage 2
In Stage 2, you will begin implementing the Gameplay Phase of CS Submarine. This milestone has been divided into five substages:
- Stage 2.1 - Submarine Movement.
- Stage 2.2 - Validate Submarine Movement.
- Stage 2.3 - Collect Treasure & Print Submarine Information.
- Stage 2.4 - Print Map Statistics.
- Stage 2.5 - Winning & Losing.
Stage 2.1 - Submarine Movement
Task
The first step of the Gameplay Phase is to get the Submarine moving. By the end of this substage, your program will allow the user to pilot the Submarine around the ocean.
Commands
qquits the game.wmoves the Submarine up.amoves the Submarine left.smoves the Submarine down.dmoves the Submarine right.rcounts as a move without moving the Submarine's position.
Description
In this substage, you will need to:
-
Start the Gameplay Phase:
"============= Gameplay Phase ============\n"is already printed by Stage 1.3, as the last thing that happens once the Submarine has spawned. Everything in this substage runs after it.
-
Implement a Gameplay Loop to repeatedly read in and handle user commands:
- The first command to add to the Gameplay Loop is
qto quit. - When the
qcommand is entered, the program should immediately:- Print
"============= Quitting Game =============\n". - Exit without any other output.
- Print
- Only
qprints that message. If[Ctrl-D]is pressed nothing extra should be printed.
- The first command to add to the Gameplay Loop is
-
Move the Submarine:
- The next Gameplay Loop commands move the Submarine by one grid cell at a time:
wmoves the Submarine up, towards the surface (towards row 0).amoves the Submarine left.smoves the Submarine down, towards the ocean floor (towards rowROWS - 1).dmoves the Submarine right.
- The Gameplay Loop should also handle a rest command:
rcounts as a turn without changing the Submarine's position on the board.
- The next Gameplay Loop commands move the Submarine by one grid cell at a time:
-
Wrap around the ocean:
- The ocean wraps around horizontally. Moving left from column
0places the Submarine at columnCOLS - 1, and moving right from columnCOLS - 1places it at column0. - The ocean does not wrap vertically. Moving up from the surface or down from the ocean floor is handled in Stage 2.2.
- The ocean wraps around horizontally. Moving left from column
-
Finish the turn:
- Display the board with the provided
print_board()function. This completes the turn. - After each command is handled, the program should continue reading and handling the next command until
qis entered.
- Display the board with the provided
Assumptions / Restrictions / Clarifications
- The
scommand moves the Submarine down. This is not related to thesSeaweed command from Stage 1.5 as the Setup Phase has already ended by the time the Gameplay Loop starts.
When your code is tested in this substage:
- No movement command will move the Submarine onto a tile that contains an entity.
- No movement command will move the Submarine up from the surface or down from the ocean floor.
Nothing from Stage 2.5 will be triggered by the tests for Stages 2.1 to 2.4. Until you reach that substage you may rely on all of the following:
- At least one
TREASUREwill always remain on the board, so the Exits never unlock and the Submarine can never reach an unlocked one. - The Submarine will never be left to run out of oxygen.
- The Submarine will never be moved onto a
MINE.
For this substage and all future substages:
- The Gameplay Loop runs until
qis entered, or until[Ctrl-D]is pressed. Onlyqprints the quitting message.
Examples
Input:
x 0 0 t 9 9 e 5 5 q
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 0 0
t 9 9
e
Enter the Submarine's starting position: 5 5
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
q
============= Quitting Game =============
Input:
x 0 0 t 9 9 e 5 5 s d w a q
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 0 0
t 9 9
e
Enter the Submarine's starting position: 5 5
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
s
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
d
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | |[o>| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
w
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | |[o>| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
a
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
q
============= Quitting Game =============
Input:
x 0 0 t 9 9 e 5 5 r r r q
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 0 0
t 9 9
e
Enter the Submarine's starting position: 5 5
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
q
============= Quitting Game =============
Autotest
Stage 2.2 - Validate Submarine Movement
Task
In the previous substage, your program allowed the user to pilot the Submarine. But what should happen if the Submarine tries to swim into a thick patch of Seaweed, or straight up out of the ocean?
Description
A destination is invalid if any of the following are true:
- The tile contains a
SEAWEEDentity. - The tile contains an
EXIT_LOCKEDentity. - The move is
wand the Submarine is already at the surface, row0. - The move is
sand the Submarine is already at the ocean floor, rowROWS - 1.
If the Submarine attempts to move to an invalid destination:
- Print
"The Submarine cannot move there!\n". - The Submarine should not move.
- The turn does not happen. No oxygen is used, and the board is not printed.
- Continue the Gameplay Loop, reading the user's next command.
Every other tile is a valid destination. The Submarine may swim onto OCEAN, TREASURE, AIR_POCKET, MINE and EXIT_UNLOCKED tiles.
Assumptions / Restrictions / Clarifications
- Remember that the ocean wraps horizontally. A move that wraps can still be rejected: if the Submarine is at column
0and columnCOLS - 1of that row holds Seaweed, thenais an invalid move. - Swimming onto a
TREASUREor anAIR_POCKETis allowed, but you do not need to collect anything yet. Collecting is handled in Stage 2.3. - Swimming onto a
MINEis allowed, and nothing happens to the Submarine yet. Losing the game is handled in Stage 2.5. - No
EXIT_UNLOCKEDtile can exist yet, because unlocking the exits is handled in Stage 2.5.
Examples
Input:
x 0 0 t 9 9 s 5 6 h 1 e 5 5 d a q
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 0 0
t 9 9
s 5 6 h 1
e
Enter the Submarine's starting position: 5 5
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>|)|(| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
d
The Submarine cannot move there!
a
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | |[o>| |)|(| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
q
============= Quitting Game =============
Input:
x 5 6 t 9 9 e 5 5 d s q
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 5 6
t 9 9
e
Enter the Submarine's starting position: 5 5
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>|[X]| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
d
The Submarine cannot move there!
s
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | |[X]| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
q
============= Quitting Game =============
Input:
x 9 0 t 9 9 e 0 5 w s q
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 9 0
t 9 9
e
Enter the Submarine's starting position: 0 5
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
w
The Submarine cannot move there!
s
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
q
============= Quitting Game =============
Autotest
Stage 2.3 - Collect Treasure & Print Submarine Information
Task
The Submarine can now swim safely around the ocean. It is time to start picking things up, and give the player a way to check their instruments.
Commands
p
Description
In this substage, you will extend your Gameplay Loop to:
- Collect whatever the Submarine lands on. After the Submarine has moved, look at the tile it ended its turn on:
- If the tile contains a
TREASURE, collect it. Add1to the amount of treasure collected, and set the tile's entity toOCEAN. - If the tile contains an
AIR_POCKET, use it. Add20to the Submarine's oxygen, and set the tile's entity toOCEAN.
- If the tile contains a
- Track oxygen:
- The Submarine starts the Gameplay Phase with
100oxygen. - Every turn uses
5oxygen. A rest is a turn, so resting also uses5. - A rejected move from Stage 2.2 is not a turn, so it uses no oxygen.
- Oxygen can never go above
100. If an Air Pocket would take it higher, set it to100instead.
- The Submarine starts the Gameplay Phase with
- Handle the new command
p:- Print the Submarine's information using the provided
print_submarine_stats()function. This shows:- The Submarine's remaining oxygen.
- The amount of treasure collected.
- The number of turns the Submarine has taken.
- The number of torpedoes remaining.
- Print the Submarine's information using the provided
Assumptions / Restrictions / Clarifications
- Oxygen is used as soon as the Submarine has moved, before anything on the tile is collected. Swimming onto an Air Pocket with
95oxygen therefore spends5first and then refills, leaving the Submarine on a full100. - The Submarine carries
4torpedoes for the whole game, but has no way to fire one until Stage 4.1. The torpedo figure is therefore always4in this stage. - Running out of oxygen does not end the game yet. That is handled in Stage 2.5.
- This is the first substage that can take a Treasure off the board, but the tests will never let you take the last one. At least one Treasure always remains, so the Exits stay locked until Stage 2.5.
Examples
Input:
x 0 0 t 5 6 t 9 9 e 5 5 p d d p q
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 0 0
t 5 6
t 9 9
e
Enter the Submarine's starting position: 5 5
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>|[$]| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
p
+=======================================+
| >> SUBMARINE STATUS << |
+=======================================+
| Oxygen : 100 |
| Treasure : 0 |
| Moves : 0 |
| Torpedoes : 4 |
+=======================================+
d
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | |[o>| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
d
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | |[o>| | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
p
+=======================================+
| >> SUBMARINE STATUS << |
+=======================================+
| Oxygen : 90 |
| Treasure : 1 |
| Moves : 2 |
| Torpedoes : 4 |
+=======================================+
q
============= Quitting Game =============
Input:
x 0 0 t 9 9 o 5 6 e 5 5 r r p d d p q
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 0 0
t 9 9
o 5 6
e
Enter the Submarine's starting position: 5 5
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>|oOo| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>|oOo| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>|oOo| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
p
+=======================================+
| >> SUBMARINE STATUS << |
+=======================================+
| Oxygen : 90 |
| Treasure : 0 |
| Moves : 2 |
| Torpedoes : 4 |
+=======================================+
d
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | |[o>| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
d
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | |[o>| | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
p
+=======================================+
| >> SUBMARINE STATUS << |
+=======================================+
| Oxygen : 95 |
| Treasure : 0 |
| Moves : 4 |
| Torpedoes : 4 |
+=======================================+
q
============= Quitting Game =============
Autotest
Stage 2.4 - Print Map Statistics
Task
The player can now see the state of their Submarine. This substage adds a way to see the state of the ocean around it.
Commands
m
Description
In this substage, you will extend your Gameplay Loop to handle one new command:
- Given the command
m, print the map statistics using the providedprint_map_statistics()function.
print_map_statistics() takes seven inputs, in this order:
- The number of
TREASUREtiles remaining on the board. - The number of
AIR_POCKETtiles remaining on the board. - The number of
SEAWEEDtiles remaining on the board. - The number of
MINEtiles remaining on the board. - The number of
JELLYFISHtiles remaining on the board. - The number of
ANGLERFISHtiles remaining on the board. - The number of Exit tiles on the board, both
EXIT_LOCKEDandEXIT_UNLOCKED.
Each count should be of what is currently on the board. For example, collecting a TREASURE reduces the TREASURE count by one.
Assumptions / Restrictions / Clarifications
JELLYFISHandANGLERFISHcannot be placed on the board yet, so both of those counts will always be0in this stage. They are added in Stage 3.
Examples
Input:
x 0 0 t 1 1 t 2 2 o 3 3 m 4 4 s 7 0 h 3 e 5 5 m q
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 0 0
t 1 1
t 2 2
o 3 3
m 4 4
s 7 0 h 3
e
Enter the Submarine's starting position: 5 5
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| |[$]| | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | |[$]| | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | |oOo| | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | |(*)| | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|)|(|)|(|)|(| | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
m
+=======================================+
| >> MAP STATISTICS << |
+=======================================+
| Treasure : 2 |
| Air Pockets : 1 |
| Seaweed : 3 |
+---------------------------------------+
| Mines : 1 |
| Jellyfish : 0 |
| Anglerfish : 0 |
+---------------------------------------+
| Exits : 1 |
+=======================================+
q
============= Quitting Game =============
Input:
x 0 0 t 5 6 t 9 9 o 5 7 e 5 5 m d m d m q
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 0 0
t 5 6
t 9 9
o 5 7
e
Enter the Submarine's starting position: 5 5
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>|[$]|oOo| | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
m
+=======================================+
| >> MAP STATISTICS << |
+=======================================+
| Treasure : 2 |
| Air Pockets : 1 |
| Seaweed : 0 |
+---------------------------------------+
| Mines : 0 |
| Jellyfish : 0 |
| Anglerfish : 0 |
+---------------------------------------+
| Exits : 1 |
+=======================================+
d
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | |[o>|oOo| | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
m
+=======================================+
| >> MAP STATISTICS << |
+=======================================+
| Treasure : 1 |
| Air Pockets : 1 |
| Seaweed : 0 |
+---------------------------------------+
| Mines : 0 |
| Jellyfish : 0 |
| Anglerfish : 0 |
+---------------------------------------+
| Exits : 1 |
+=======================================+
d
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | |[o>| | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
m
+=======================================+
| >> MAP STATISTICS << |
+=======================================+
| Treasure : 1 |
| Air Pockets : 0 |
| Seaweed : 0 |
+---------------------------------------+
| Mines : 0 |
| Jellyfish : 0 |
| Anglerfish : 0 |
+---------------------------------------+
| Exits : 1 |
+=======================================+
q
============= Quitting Game =============
Autotest
Stage 2.5 - Winning & Losing
Task
In this substage, you will allow the player to win or lose the game!
The aim of CS Submarine is to collect all the Treasure and escape. The Exits placed during the Setup Phase start locked. Once no Treasure remains on the board, they unlock, and swimming into one wins the game.
Description
In this substage, you will need to:
- Unlock the Exits. Whenever a Treasure is collected, check the board: if no
TREASUREtiles remain anywhere, change everyEXIT_LOCKEDtile toEXIT_UNLOCKED. Later stages add other ways for Treasure to leave the board, and the same check always applies. - Win the game. If the Submarine ends its move on an
EXIT_UNLOCKEDtile:- Print the board with
print_board(). - Call the provided
print_win_message()function. - Print the Submarine's information with
print_submarine_stats(). - Exit the program.
- Print the board with
- Lose by running out of oxygen. If the Submarine's oxygen reaches
0:- Print the board with
print_board(). - Call the provided
print_oxygen_loss_message()function. - Print the Submarine's information with
print_submarine_stats(). - Exit the program.
- Print the board with
- Lose to a Mine. If the Submarine ends its turn on a
MINEtile:- Print the board with
print_board(). - Call the provided
print_loss_message()function, passing itMINE. - Print the Submarine's information with
print_submarine_stats(). - Exit the program.
- Print the board with
The Order of a Turn
Once the Submarine has moved, a turn resolves in this order. Later stages add more steps, but the order of these never changes:
- The Submarine moves, or rests.
- The turn's
5oxygen is used. - Collect the Treasure or Air Pocket on the tile the Submarine ended on. If that clears the last Treasure, every Exit unlocks.
- If the Submarine is on an
EXIT_UNLOCKEDtile, the player wins. - If oxygen has reached
0, the player loses. - If the Submarine is on a
MINE, the player loses. - Print the board.
Assumptions / Restrictions / Clarifications
- The Exits unlock as a group. There is no way to unlock only some of them.
- An
EXIT_UNLOCKEDtile stays unlocked. No later stage locks it again. MINEis the only entity that can sink the Submarine in this stage. Jellyfish, Anglerfish, Torpedoes and Seeking Mines are added in Stages 3 and 4.- If the board was set up with no Treasure at all, the Exits unlock at the end of the Submarine's first turn.
- When the game ends, the board is printed one last time, then the win or loss message, then the Submarine's information.
Examples
Input:
x 5 7 t 5 6 e 5 5 d d
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 5 7
t 5 6
e
Enter the Submarine's starting position: 5 5
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>|[$]|[X]| | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
d
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | |[o>|[^]| | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+===+===+===+===+===+===+===+===+===+===+
d
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | |[o>| | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+===+===+===+===+===+===+===+===+===+===+
+=======================================+
| *** ESCAPED WITH THE TREASURE! *** |
+=======================================+
+=======================================+
| >> SUBMARINE STATUS << |
+=======================================+
| Oxygen : 90 |
| Treasure : 1 |
| Moves : 2 |
| Torpedoes : 4 |
+=======================================+
Input:
x 0 0 t 9 9 e 5 5 r r r r r r r r r r r r r r r r r r r r
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 0 0
t 9 9
e
Enter the Submarine's starting position: 5 5
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
+=======================================+
>> Out of oxygen! <<
+=======================================+
+=======================================+
| >> SUBMARINE STATUS << |
+=======================================+
| Oxygen : 0 |
| Treasure : 0 |
| Moves : 20 |
| Torpedoes : 4 |
+=======================================+
Input:
x 0 0 t 9 9 m 5 6 e 5 5 d
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 0 0
t 9 9
m 5 6
e
Enter the Submarine's starting position: 5 5
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>|(*)| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
d
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | |[o>| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
+=======================================+
>> Sunk by a Mine! <<
+=======================================+
+=======================================+
| >> SUBMARINE STATUS << |
+=======================================+
| Oxygen : 95 |
| Treasure : 0 |
| Moves : 1 |
| Torpedoes : 4 |
+=======================================+
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-stagecommand 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_submarine.c 1511 autotest-stage 02 cs_submarine give cs1511 ass1_cs_submarine cs_submarine.c
Stage 3
In Stage 3, the ocean starts fighting back. This milestone has been divided into five substages:
- Stage 3.1 - Anglerfish.
- Stage 3.2 - The Deep Sea.
- Stage 3.3 - Jellyfish.
- Stage 3.4 - Undo.
- Stage 3.5 - Ocean Currents.
Stage 3.1 - Anglerfish
Task
An Anglerfish sits motionless in the dark, invisible until you are almost on top of it. By the end of this substage, your program will let the user place Anglerfish during the Setup Phase, hide them until the Submarine is close, and sink the Submarine that swims into one.
Commands
a [row] [col]
Description
In this substage, you will:
- Extend your Setup Loop to handle one new command:
- Given the command
a [row] [col], add anANGLERFISHto that tile. - The validation rules from Stage 1.2 apply to this command exactly as they do to every other entity.
- Given the command
- Hide Anglerfish that have not been revealed. An
ANGLERFISHtile prints as ordinary ocean (three spaces) until it has been revealed. - Reveal an Anglerfish when the Submarine comes within 2 rows and within 2 columns of it.
- Keep it revealed. Once an Anglerfish has been revealed it stays revealed for the rest of the game, even after the Submarine swims away.
- Sink the Submarine that ends its turn on an
ANGLERFISHtile:- Print the board with
print_board(). - Call
print_loss_message(), passing itANGLERFISH. - Print the Submarine's information.
- Exit the program.
- Print the board with
Range wraps horizontally, like everything else in the ocean. An Anglerfish at column 0 is 1 column away from a Submarine at column COLS - 1. The following diagram shows the distance the Submarine must be from an Anglerfish to reveal it:
Assumptions / Restrictions / Clarifications
- Being within range is measured from the Submarine's position every time the board is printed, using where the Submarine is at that moment. That includes the board printed when it spawns, the boards printed by
vanduin Stage 3, and the final board printed when the game is won or lost. - The Submarine can be sunk by an Anglerfish it has never seen. Swimming onto an unrevealed Anglerfish loses the game exactly as swimming onto a revealed one does.
- The
ANGLERFISHcount printed byprint_map_statistics()counts every Anglerfish on the board, revealed or not. - A tile holding an unrevealed Anglerfish is still occupied for the purposes of Stage 1.2 validation.
Examples
Input:
x 9 0 t 0 0 a 5 9 e 5 5 d d d q
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 9 0
t 0 0
a 5 9
e
Enter the Submarine's starting position: 5 5
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[$]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
d
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[$]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | |[o>| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+===+===+===+===+===+===+===+===+===+===+
d
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[$]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | |[o>| |><>|
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+===+===+===+===+===+===+===+===+===+===+
d
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[$]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | |[o>|><>|
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+===+===+===+===+===+===+===+===+===+===+
q
============= Quitting Game =============
Input:
x 9 0 t 0 0 a 5 7 e 5 5 d d
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 9 0
t 0 0
a 5 7
e
Enter the Submarine's starting position: 5 5
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[$]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| |><>| | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
d
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[$]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | |[o>|><>| | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+===+===+===+===+===+===+===+===+===+===+
d
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[$]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | |[o>| | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+===+===+===+===+===+===+===+===+===+===+
+=======================================+
>> Sunk by a Anglerfish! <<
+=======================================+
+=======================================+
| >> SUBMARINE STATUS << |
+=======================================+
| Oxygen : 90 |
| Treasure : 0 |
| Moves : 2 |
| Torpedoes : 4 |
+=======================================+
Autotest
Stage 3.2 - The Deep Sea
Task
Light does not reach the bottom of the ocean, and pressure makes every breath expensive. In this substage, how much the Submarine can see and how fast it burns oxygen both depend on how deep it is.
Commands
v
Description
In this substage, you will:
-
Handle the new Gameplay command
v, which switches Deep Sea mode on and off:- The first
vswitches it on. Print"Deep sea mode enabled!\n", then print the board. - The next
vswitches it off again. Print"Deep sea mode disabled!\n", then print the board. vis not a turn. No oxygen is used and the move count does not change.- Everything below applies only while Deep Sea mode is on. With it off, the whole board is visible and a turn costs a flat
5oxygen, exactly as it has since Stage 2.
- The first
-
Limit what the Submarine can see. With the Submarine at row
n, it can see everything within a radius ofROWS - ntiles, measured as straight-line Euclidean distance. A tile exactlyradiustiles away is visible. Column distance is measured the shorter way around the board. Every tile outside that circle prints asHIDDEN, which draws as###.The Euclidean distance between two tiles
[r1][c1]and[r2][c2]can be calculated as:distance = sqrt((r1 - r2) ^ 2 + (c1 - c2) ^ 2) -
Change how oxygen is used. While Deep Sea mode is on, a turn no longer costs a flat
5oxygen. It costs[row] + 1, where[row]is the row the Submarine ends the turn on.
Because the ocean wraps, the number of visible tiles depends only on the Submarine's row, never its column. On the ocean floor the radius is 1, and the Submarine can see nothing beyond the tiles directly adjacent to it.
The same ocean seen from row 0, row 2, row 5 and row 9, with the Submarine in column 7 each time. Everything outside the circle prints as HIDDEN, and the circle wraps around the side of the board.
Assumptions / Restrictions / Clarifications
- Deep Sea mode starts off. Until the first
v, the game behaves exactly as it did in Stage 3.1. vmay be used as often as you like, and the Submarine can switch back and forth freely.- Switching Deep Sea mode off restores full vision and the flat
5oxygen cost. Oxygen already spent is not refunded. - Oxygen can go below zero. In Deep Sea mode a turn can cost up to
10. So if you move on row9with3oxygen left, you will drop to-7. - An Air Pocket is collected before the loss check, and it adds
20to the oxygen level. For example, if the Submarine went to-7oxygen but collects an Air Pocket, its oxygen will be13, and the Submarine survives. - Hiding a tile changes nothing about it. A Mine you cannot see will still sink you, and Treasure you cannot see is still on the board and still keeps the Exits locked.
- The Submarine is always visible, since it is
0tiles from itself.
Examples
Input:
x 0 0 t 9 9 e 5 5 v s s s s v q
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 0 0
t 9 9
e
Enter the Submarine's starting position: 5 5
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
v
Deep sea mode enabled!
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|###|###|###|###|###| |###|###|###|###|
+---+---+---+---+---+---+---+---+---+---+
|###|###| | | | | | | |###|
+---+---+---+---+---+---+---+---+---+---+
|###| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|###| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|###| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
|###| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|###| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|###| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|###|###| | | | | | | |###|
+===+===+===+===+===+===+===+===+===+===+
s
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|###|###|###|###|###|###|###|###|###|###|
+---+---+---+---+---+---+---+---+---+---+
|###|###|###|###|###|###|###|###|###|###|
+---+---+---+---+---+---+---+---+---+---+
|###|###|###|###|###| |###|###|###|###|
+---+---+---+---+---+---+---+---+---+---+
|###|###|###| | | | | |###|###|
+---+---+---+---+---+---+---+---+---+---+
|###|###| | | | | | | |###|
+---+---+---+---+---+---+---+---+---+---+
|###|###| | | | | | | |###|
+---+---+---+---+---+---+---+---+---+---+
|###| | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
|###|###| | | | | | | |###|
+---+---+---+---+---+---+---+---+---+---+
|###|###| | | | | | | |###|
+---+---+---+---+---+---+---+---+---+---+
|###|###|###| | | | | |###|###|
+===+===+===+===+===+===+===+===+===+===+
s
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|###|###|###|###|###|###|###|###|###|###|
+---+---+---+---+---+---+---+---+---+---+
|###|###|###|###|###|###|###|###|###|###|
+---+---+---+---+---+---+---+---+---+---+
|###|###|###|###|###|###|###|###|###|###|
+---+---+---+---+---+---+---+---+---+---+
|###|###|###|###|###|###|###|###|###|###|
+---+---+---+---+---+---+---+---+---+---+
|###|###|###|###|###| |###|###|###|###|
+---+---+---+---+---+---+---+---+---+---+
|###|###|###| | | | | |###|###|
+---+---+---+---+---+---+---+---+---+---+
|###|###|###| | | | | |###|###|
+---+---+---+---+---+---+---+---+---+---+
|###|###| | | |[o>| | | |###|
+---+---+---+---+---+---+---+---+---+---+
|###|###|###| | | | | |###|###|
+---+---+---+---+---+---+---+---+---+---+
|###|###|###| | | | | |###|###|
+===+===+===+===+===+===+===+===+===+===+
s
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|###|###|###|###|###|###|###|###|###|###|
+---+---+---+---+---+---+---+---+---+---+
|###|###|###|###|###|###|###|###|###|###|
+---+---+---+---+---+---+---+---+---+---+
|###|###|###|###|###|###|###|###|###|###|
+---+---+---+---+---+---+---+---+---+---+
|###|###|###|###|###|###|###|###|###|###|
+---+---+---+---+---+---+---+---+---+---+
|###|###|###|###|###|###|###|###|###|###|
+---+---+---+---+---+---+---+---+---+---+
|###|###|###|###|###|###|###|###|###|###|
+---+---+---+---+---+---+---+---+---+---+
|###|###|###|###|###| |###|###|###|###|
+---+---+---+---+---+---+---+---+---+---+
|###|###|###|###| | | |###|###|###|
+---+---+---+---+---+---+---+---+---+---+
|###|###|###| | |[o>| | |###|###|
+---+---+---+---+---+---+---+---+---+---+
|###|###|###|###| | | |###|###|###|
+===+===+===+===+===+===+===+===+===+===+
s
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|###|###|###|###|###|###|###|###|###|###|
+---+---+---+---+---+---+---+---+---+---+
|###|###|###|###|###|###|###|###|###|###|
+---+---+---+---+---+---+---+---+---+---+
|###|###|###|###|###|###|###|###|###|###|
+---+---+---+---+---+---+---+---+---+---+
|###|###|###|###|###|###|###|###|###|###|
+---+---+---+---+---+---+---+---+---+---+
|###|###|###|###|###|###|###|###|###|###|
+---+---+---+---+---+---+---+---+---+---+
|###|###|###|###|###|###|###|###|###|###|
+---+---+---+---+---+---+---+---+---+---+
|###|###|###|###|###|###|###|###|###|###|
+---+---+---+---+---+---+---+---+---+---+
|###|###|###|###|###|###|###|###|###|###|
+---+---+---+---+---+---+---+---+---+---+
|###|###|###|###|###| |###|###|###|###|
+---+---+---+---+---+---+---+---+---+---+
|###|###|###|###| |[o>| |###|###|###|
+===+===+===+===+===+===+===+===+===+===+
v
Deep sea mode disabled!
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
q
============= Quitting Game =============
Input:
x 9 0 t 9 9 e 0 5 p v s s s p w w p q
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 9 0
t 9 9
e
Enter the Submarine's starting position: 0 5
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
p
+=======================================+
| >> SUBMARINE STATUS << |
+=======================================+
| Oxygen : 100 |
| Treasure : 0 |
| Moves : 0 |
| Torpedoes : 4 |
+=======================================+
v
Deep sea mode enabled!
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|###| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
s
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|###| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
s
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|###|###| | | | | | | |###|
+===+===+===+===+===+===+===+===+===+===+
s
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|###| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|###|###| | | | | | | |###|
+===+===+===+===+===+===+===+===+===+===+
p
+=======================================+
| >> SUBMARINE STATUS << |
+=======================================+
| Oxygen : 91 |
| Treasure : 0 |
| Moves : 3 |
| Torpedoes : 4 |
+=======================================+
w
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|###|###| | | | | | | |###|
+===+===+===+===+===+===+===+===+===+===+
w
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|###| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
p
+=======================================+
| >> SUBMARINE STATUS << |
+=======================================+
| Oxygen : 86 |
| Treasure : 0 |
| Moves : 5 |
| Torpedoes : 4 |
+=======================================+
q
============= Quitting Game =============
Autotest
Stage 3.3 - Jellyfish
Task
Unlike an Anglerfish, a Jellyfish can move around the board. Each one drifts back and forth along a single axis, and touching one loses the game.
Commands
j [axis] [row] [col]
Description
In this substage, you will:
- Extend your Setup Loop to handle one new command:
- Given the command
j [axis] [row] [col], add aJELLYFISHto that tile. - If the axis is
v, the Jellyfish patrols vertically and starts moving up, towards the surface. - If the axis is
h, the Jellyfish patrols horizontally and starts moving right. - The validation rules from Stage 1.2 apply to this command.
- Given the command
- Move every Jellyfish once per turn, after the Submarine's turn has resolved. For each Jellyfish:
- Look at the tile it is facing.
- If that tile is occupied, reverse the Jellyfish's direction. It does not move this turn, and will try the new direction next turn.
- Otherwise, move the Jellyfish onto it.
- Sink the Submarine a Jellyfish drifts into. If a Jellyfish moves onto the Submarine's tile:
- Print the board with
print_board(). - Call
print_loss_message(), passing itJELLYFISH. - Print the Submarine's information.
- Exit the program.
- Print the board with
A tile is occupied if its entity is anything other than OCEAN, for example, Seaweed, Treasure, Air Pockets, Mines, Exits, Anglerfish (including hidden Anglerfish) and other Jellyfish all count. For a vertical Jellyfish, the surface and the ocean floor are occupied too, since there is nothing beyond them.
Because Jellyfish only ever move onto ocean, they can never destroy Treasure, sit on an Exit, or wander off their axis.
Where This Fits In The Turn
Jellyfish move at the end of the turn, after the Submarine has moved, collected, and used its oxygen:
- The Submarine moves, or rests.
- The turn's oxygen is used.
- Collect the Treasure or Air Pocket on the tile the Submarine ended on. If that clears the last Treasure, every Exit unlocks.
- If the Submarine is on an
EXIT_UNLOCKEDtile, the player wins. - If oxygen has reached
0, the player loses. - If the Submarine is on a
MINE, aJELLYFISHor anANGLERFISH, the player loses. - Every Jellyfish moves.
- If a Jellyfish moved onto the Submarine, the player loses.
- Print the board.
Assumptions / Restrictions / Clarifications
- Every Jellyfish looks at the board as it stood at the start of the Jellyfish step, and they all move at the same moment. A Jellyfish that is about to move out of the way still counts as being in the way.
- A Jellyfish blocked by another Jellyfish changes direction. If two are facing each other, both change direction and neither moves.
- Two Jellyfish can never end up on the same tile. If two would move onto the same tile, both should reverse direction and not move.
- When a Jellyfish changes direction, it does not matter whether the tile behind it is occupied. It stays where it is with its direction flipped, and tries again next turn.
- A horizontal Jellyfish never reaches an edge, because the ocean wraps. It circles the board unless something blocks it.
- Only the axes
vandhwill be tested. - Jellyfish do not move on a turn where the Submarine's move was rejected. A rejected move is not a turn, so nothing in the list above happens.
vis not a turn either, so toggling Deep Sea mode never moves a Jellyfish.- A Jellyfish outside the visible circle in Deep Sea mode still moves, and can drift out of the darkness onto you.
Examples
Input:
x 9 0 t 9 9 j h 5 3 j v 5 8 e 0 5 r r r q
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 9 0
t 9 9
j h 5 3
j v 5 8
e
Enter the Submarine's starting position: 0 5
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | |(~)| | | | |(~)| |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | |(~)| |
+---+---+---+---+---+---+---+---+---+---+
| | | | |(~)| | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | |(~)| |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |(~)| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | |(~)| |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | |(~)| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
q
============= Quitting Game =============
Input:
x 9 0 t 9 9 j h 5 3 s 5 4 v 1 e 0 5 r r r q
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 9 0
t 9 9
j h 5 3
s 5 4 v 1
e
Enter the Submarine's starting position: 0 5
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | |(~)|)|(| | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | |(~)|)|(| | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | |(~)| |)|(| | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| |(~)| | |)|(| | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
q
============= Quitting Game =============
Input:
x 9 0 t 9 9 j h 5 3 j h 7 2 e 5 5 r r
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 9 0
t 9 9
j h 5 3
j h 7 2
e
Enter the Submarine's starting position: 5 5
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | |(~)| |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | |(~)| | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | |(~)|[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | |(~)| | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | |(~)| | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
+=======================================+
>> Sunk by a Jellyfish! <<
+=======================================+
+=======================================+
| >> SUBMARINE STATUS << |
+=======================================+
| Oxygen : 90 |
| Treasure : 0 |
| Moves : 2 |
| Torpedoes : 4 |
+=======================================+
Autotest
Stage 3.4 - Undo
Task
The ocean is unforgiving, and a single move into the dark can end a game. This substage lets the user take it back.
Commands
u [turns]
Description
In this substage, you will:
- Handle the new Gameplay command
u [turns], which rewinds the game by[turns]turns. - Restore everything to how it stood at the end of that earlier turn:
- The whole board, including Treasure, Air Pockets, Mines and Seaweed.
- The Submarine's position, oxygen, treasure collected and turns taken.
- Every Jellyfish's position and the direction it was facing.
- Which Anglerfish had been revealed.
- Rewind no further than the start of the game. If
[turns]is larger than the number of turns taken, restore the game to the start of the Gameplay Phase. - Print the board once the game has been restored.
An undo is not a turn. It uses no oxygen, does not add to the number of turns taken, and no Jellyfish moves while it happens.
Assumptions / Restrictions / Clarifications
[turns]will always be at least1.- The Gameplay Phase will never run for more than
256turns, and[turns]will never be more than256, so no more than256turns can ever need to be undone. - Undoing at the very start of the Gameplay Phase is allowed. There are no turns to undo, so nothing changes, and the board is printed unchanged.
- A turn that ended the game cannot be undone, because the program has already exited.
- Undo does not touch Deep Sea mode.
vis not a turn, so there is nothing to rewind: if the lights were off before the undo, they are still off after it.
Examples
Input:
x 0 0 t 9 9 t 5 6 j h 5 0 e 5 5 d d p u 1 p q
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 0 0
t 9 9
t 5 6
j h 5 0
e
Enter the Submarine's starting position: 5 5
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|(~)| | | | |[o>|[$]| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
d
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| |(~)| | | | |[o>| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
d
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | |(~)| | | | |[o>| | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
p
+=======================================+
| >> SUBMARINE STATUS << |
+=======================================+
| Oxygen : 90 |
| Treasure : 1 |
| Moves : 2 |
| Torpedoes : 4 |
+=======================================+
u 1
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| |(~)| | | | |[o>| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
p
+=======================================+
| >> SUBMARINE STATUS << |
+=======================================+
| Oxygen : 95 |
| Treasure : 1 |
| Moves : 1 |
| Torpedoes : 4 |
+=======================================+
q
============= Quitting Game =============
Input:
x 0 0 t 9 9 t 3 5 j h 5 0 e 5 5 r w w p u 9 p q
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 0 0
t 9 9
t 3 5
j h 5 0
e
Enter the Submarine's starting position: 5 5
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[$]| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|(~)| | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[$]| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| |(~)| | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
w
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[$]| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | |(~)| | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
w
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | |(~)| | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
p
+=======================================+
| >> SUBMARINE STATUS << |
+=======================================+
| Oxygen : 85 |
| Treasure : 1 |
| Moves : 3 |
| Torpedoes : 4 |
+=======================================+
u 9
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[$]| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|(~)| | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
p
+=======================================+
| >> SUBMARINE STATUS << |
+=======================================+
| Oxygen : 100 |
| Treasure : 0 |
| Moves : 0 |
| Torpedoes : 4 |
+=======================================+
q
============= Quitting Game =============
Autotest
Stage 3.5 - Ocean Currents
Task
The ocean is not still. In this substage you will let the user place currents and have them carry the Submarine and the Jellyfish along.
Commands
c [direction] [row] [col]
Description
In this substage, you will:
- Handle the new Setup Phase command
c [direction] [row] [col], where[direction]isw,a,sord:
| Direction | Entity | Art |
|---|---|---|
w | CURRENT_UP | ^^^ |
a | CURRENT_LEFT | <<< |
s | CURRENT_DOWN | vvv |
d | CURRENT_RIGHT | >>> |
- Push the Submarine after every turn it takes. If the tile the Submarine is standing on is a current, move it one tile in that current's direction. This happens whether the Submarine moved or rested.
- Chain the pushes. If the Submarine lands on another current, it is pushed again, up to a maximum of
5pushes in one turn. After the fifth push the Submarine stops, even if it is still standing on a current. - Stop the chain when a push is blocked. A push into
SEAWEEDor anEXIT_LOCKEDtile does not happen, and no further pushes happen that turn. ACURRENT_UPon row0and aCURRENT_DOWNon rowROWS - 1have nowhere to push to, so they are blocked in the same way. - Sink the Submarine if it is carried into a hazard. If a push moves the Submarine onto a
MINE, anANGLERFISHor aJELLYFISH, it is destroyed where the push put it, part-way through the ride:- Print the board with
print_board(). - Call
print_loss_message(), passing it whichever hazard it landed on. - Print the Submarine's information.
- Exit the program.
- Print the board with
- Carry Jellyfish on the currents as well. A Jellyfish that swims onto a current during the Hazard turn is pushed along it, chaining and capped at
5exactly like the Submarine. - Rotate every current
90degrees clockwise every3turns:
^^^ -> >>> -> vvv -> <<< -> ^^^
All of them rotate at once, in place, as the very last thing in the turn, after every hazard has moved and immediately before the board is printed.
Carried Jellyfish
A Jellyfish being carried is not the same as a Jellyfish swimming:
- It keeps its own patrol direction. Once the ride ends, the Jellyfish carries on patrolling the way it was already facing.
- It is carried only on the turn it swims onto the current. A Jellyfish sitting on a current at the start of the Hazard turn is not picked up again, unlike the Submarine, which is pushed every turn.
- A push is blocked by anything that is not
OCEAN. A Jellyfish whose push is blocked simply rests where it is. - A Jellyfish carried onto the Submarine sinks it, exactly as one that swims onto it does.
- Moving and being carried are two separate steps. Every Jellyfish moves first, all at the same moment, exactly as in Stage 3.3. Only then are they carried.
- Jellyfish are carried one at a time, starting from row
0and working down, left to right within a row. Each ride finishes before the next Jellyfish is considered, so a Jellyfish can be blocked by one that has already been carried, and two can never be carried onto the same tile.
The following diagram shows how Jellyfish interact with currents. The first board is the start of the turn. In the second, both Jellyfish have made their own move: the left one has swum onto the current at [5][4], and the lower one has swum up onto [5][6]. The third board is the end of the turn, after each Jellyfish has been carried by the current.
The Order of a Turn
- The Submarine moves or rests.
- The turn's oxygen is used, based on the row the Submarine moved to.
- Currents push the Submarine, up to
5times. If a push carries it onto any hazard, the player loses straight away. If the Submarine has just moved onto a hazard, it is not pushed at all, and it is lost at step 7 on the tile it moved onto. - Collect the Treasure or Air Pocket on the tile the Submarine ended on. If that clears the last Treasure, every Exit unlocks.
- If the Submarine is on an
EXIT_UNLOCKEDtile, the player wins. - If oxygen has reached
0, the player loses. - If the Submarine is on a
MINE, aJELLYFISHor anANGLERFISH, the player loses. - Every Jellyfish moves, and any that swims onto a current is carried.
- If a Jellyfish moved or was carried onto the Submarine, the player loses.
- Every
3turns, all currents rotate90degrees clockwise. - Print the board.
The currents rotate on every third turn, including a turn that ends the game. A win or a loss on turn 3, 6 or 9 prints its final board with the currents already turned.
Assumptions / Restrictions / Clarifications
- Pushes wrap horizontally.
CURRENT_LEFTon column0pushes to columnCOLS - 1. - In Deep Sea mode the turn's oxygen costs
[row] + 1for the row the Submarine moved to, before any current has pushed it. Oxygen is spent at step 2, so where the current later carries the Submarine does not change what the turn cost. - The rotation is counted in turns, the same count
pprints as Moves.p,m,vanduare not turns and do not advance it. - The
ccommand follows the Stage 1.2 validation rules like every other Setup command. - The Submarine cannot start on a current either. A starting position on a current tile is rejected with
"The Submarine cannot start here!\n", exactly as Stage 1.4 rejects one on an entity. - If a tile holds both a current and another entity at the end of a turn, print the entity: a Jellyfish on a current prints as
(~), not as the current. The current is still there, and prints again as soon as the entity moves off. Nothing ever destroys a current. - Undo must restore every current's direction, along with everything it already restored in Stage 3.4.
- Only the directions
w,a,sanddwill be tested.
Examples
Input:
x 3 5 t 5 5 o 4 5 c d 5 1 c d 5 2 c d 5 3 c d 5 4 s 5 6 h 1 e 5 2 5 6 5 0 d m w w
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 3 5
t 5 5
o 4 5
c d 5 1
c d 5 2
c d 5 3
c d 5 4
s 5 6 h 1
e
Enter the Submarine's starting position: 5 2
The Submarine cannot start here!
Enter the Submarine's starting position: 5 6
The Submarine cannot start here!
Enter the Submarine's starting position: 5 0
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[X]| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |oOo| | | | |
+---+---+---+---+---+---+---+---+---+---+
|[o>|>>>|>>>|>>>|>>>|[$]|)|(| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
d
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[^]| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |oOo| | | | |
+---+---+---+---+---+---+---+---+---+---+
| |>>>|>>>|>>>|>>>|[o>|)|(| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+===+===+===+===+===+===+===+===+===+===+
m
+=======================================+
| >> MAP STATISTICS << |
+=======================================+
| Treasure : 0 |
| Air Pockets : 1 |
| Seaweed : 1 |
+---------------------------------------+
| Mines : 0 |
| Jellyfish : 0 |
| Anglerfish : 0 |
+---------------------------------------+
| Exits : 1 |
+=======================================+
w
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[^]| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| |>>>|>>>|>>>|>>>| |)|(| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+===+===+===+===+===+===+===+===+===+===+
w
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| |vvv|vvv|vvv|vvv| |)|(| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+===+===+===+===+===+===+===+===+===+===+
+=======================================+
| *** ESCAPED WITH THE TREASURE! *** |
+=======================================+
+=======================================+
| >> SUBMARINE STATUS << |
+=======================================+
| Oxygen : 95 |
| Treasure : 1 |
| Moves : 3 |
| Torpedoes : 4 |
+=======================================+
Input:
x 0 0 t 9 9 c d 5 1 c d 5 2 c d 5 3 c d 5 4 c d 5 5 c d 5 6 c d 5 7 c d 5 8 c d 5 9 e 5 0 d d d d p q
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 0 0
t 9 9
c d 5 1
c d 5 2
c d 5 3
c d 5 4
c d 5 5
c d 5 6
c d 5 7
c d 5 8
c d 5 9
e
Enter the Submarine's starting position: 5 0
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[o>|>>>|>>>|>>>|>>>|>>>|>>>|>>>|>>>|>>>|
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
d
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| |>>>|>>>|>>>|>>>|>>>|[o>|>>>|>>>|>>>|
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
d
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[o>|>>>|>>>|>>>|>>>|>>>|>>>|>>>|>>>|>>>|
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
d
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| |vvv|vvv|vvv|vvv|vvv|[o>|vvv|vvv|vvv|
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
d
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| |vvv|vvv|vvv|vvv|vvv|vvv|vvv|vvv|vvv|
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | |[o>| | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
p
+=======================================+
| >> SUBMARINE STATUS << |
+=======================================+
| Oxygen : 80 |
| Treasure : 0 |
| Moves : 4 |
| Torpedoes : 4 |
+=======================================+
q
============= Quitting Game =============
Input:
x 9 0 t 9 9 c w 3 3 c d 3 5 c s 3 7 c a 5 5 e 0 5 s s s a s w q
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 9 0
t 9 9
c w 3 3
c d 3 5
c s 3 7
c a 5 5
e
Enter the Submarine's starting position: 0 5
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | |^^^| |>>>| |vvv| | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |<<<| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
s
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | |^^^| |>>>| |vvv| | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |<<<| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
s
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | |^^^| |>>>| |vvv| | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |<<<| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
s
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | |>>>| |vvv|[o>|<<<| | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |^^^| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
a
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | |>>>| |vvv| |<<<| | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |^^^| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
s
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | |>>>| |vvv| |<<<| | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |^^^| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
w
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | |vvv| |<<<| |^^^| | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |>>>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
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-stagecommand 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_submarine.c 1511 autotest-stage 03 cs_submarine give cs1511 ass1_cs_submarine cs_submarine.c
Stage 4
Welcome to Stage 4! In this stage you will extend CS Submarine with two advanced features. This milestone has been divided into two substages:
- Stage 4.1 - Torpedoes.
- Stage 4.2 - Seeking Mines.
Stage 4.1 - Torpedoes
Task
So far the Submarine has had no way to fight back. In this substage you will equip the Submarine with 4 torpedoes, and once fired, a torpedo keeps travelling on its own.
Commands
f [direction]
Description
In this substage, you will:
- Handle the new Gameplay command
f [direction], where[direction]isw,a,sord:- The Submarine has
4torpedoes for the whole game. Firing costs one torpedo. - Firing is a turn. It uses oxygen and counts towards the number of turns taken, but the Submarine does not move. A current under the Submarine still pushes it, exactly as it does on a turn spent resting.
- If the Submarine has no torpedoes left, print
"No torpedoes remaining!\n". This is not a turn: no oxygen is used, no current pushes, and the board is not printed.
- The Submarine has
- Keep the torpedo count up to date. The
pcommand already prints torpedoes remaining; until now it has always shown4. - Move and launch torpedoes each turn:
- First, every torpedo already in flight moves
1tile in the direction it was fired. They all move at the same moment. - Then, if a torpedo was fired this turn, it launches and travels
2tiles from the Submarine in the chosen direction. It does not advance again until the next turn. - A torpedo launches from where the Submarine ends the turn, after any current has pushed it.
- First, every torpedo already in flight moves
- Resolve each tile as a torpedo enters it. If something consumes or destroys a newly launched torpedo on its first tile, it never reaches its second.
| Tile | What happens |
|---|---|
OCEAN | The torpedo travels on. |
| A current | The torpedo crosses it as if it were ocean. The current is not destroyed. |
TREASURE | Collected, exactly as if the Submarine had swum over it. The torpedo travels on. |
AIR_POCKET | Collected, refilling the Submarine's oxygen. The torpedo travels on. |
JELLYFISH | Destroyed. The tile becomes OCEAN and the torpedo is gone. |
ANGLERFISH | Destroyed. The tile becomes OCEAN and the torpedo is gone. This includes hidden anglerfish. |
MINE | Detonated. The tile becomes OCEAN and the torpedo is gone. |
SEAWEED | The torpedo is absorbed. The Seaweed survives. |
EXIT_LOCKED / EXIT_UNLOCKED | The torpedo is absorbed. The Exit survives. |
TORPEDO | Both torpedoes are destroyed. The tile becomes OCEAN. |
| The Submarine | The player loses. |
- Sink the Submarine that touches a torpedo. If the Submarine ends its move on a torpedo, is carried onto one by a current, or a torpedo moves onto the Submarine:
- Print the board with
print_board(). - Call
print_loss_message(), passing itTORPEDO. - Print the Submarine's information.
- Exit the program.
- Print the board with
A torpedo travelling left or right wraps around the ocean and keeps going. A torpedo travelling up or down expires when it passes the surface or the ocean floor.
A torpedo fired to the right from [5][6]: two tiles as it launches, then one tile a turn, wrapping past column COLS - 1. The label between two boards is the command that turned the left one into the right one.
The Order of a Turn
- The Submarine moves, rests, or fires. Firing spends a torpedo, but the torpedo does not launch yet.
- The turn's oxygen is used, based on the row the Submarine moved to.
- Currents push the Submarine, up to
5times. If a push carries it onto any hazard, the player loses straight away. If the Submarine has just moved onto a hazard, it is not pushed at all, and it is lost at step 7 on the tile it moved onto. - Collect the Treasure or Air Pocket on the tile the Submarine ended on. If that clears the last Treasure, every Exit unlocks.
- If the Submarine is on an
EXIT_UNLOCKEDtile, the player wins. - If oxygen has reached
0, the player loses. - If the Submarine is on a
MINE, aJELLYFISH, anANGLERFISHor aTORPEDO, the player loses. - Every torpedo already in flight advances one tile, then a torpedo fired this turn launches and travels its opening
2tiles. - If a torpedo moved onto the Submarine, the player loses.
- If a torpedo took the last Treasure, unlock every Exit.
- Every Jellyfish moves, and any that swims onto a current is carried.
- If a Jellyfish moved or was carried onto the Submarine, the player loses.
- Every
3turns, all currents rotate90degrees clockwise. - Print the board.
Assumptions / Restrictions / Clarifications
- All
4torpedoes may be in flight at once. - A torpedo that runs off the top or bottom of the board during its opening 2 tiles is gone immediately, and is still spent.
- If multiple torpedoes would advance onto the same tile, the tile resolves according to the table above, the torpedoes are destroyed and that tile becomes
OCEAN. - If two torpedoes swap tiles by moving past each other head-on, both survive and travel on.
- A torpedo blocks a Jellyfish, because a Jellyfish only moves onto
OCEAN. - Treasure destroyed by a torpedo still counts towards clearing the board. If a torpedo collects the last Treasure, the Exits unlock at step 10 of that same turn.
- Oxygen collected by a torpedo is capped at
100, the same as swimming over an Air Pocket. - Torpedoes are not affected by currents. A torpedo crosses a current tile as if it were ocean, and never changes direction, however the currents rotate.
- A
TORPEDOis now one of the hazards a current can carry the Submarine onto, exactly as aMINE, anANGLERFISHor aJELLYFISHis in Stage 3.5. - Only the directions
w,a,sanddwill be tested. vis not a turn, so toggling Deep Sea mode never advances a torpedo or rotates a current.- Your undo from Stage 3.4 must now also restore the torpedoes remaining and every torpedo in flight, with its direction.
Examples
Input:
x 0 0 t 9 9 c d 5 5 s 5 6 h 1 e 5 4 d f a r r p q
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 0 0
t 9 9
c d 5 5
s 5 6 h 1
e
Enter the Submarine's starting position: 5 4
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | |[o>|>>>|)|(| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
d
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>|)|(| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
f a
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | |-*-| |[o>|)|(| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | |-*-| | |[o>|)|(| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| |-*-| | | |vvv|)|(| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
p
+=======================================+
| >> SUBMARINE STATUS << |
+=======================================+
| Oxygen : 80 |
| Treasure : 0 |
| Moves : 4 |
| Torpedoes : 3 |
+=======================================+
q
============= Quitting Game =============
Input:
x 0 0 t 9 9 m 5 8 m 3 5 c d 6 5 e 5 5 m f d m r m f w m s p q
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 0 0
t 9 9
m 5 8
m 3 5
c d 6 5
e
Enter the Submarine's starting position: 5 5
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |(*)| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | |(*)| |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |>>>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
m
+=======================================+
| >> MAP STATISTICS << |
+=======================================+
| Treasure : 1 |
| Air Pockets : 0 |
| Seaweed : 0 |
+---------------------------------------+
| Mines : 2 |
| Jellyfish : 0 |
| Anglerfish : 0 |
+---------------------------------------+
| Exits : 1 |
+=======================================+
f d
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |(*)| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| |-*-|(*)| |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |>>>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
m
+=======================================+
| >> MAP STATISTICS << |
+=======================================+
| Treasure : 1 |
| Air Pockets : 0 |
| Seaweed : 0 |
+---------------------------------------+
| Mines : 2 |
| Jellyfish : 0 |
| Anglerfish : 0 |
+---------------------------------------+
| Exits : 1 |
+=======================================+
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |(*)| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |>>>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
m
+=======================================+
| >> MAP STATISTICS << |
+=======================================+
| Treasure : 1 |
| Air Pockets : 0 |
| Seaweed : 0 |
+---------------------------------------+
| Mines : 1 |
| Jellyfish : 0 |
| Anglerfish : 0 |
+---------------------------------------+
| Exits : 1 |
+=======================================+
f w
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |vvv| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
m
+=======================================+
| >> MAP STATISTICS << |
+=======================================+
| Treasure : 1 |
| Air Pockets : 0 |
| Seaweed : 0 |
+---------------------------------------+
| Mines : 0 |
| Jellyfish : 0 |
| Anglerfish : 0 |
+---------------------------------------+
| Exits : 1 |
+=======================================+
s
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |vvv| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
p
+=======================================+
| >> SUBMARINE STATUS << |
+=======================================+
| Oxygen : 80 |
| Treasure : 0 |
| Moves : 4 |
| Torpedoes : 2 |
+=======================================+
q
============= Quitting Game =============
Input:
x 5 2 t 5 7 t 5 8 c a 5 4 c a 5 3 e 5 5 f d m r m a
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 5 2
t 5 7
t 5 8
c a 5 4
c a 5 3
e
Enter the Submarine's starting position: 5 5
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | |[X]|<<<|<<<|[o>| |[$]|[$]| |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
f d
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | |[X]|<<<|<<<|[o>| |-*-|[$]| |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+===+===+===+===+===+===+===+===+===+===+
m
+=======================================+
| >> MAP STATISTICS << |
+=======================================+
| Treasure : 1 |
| Air Pockets : 0 |
| Seaweed : 0 |
+---------------------------------------+
| Mines : 0 |
| Jellyfish : 0 |
| Anglerfish : 0 |
+---------------------------------------+
| Exits : 1 |
+=======================================+
r
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | |[^]|<<<|<<<|[o>| | |-*-| |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+===+===+===+===+===+===+===+===+===+===+
m
+=======================================+
| >> MAP STATISTICS << |
+=======================================+
| Treasure : 0 |
| Air Pockets : 0 |
| Seaweed : 0 |
+---------------------------------------+
| Mines : 0 |
| Jellyfish : 0 |
| Anglerfish : 0 |
+---------------------------------------+
| Exits : 1 |
+=======================================+
a
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | |[o>|^^^|^^^| | | |-*-| |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+===+===+===+===+===+===+===+===+===+===+
+=======================================+
| *** ESCAPED WITH THE TREASURE! *** |
+=======================================+
+=======================================+
| >> SUBMARINE STATUS << |
+=======================================+
| Oxygen : 85 |
| Treasure : 2 |
| Moves : 3 |
| Torpedoes : 3 |
+=======================================+
Autotest
Stage 4.2 - Seeking Mines
Task
Every hazard so far has either sat still or drifted. A Seeking Mine drives a route the user writes for it, over and over, for the rest of the game.
Commands
S [row] [col] [speed] [script]X
Description
In this substage, you will:
- Handle the new Setup Phase command
S [row] [col] [speed] [script]X, which places aSEEKING_MINE. It draws as{*}. - Read the
[script], a run ofw,a,sanddcharacters giving the route the mine drives. The script is terminated by a capitalX, which is never a step and never appears anywhere else. Read the script one character at a time until you reach it. - Drive the route. Every turn the mine takes
[speed]steps, one tile at a time, in the order the script gives. When the mine reaches theXit starts again at the first character.- With more than one mine on the board, they move a step at a time in rounds. Every mine takes its first step, in the order they were placed during Setup, then every mine takes its second step, and so on. A mine only takes a step in a round it still has
[speed]for, so a speed-1mine sits out every round after the first. [speed]is how many characters of the script the mine uses each turn. A mine placed withS 5 2 2 dwXmoves one tile right and one tile up on its first turn.
- With more than one mine on the board, they move a step at a time in rounds. Every mine takes its first step, in the order they were placed during Setup, then every mine takes its second step, and so on. A mine only takes a step in a round it still has
- Resolve each step:
| Tile | What happens |
|---|---|
SEAWEED, EXIT_LOCKED, EXIT_UNLOCKED | The step is blocked. The mine does not move. |
| Off the top or bottom of the board | The step is blocked. The mine does not move. |
| A current | The mine drives over it. The current is not destroyed and reappears once the mine moves on. |
SEEKING_MINE | The mines pass through each other. Neither is destroyed. |
TREASURE, AIR_POCKET, MINE, JELLYFISH, ANGLERFISH, TORPEDO | Destroyed. The tile becomes OCEAN. Nothing is collected, however if the last Treasure is destroyed, the Exits should unlock. |
| The Submarine | The player loses. |
Unless the table says otherwise, nothing the Seeking Mine drives over destroys it, and they never destroy each other. A torpedo is the only thing that can destroy a Seeking Mine.
- Consume a blocked step anyway. When a step cannot be taken, the mine stays where it is but still moves on to the next character of its script, and carries on until it has used all
[speed]steps for the turn. - Sink the Submarine on any step, not only the tile the mine finishes its turn on. The moment a step enters the Submarine's tile the game is over, so no other mine takes another step:
- Print the board with
print_board(). - Call
print_loss_message(), passing itSEEKING_MINE. - Print the Submarine's information.
- Exit the program.
- Print the board with
Seeking Mines move straight after the torpedoes, between steps 9 and 10 of the turn order in Stage 4.1.
Two Seeking Mines, placed with S 5 2 1 dX and S 5 4 1 aX, driving towards each other. On the second board they are on the same tile, which draws a single {*}; on the third they have passed through each other and carried on along their own scripts.
Assumptions / Restrictions / Clarifications
- The
Scommand follows the Stage 1.2 validation rules like every other Setup command. [speed]is at least1and at most64.- The script is at most
64steps long, not counting the terminatingX. It may also be empty:S 3 3 1 Xplaces a mine that has no route so never moves. - Multiple Seeking Mines may occupy the same tile. They pass through each other, the tile draws a single
{*}, and each carries on along its own script afterwards. - At most
10Seeking Mines will be placed. - The
Xterminator is guaranteed. - Steps wrap horizontally, like all movement in the ocean. Only the top and bottom edges block.
- The Submarine does not block a Seeking Mine, and neither does anything the mine destroys.
- Treasure destroyed by a Seeking Mine is gone, not collected. It does not raise the Treasure count, but it does bring the board closer to clear, so a Seeking Mine can unlock the Exits.
- An Air Pocket destroyed by a Seeking Mine refills nothing.
- Mines always step in the order they were placed during Setup, one step each per round. If a step sinks the Submarine the game ends immediately: no other mine takes another step that turn, including mines later in the same round.
- A torpedo that moves onto a tile holding a Seeking Mine destroys the mine and itself, exactly as it does with a plain
MINE. If several Seeking Mines are on that tile, the torpedo destroys all of them. - A Seeking Mine that steps onto a torpedo destroys the torpedo and carries on with the rest of its steps.
- A Jellyfish being carried by a current is blocked by a Seeking Mine, the same as by any other entity, and rests where it is.
- Seeking Mines are not carried by currents. Only the Submarine and Jellyfish are.
- A Seeking Mine can be on a current, because it travels over currents without destroying them. A push that carries the Submarine onto one sinks it exactly as a
TORPEDOor aJELLYFISHdoes, part-way through the ride, withprint_loss_message()passedSEEKING_MINE. - A Seeking Mine counts towards the Mines figure printed by
print_map_statistics(), together with plain Mines. Every Seeking Mine counts, two mines on the same tile add2, even though the tile draws a single{*}. - Undo must restore each Seeking Mine's position and how far through its script it had got.
Examples
Input:
x 9 0 t 9 9 t 5 1 o 6 9 m 6 0 S 5 8 2 ddsaX e 3 5 a s d s p m q
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 9 0
t 9 9
t 5 1
o 6 9
m 6 0
S 5 8 2 ddsaX
e
Enter the Submarine's starting position: 3 5
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| |[$]| | | | | | |{*}| |
+---+---+---+---+---+---+---+---+---+---+
|(*)| | | | | | | | |oOo|
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
a
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | |[o>| | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|{*}|[$]| | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|(*)| | | | | | | | |oOo|
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
s
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | |[o>| | | | | |
+---+---+---+---+---+---+---+---+---+---+
| |[$]| | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |{*}|
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
d
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| |[$]| | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| |{*}| | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
s
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| |[$]| | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|{*}| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
p
+=======================================+
| >> SUBMARINE STATUS << |
+=======================================+
| Oxygen : 80 |
| Treasure : 0 |
| Moves : 4 |
| Torpedoes : 4 |
+=======================================+
m
+=======================================+
| >> MAP STATISTICS << |
+=======================================+
| Treasure : 2 |
| Air Pockets : 0 |
| Seaweed : 0 |
+---------------------------------------+
| Mines : 1 |
| Jellyfish : 0 |
| Anglerfish : 0 |
+---------------------------------------+
| Exits : 1 |
+=======================================+
q
============= Quitting Game =============
Input:
x 8 2 t 2 2 t 9 9 s 9 6 h 1 S 6 0 3 sdX e 2 5 a a a s s q
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 8 2
t 2 2
t 9 9
s 9 6 h 1
S 6 0 3 sdX
e
Enter the Submarine's starting position: 2 5
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | |[$]| | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|{*}| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | |[X]| | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | |)|(| | |[$]|
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
a
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | |[$]| |[o>| | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| |{*}|[X]| | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | |)|(| | |[$]|
+===+===+===+===+===+===+===+===+===+===+
a
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | |[$]|[o>| | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | |[X]| | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | |{*}| | | |)|(| | |[$]|
+===+===+===+===+===+===+===+===+===+===+
a
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | |[o>| | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | |[X]| | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | |{*}| | |)|(| | |[$]|
+===+===+===+===+===+===+===+===+===+===+
s
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | |[o>| | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | |[X]| | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |{*}|)|(| | |[$]|
+===+===+===+===+===+===+===+===+===+===+
s
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | |[o>| | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | |[X]| | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |{*}|)|(| | |[$]|
+===+===+===+===+===+===+===+===+===+===+
q
============= Quitting Game =============
Input:
x 9 0 t 9 9 S 4 0 2 dX S 4 6 1 aX S 7 9 3 dsaX e 0 5 a s m d q
Input and Output:
dcc cs_submarine.c -o cs_submarine
./cs_submarine
=========================================
o o
o o |===================| o o
o o | Welcome to | o o
o o | CS SUBMARINE | o o
o |===================| o
~~~~~ ~~~~~
=========================================
============== Setup Phase ==============
Enter setup commands:
x 9 0
t 9 9
S 4 0 2 dX
S 4 6 1 aX
S 7 9 3 dsaX
e
Enter the Submarine's starting position: 0 5
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|{*}| | | | | |{*}| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |{*}|
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
============= Gameplay Phase ============
a
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | |[o>| | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | |{*}| | |{*}| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |{*}|
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
s
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | |[o>| | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | |{*}| | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |{*}|
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
m
+=======================================+
| >> MAP STATISTICS << |
+=======================================+
| Treasure : 1 |
| Air Pockets : 0 |
| Seaweed : 0 |
+---------------------------------------+
| Mines : 3 |
| Jellyfish : 0 |
| Anglerfish : 0 |
+---------------------------------------+
| Exits : 1 |
+=======================================+
d
+===+===+===+===+===+===+===+===+===+===+
|*** >> C S S U B M A R I N E << ***|
+===+===+===+===+===+===+===+===+===+===+
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | |[o>| | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | |{*}| | |{*}| | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | | |
+---+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |{*}|
+---+---+---+---+---+---+---+---+---+---+
|[X]| | | | | | | | |[$]|
+===+===+===+===+===+===+===+===+===+===+
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-stagecommand 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_submarine.c 1511 autotest-stage 04 cs_submarine give cs1511 ass1_cs_submarine cs_submarine.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 Submarine, 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_submarine.c code.
ls cs_submarine.c cs_submarine 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:
x 0 0 t 5 8 o 5 2 m 5 7 s 3 4 h 3 e 5 5
This puts a locked Exit in the top corner and scatters a Treasure, an Air Pocket, a Mine and a run of Seaweed around the ocean. The e ends the Setup Phase, and the 5 5 after it spawns the Submarine in the middle, so the game is ready to play the moment it starts.
3. Run the code with your file
Next, instead of just running ./cs_submarine, 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_submarine
Otherwise, use the following:
cat my_level.in | ./cs_submarine
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
As an extension, we have set up a starting point to add a texture pack to your game via SplashKit.
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_submarine cd cs_submarine
Set up your directory for SplashKit with:
1511 setup-splashkit-directory
Run this cp command to retrieve the sample code.
cp -n /web/cs1511/26T3/activities/cs_submarine/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_submarine.c.
To compile and run your program, use:
skm clang++ splashkit_cs_submarine.c -o splashkit_cs_submarine ./splashkit_cs_submarine
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.
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 😅.
Extra Extension
Finished everything? Here are some extra features you could add to make your game more interesting (not for marks but feel free to show your tutor or post on the course forum!):
- Sea Life: Add more creatures to the ocean. They could move in different patterns to the Jellyfish, hunt the Submarine instead of patrolling, or flee from it.
- Salvage: Give each Treasure a different value, and score the run on what the Submarine surfaced with rather than on simply escaping.
- Equipment: Let the player spend collected Treasure on upgrades between runs — a bigger air tank, more torpedoes, a brighter lamp for the deep sea.
- Sonar: Add a command that reveals a radius of the ocean for one turn, at the cost of extra oxygen.
Try to keep any additions manageable and within the scope of your current design. Congratulations on making such good progress!
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_submarine.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_submarine cs_submarine.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_submarine.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 26 October 2026 18: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
(2026-10-06 09:00) -
- Assignment released
-
Version 1.1
(2026-10-15 16:00) -
- Stage 3.5: Fixed rendering of currents in description