Assignment 1 - CS Submarine

Overview

Your task is to implement the CS Submarine game.

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

  1. Create a new folder for your assignment:
mkdir ass1
cd ass1
  1. 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.

  1. 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.

Two Phases: Setup and Gameplay

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 row 3.
  • 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 the struct tile at row 2 and column 3.
  • board[2][3].entity accesses the enum entity of this struct tile.

Similarly:

  • board[8][1] accesses the struct tile at row 8 and column 1.
  • board[8][1].entity accesses the enum entity of this struct 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:

  1. The board array.
  2. The row position of the Submarine. Since the Submarine has not yet been placed on the board, we use the #define'd constant NO_SUBMARINE.
  3. The column position of the Submarine. Since the Submarine has not yet been placed on the board, we use the #define'd constant NO_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 the enum entity that sank it. You will first need it in Stage 2.5.

You will not need to call these:

  • print_board_line(), print_board_header() and print_tile_spacer() are helpers called by print_board().
  • get_name_from_type() converts an enum entity into a readable string, and is called by print_loss_message().

FAQ

Q: Can I edit the provided code?

Yes! Feel free to modify/replace/discard any of the provided:

  • #define constants,
  • enums,
  • structs, and
  • functions.

For example: you may wish to add fields to the provided struct tile definition. 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:

  1. Print the Setup Phase heading, "============== Setup Phase ==============\n".
  2. Print "Enter setup commands:\n".
  3. 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:
CommandEntityArt
t [row] [col]TREASURE[$]
o [row] [col]AIR_POCKEToOo
m [row] [col]MINE(*)
x [row] [col]EXIT_LOCKED[X]
  1. 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:

  1. Reject a placement that is not on the board. Print "Invalid location: position is not on the board!\n" and carry on reading commands.
  2. 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 0 and ROWS - 1, and a column when it is between 0 and COLS - 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:

  1. Handle the new Setup Phase command e, which ends the Setup Phase.
  2. Refuse to end setup until at least one EXIT_LOCKED has been placed. If e is 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.
  3. 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.
  4. Print the board with the Submarine on it, drawn as [o>.
  5. 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 board array. Keep track of its row and column and pass them to print_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. e ends 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:

  1. Reject a starting position that is not on the board. A row is on the board when it is between 0 and ROWS - 1, and a column when it is between 0 and COLS - 1.
  2. Reject a starting position on a tile that is not an OCEAN entity.
  3. For either, print "The Submarine cannot start here!\n" and prompt again with "Enter the Submarine's starting position: ".
  4. Keep prompting until a valid position is given.
  5. Print the board.
  6. 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:

  1. Handle the new Setup Phase command s [row] [col] [direction] [length], which places a run of SEAWEED, printed as )|(.
  2. Grow the run from [row] [col] for [length] tiles. The [direction] can be:
    • h grows right, along the row.
    • v grows up, towards the surface.
  3. 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".
  4. The SEAWEED is only placed when every tile on the path is valid.

Assumptions / Restrictions / Clarifications

  • [direction] is always h or v. No other direction will be tested.
  • [length] is always at least 1.
  • A run of length 1 is 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-stage command as shown below.
  • Remember -- give early, and give often. Only your last submission counts, but why not be safe and submit right now?
1511 style cs_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

  • q quits the game.
  • w moves the Submarine up.
  • a moves the Submarine left.
  • s moves the Submarine down.
  • d moves the Submarine right.
  • r counts as a move without moving the Submarine's position.

Description

In this substage, you will need to:

  1. 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.
  2. Implement a Gameplay Loop to repeatedly read in and handle user commands:

    • The first command to add to the Gameplay Loop is q to quit.
    • When the q command is entered, the program should immediately:
      • Print "============= Quitting Game =============\n".
      • Exit without any other output.
    • Only q prints that message. If [Ctrl-D] is pressed nothing extra should be printed.
  3. Move the Submarine:

    • The next Gameplay Loop commands move the Submarine by one grid cell at a time:
      • w moves the Submarine up, towards the surface (towards row 0).
      • a moves the Submarine left.
      • s moves the Submarine down, towards the ocean floor (towards row ROWS - 1).
      • d moves the Submarine right.
    • The Gameplay Loop should also handle a rest command:
      • r counts as a turn without changing the Submarine's position on the board.
  4. Wrap around the ocean:

    • The ocean wraps around horizontally. Moving left from column 0 places the Submarine at column COLS - 1, and moving right from column COLS - 1 places it at column 0.
    • The ocean does not wrap vertically. Moving up from the surface or down from the ocean floor is handled in Stage 2.2.
  5. 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 q is entered.

Assumptions / Restrictions / Clarifications

  • The s command moves the Submarine down. This is not related to the s Seaweed 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 TREASURE will 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 q is entered, or until [Ctrl-D] is pressed. Only q prints 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 SEAWEED entity.
  • The tile contains an EXIT_LOCKED entity.
  • The move is w and the Submarine is already at the surface, row 0.
  • The move is s and the Submarine is already at the ocean floor, row ROWS - 1.

If the Submarine attempts to move to an invalid destination:

  1. Print "The Submarine cannot move there!\n".
  2. The Submarine should not move.
  3. The turn does not happen. No oxygen is used, and the board is not printed.
  4. 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 0 and column COLS - 1 of that row holds Seaweed, then a is an invalid move.
  • Swimming onto a TREASURE or an AIR_POCKET is allowed, but you do not need to collect anything yet. Collecting is handled in Stage 2.3.
  • Swimming onto a MINE is allowed, and nothing happens to the Submarine yet. Losing the game is handled in Stage 2.5.
  • No EXIT_UNLOCKED tile 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:

  1. 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. Add 1 to the amount of treasure collected, and set the tile's entity to OCEAN.
    • If the tile contains an AIR_POCKET, use it. Add 20 to the Submarine's oxygen, and set the tile's entity to OCEAN.
  2. Track oxygen:
    • The Submarine starts the Gameplay Phase with 100 oxygen.
    • Every turn uses 5 oxygen. A rest is a turn, so resting also uses 5.
    • 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 to 100 instead.
  3. 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.

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 95 oxygen therefore spends 5 first and then refills, leaving the Submarine on a full 100.
  • The Submarine carries 4 torpedoes for the whole game, but has no way to fire one until Stage 4.1. The torpedo figure is therefore always 4 in 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:

  1. Given the command m, print the map statistics using the provided print_map_statistics() function.

print_map_statistics() takes seven inputs, in this order:

  1. The number of TREASURE tiles remaining on the board.
  2. The number of AIR_POCKET tiles remaining on the board.
  3. The number of SEAWEED tiles remaining on the board.
  4. The number of MINE tiles remaining on the board.
  5. The number of JELLYFISH tiles remaining on the board.
  6. The number of ANGLERFISH tiles remaining on the board.
  7. The number of Exit tiles on the board, both EXIT_LOCKED and EXIT_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

  • JELLYFISH and ANGLERFISH cannot be placed on the board yet, so both of those counts will always be 0 in 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:

  1. Unlock the Exits. Whenever a Treasure is collected, check the board: if no TREASURE tiles remain anywhere, change every EXIT_LOCKED tile to EXIT_UNLOCKED. Later stages add other ways for Treasure to leave the board, and the same check always applies.
  2. Win the game. If the Submarine ends its move on an EXIT_UNLOCKED tile:
    • 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.
  3. 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.
  4. Lose to a Mine. If the Submarine ends its turn on a MINE tile:
    • Print the board with print_board().
    • Call the provided print_loss_message() function, passing it MINE.
    • Print the Submarine's information with print_submarine_stats().
    • Exit the program.

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:

  1. The Submarine moves, or rests.
  2. The turn's 5 oxygen is used.
  3. Collect the Treasure or Air Pocket on the tile the Submarine ended on. If that clears the last Treasure, every Exit unlocks.
  4. If the Submarine is on an EXIT_UNLOCKED tile, the player wins.
  5. If oxygen has reached 0, the player loses.
  6. If the Submarine is on a MINE, the player loses.
  7. Print the board.

Assumptions / Restrictions / Clarifications

  • The Exits unlock as a group. There is no way to unlock only some of them.
  • An EXIT_UNLOCKED tile stays unlocked. No later stage locks it again.
  • MINE is 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-stage command as shown below.
  • Remember -- give early, and give often. Only your last submission counts, but why not be safe and submit right now?
1511 style cs_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:

  1. Extend your Setup Loop to handle one new command:
    • Given the command a [row] [col], add an ANGLERFISH to that tile.
    • The validation rules from Stage 1.2 apply to this command exactly as they do to every other entity.
  2. Hide Anglerfish that have not been revealed. An ANGLERFISH tile prints as ordinary ocean (three spaces) until it has been revealed.
  3. Reveal an Anglerfish when the Submarine comes within 2 rows and within 2 columns of it.
  4. Keep it revealed. Once an Anglerfish has been revealed it stays revealed for the rest of the game, even after the Submarine swims away.
  5. Sink the Submarine that ends its turn on an ANGLERFISH tile:
    • Print the board with print_board().
    • Call print_loss_message(), passing it ANGLERFISH.
    • Print the Submarine's information.
    • Exit the program.

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 v and u in 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 ANGLERFISH count printed by print_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:

  1. Handle the new Gameplay command v, which switches Deep Sea mode on and off:

    • The first v switches it on. Print "Deep sea mode enabled!\n", then print the board.
    • The next v switches it off again. Print "Deep sea mode disabled!\n", then print the board.
    • v is 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 5 oxygen, exactly as it has since Stage 2.
  2. Limit what the Submarine can see. With the Submarine at row n, it can see everything within a radius of ROWS - n tiles, measured as straight-line Euclidean distance. A tile exactly radius tiles away is visible. Column distance is measured the shorter way around the board. Every tile outside that circle prints as HIDDEN, 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)

  3. Change how oxygen is used. While Deep Sea mode is on, a turn no longer costs a flat 5 oxygen. 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.
  • v may 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 5 oxygen 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 row 9 with 3 oxygen left, you will drop to -7.
  • An Air Pocket is collected before the loss check, and it adds 20 to the oxygen level. For example, if the Submarine went to -7 oxygen but collects an Air Pocket, its oxygen will be 13, 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 0 tiles 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:

  1. Extend your Setup Loop to handle one new command:
    • Given the command j [axis] [row] [col], add a JELLYFISH to 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.
  2. 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.
  3. 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 it JELLYFISH.
    • Print the Submarine's information.
    • Exit the program.

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:

  1. The Submarine moves, or rests.
  2. The turn's oxygen is used.
  3. Collect the Treasure or Air Pocket on the tile the Submarine ended on. If that clears the last Treasure, every Exit unlocks.
  4. If the Submarine is on an EXIT_UNLOCKED tile, the player wins.
  5. If oxygen has reached 0, the player loses.
  6. If the Submarine is on a MINE, a JELLYFISH or an ANGLERFISH, the player loses.
  7. Every Jellyfish moves.
  8. If a Jellyfish moved onto the Submarine, the player loses.
  9. 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 v and h will 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.
  • v is 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:

  1. Handle the new Gameplay command u [turns], which rewinds the game by [turns] turns.
  2. 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.
  3. 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.
  4. 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 least 1.
  • The Gameplay Phase will never run for more than 256 turns, and [turns] will never be more than 256, so no more than 256 turns 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. v is 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:

  1. Handle the new Setup Phase command c [direction] [row] [col], where [direction] is w, a, s or d:
DirectionEntityArt
wCURRENT_UP^^^
aCURRENT_LEFT<<<
sCURRENT_DOWNvvv
dCURRENT_RIGHT>>>
  1. 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.
  2. Chain the pushes. If the Submarine lands on another current, it is pushed again, up to a maximum of 5 pushes in one turn. After the fifth push the Submarine stops, even if it is still standing on a current.
  3. Stop the chain when a push is blocked. A push into SEAWEED or an EXIT_LOCKED tile does not happen, and no further pushes happen that turn. A CURRENT_UP on row 0 and a CURRENT_DOWN on row ROWS - 1 have nowhere to push to, so they are blocked in the same way.
  4. Sink the Submarine if it is carried into a hazard. If a push moves the Submarine onto a MINE, an ANGLERFISH or a JELLYFISH, 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.
  5. 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 5 exactly like the Submarine.
  6. Rotate every current 90 degrees clockwise every 3 turns:

^^^ -> >>> -> 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 0 and 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

  1. The Submarine moves or rests.
  2. The turn's oxygen is used, based on the row the Submarine moved to.
  3. Currents push the Submarine, up to 5 times. 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.
  4. Collect the Treasure or Air Pocket on the tile the Submarine ended on. If that clears the last Treasure, every Exit unlocks.
  5. If the Submarine is on an EXIT_UNLOCKED tile, the player wins.
  6. If oxygen has reached 0, the player loses.
  7. If the Submarine is on a MINE, a JELLYFISH or an ANGLERFISH, the player loses.
  8. Every Jellyfish moves, and any that swims onto a current is carried.
  9. If a Jellyfish moved or was carried onto the Submarine, the player loses.
  10. Every 3 turns, all currents rotate 90 degrees clockwise.
  11. 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_LEFT on column 0 pushes to column COLS - 1.
  • In Deep Sea mode the turn's oxygen costs [row] + 1 for 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 p prints as Moves. p, m, v and u are not turns and do not advance it.
  • The c command 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, s and d will 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-stage command as shown below.
  • Remember -- give early, and give often. Only your last submission counts, but why not be safe and submit right now?
1511 style cs_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:

  1. Handle the new Gameplay command f [direction], where [direction] is w, a, s or d:
    • The Submarine has 4 torpedoes 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.
  2. Keep the torpedo count up to date. The p command already prints torpedoes remaining; until now it has always shown 4.
  3. Move and launch torpedoes each turn:
    • First, every torpedo already in flight moves 1 tile 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 2 tiles 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.
  4. 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.
TileWhat happens
OCEANThe torpedo travels on.
A currentThe torpedo crosses it as if it were ocean. The current is not destroyed.
TREASURECollected, exactly as if the Submarine had swum over it. The torpedo travels on.
AIR_POCKETCollected, refilling the Submarine's oxygen. The torpedo travels on.
JELLYFISHDestroyed. The tile becomes OCEAN and the torpedo is gone.
ANGLERFISHDestroyed. The tile becomes OCEAN and the torpedo is gone. This includes hidden anglerfish.
MINEDetonated. The tile becomes OCEAN and the torpedo is gone.
SEAWEEDThe torpedo is absorbed. The Seaweed survives.
EXIT_LOCKED / EXIT_UNLOCKEDThe torpedo is absorbed. The Exit survives.
TORPEDOBoth torpedoes are destroyed. The tile becomes OCEAN.
The SubmarineThe player loses.
  1. 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 it TORPEDO.
    • Print the Submarine's information.
    • Exit the program.

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

  1. The Submarine moves, rests, or fires. Firing spends a torpedo, but the torpedo does not launch yet.
  2. The turn's oxygen is used, based on the row the Submarine moved to.
  3. Currents push the Submarine, up to 5 times. 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.
  4. Collect the Treasure or Air Pocket on the tile the Submarine ended on. If that clears the last Treasure, every Exit unlocks.
  5. If the Submarine is on an EXIT_UNLOCKED tile, the player wins.
  6. If oxygen has reached 0, the player loses.
  7. If the Submarine is on a MINE, a JELLYFISH, an ANGLERFISH or a TORPEDO, the player loses.
  8. Every torpedo already in flight advances one tile, then a torpedo fired this turn launches and travels its opening 2 tiles.
  9. If a torpedo moved onto the Submarine, the player loses.
  10. If a torpedo took the last Treasure, unlock every Exit.
  11. Every Jellyfish moves, and any that swims onto a current is carried.
  12. If a Jellyfish moved or was carried onto the Submarine, the player loses.
  13. Every 3 turns, all currents rotate 90 degrees clockwise.
  14. Print the board.

Assumptions / Restrictions / Clarifications

  • All 4 torpedoes 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 TORPEDO is now one of the hazards a current can carry the Submarine onto, exactly as a MINE, an ANGLERFISH or a JELLYFISH is in Stage 3.5.
  • Only the directions w, a, s and d will be tested.
  • v is 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:

  1. Handle the new Setup Phase command S [row] [col] [speed] [script]X, which places a SEEKING_MINE. It draws as {*}.
  2. Read the [script], a run of w, a, s and d characters giving the route the mine drives. The script is terminated by a capital X, which is never a step and never appears anywhere else. Read the script one character at a time until you reach it.
  3. 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 the X it 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-1 mine sits out every round after the first.
    • [speed] is how many characters of the script the mine uses each turn. A mine placed with S 5 2 2 dwX moves one tile right and one tile up on its first turn.
  4. Resolve each step:
TileWhat happens
SEAWEED, EXIT_LOCKED, EXIT_UNLOCKEDThe step is blocked. The mine does not move.
Off the top or bottom of the boardThe step is blocked. The mine does not move.
A currentThe mine drives over it. The current is not destroyed and reappears once the mine moves on.
SEEKING_MINEThe mines pass through each other. Neither is destroyed.
TREASURE, AIR_POCKET, MINE, JELLYFISH, ANGLERFISH, TORPEDODestroyed. The tile becomes OCEAN. Nothing is collected, however if the last Treasure is destroyed, the Exits should unlock.
The SubmarineThe 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.

  1. 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.
  2. 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 it SEEKING_MINE.
    • Print the Submarine's information.
    • Exit the program.

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 S command follows the Stage 1.2 validation rules like every other Setup command.
  • [speed] is at least 1 and at most 64.
  • The script is at most 64 steps long, not counting the terminating X. It may also be empty: S 3 3 1 X places 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 10 Seeking Mines will be placed.
  • The X terminator 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 TORPEDO or a JELLYFISH does, part-way through the ride, with print_loss_message() passed SEEKING_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 add 2, 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-stage command as shown below.
  • Remember -- give early, and give often. Only your last submission counts, but why not be safe and submit right now?
1511 style cs_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%.
No submissions will be accepted after 5 days late, unless you have special provisions in place.

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