Assignment 1 - CS Snake

Overview

Your task is to implement the CS Snake game.

CS Snake is a modified version of the classic Snake game where the player enters commands to move the snake and eat apples on the board. You can play the classic Snake game here (all trademarks are the property of their respective owners).

In this re-imagined version, our snake will elongate its snake body on every move, with its tail fixed at the starting position. The goal of the game is to collect all the apples, unlock the exit, and escape!

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_snake

You should now have a file named cs_snake.c in your ass1 directory.

  1. Check that everything works by running the autotest:
1511 autotest cs_snake

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 Phase: Setup and Gameplay

Setup Phase

When the program starts, the Setup Phase begins, and a new game is created:

  • An empty game board is initialised.
  • Features (walls, exits, apples, etc.) are added to the board.
  • The snake is spawned.

Gameplay Phase

When the Setup Phase is complete, the Gameplay Phase begins. In this phase, the snake:

  • Moves across the board and elongates its body on each move.
  • Eats various types of apples to unlock exits.
  • Escapes after collecting all the apples on the board!

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_snake. 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_snake
w 6 3
e 7 5
a n 2 8
a r 3 1
p ^ 3 8
s
4 5
d
d
d
w
w
a

These inputs will:

  • Add a wall at [6][3], a locked exit at [7][5], a normal apple at [2][8], a reverse apple at [3][1], and an upward facing one-way passage at [3][8].
  • Spawn the player at board position [4][5].
  • Start the game.
  • Move the player around the board.

You don't need to fully understand these inputs yet; they're only provided as a preview.

Starter Code and Data Structures

Starter code has been provided to help you get up and running. It contains a range of useful constants, structs, enums, and functions.

If you haven't done so already, test the 1511 cs_snake reference solution, then open the provided cs_snake.c and follow along with this introduction.

The main() Function

A sample main() function has been provided to get you started.

int main(void) {
    printf("Welcome to CS Snake!\n\n");

    struct tile board[ROWS][COLS];
    initialise_board(board);

    print_board(board, NO_SNAKE, NO_SNAKE);

    return 0;
}

Printing a Welcome Message

The first statement prints a welcome message followed by a blank line:

printf("Welcome to CS Snake!\n\n");

Declaring the board Array

The next statement declares the game board.

struct tile board[ROWS][COLS];

This means that board is a two-dimensional ROWS-by-COLS array, where each element is a struct tile.

struct tile {
    enum entity entity;
};

Each struct tile currently contains one field, an enum entity. This allows each element of the board array to store a game feature (e.g. a wall, apple, exit, body segment, etc.).

enum entity {
    BODY_SEGMENT,
    EXIT_LOCKED,
    EXIT_UNLOCKED,
    WALL,
    APPLE_NORMAL,
    APPLE_REVERSE,
    APPLE_SPLIT,
    APPLE_EXPLODE,
    EXPLOSION,
    PASSAGE_UP,
    PASSAGE_DOWN,
    PASSAGE_LEFT,
    PASSAGE_RIGHT,
    PORTAL,
    EMPTY
};

Each entity corresponds to a feature and a symbol that appears when the board is printed to the terminal:

 Entity Feature Symbol
EMPTY Empty    
WALL Wall |||
BODY_SEGMENT Body Segment ###
EXIT_LOCKED Locked Exit [X]
EXIT_UNLOCKED Unlocked Exit [ ]
APPLE_NORMAL Normal Apple (`)
APPLE_REVERSE Reverse Apple (R)
APPLE_SPLIT Split Apple (S)
PASSAGE_UP Up Passage ^^^
PASSAGE_DOWN Down Passage vvv
PASSAGE_LEFT Left Passage <<<
PASSAGE_RIGHT Right Passage >>>
PORTAL Portal ~O~
EXPLOSION Explosion ***
Note: APPLE_EXPLODE is not provided in the print_board() function as you will need to modify the function yourself to handle printing this entity in Stage 4.1.

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.

Initialising the board Array

At this point, we have a board array, but it hasn't been initialised with any values. The next statement passes the newly-declared board array to the provided initialise_board() function. This gives every tile entity an initial value of EMPTY:

initialise_board(board);

Printing the Game

Before exiting, main() prints the board in the terminal:

Welcome to CS Snake!

+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +

It does this with the provided print_board() function.

print_board(board, NO_SNAKE, NO_SNAKE);

The print_board() function takes the following arguments:

  1. The board array.
  2. The row position of the snake. Since the snake has not yet been placed on the board, we use the #defined constant NO_SNAKE.
  3. The column position of the snake. Since the ninja has not yet been placed on the board, we use the #defined constant NO_SNAKE.

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 snake at row 2, column 9.
  • print_board(board, 0, 5) displays the board with the snake 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

There are five more provided functions:

  • print_board_line() is a helper function called by print_board(). You will not need to use it in your code.
  • print_board_header() is a helper function called by print_board(). You will not need to use it in your code.
  • print_tile_spacer() is a helper function called by print_board(). You will not need to use it in your code.
  • print_board_statistics() is a helper function provided to help you complete Stage 2.3.
  • print_board_statistics_with_rival() is a helper function provided to help you complete Stage 4.2.

FAQ

Q: Can I edit the provided code?

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

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

For example: you may wish to add fields to the provided struct tile definition.

You are also encouraged to create your own constants, enums, structs, and helper functions.

Q: Can I use pointers?

Yes! You can use pointers, although, they're not required. It's possible to complete every stage of the assignment without using pointers.

Q: Can I use X other C feature?

For everything not taught in the course, check the Style Guide:

  • If the guide says "avoid", it may incur a style mark penalty if not used correctly.
  • If the guide says "illegal" or "do not use", it will result in a style mark penalty (see the Style Marking Rubric).

These rules exist to ensure that everyone develops the required foundational knowledge and to maintain a level playing field for all students.

Stages

The assignment has been divided into incremental stages.

Stage 1: Setup Phase

  • Stage 1.1 - Basic Setup Loop.
  • Stage 1.2 - Error Checking.
  • Stage 1.3 - Adding Long Walls.
  • Stage 1.4 - Spawn Snake.

Stage 2: Gameplay Phase (Snake Turn)

  • Stage 2.1 - Basic Slithering.
  • Stage 2.2 - Eating Apples and Unlocking Exits.
  • Stage 2.3 - Points and Statistics.
  • Stage 2.4 - Winning and Losing.

Stage 3: Gameplay Phase (Snake Turn + Extra Mechanics)

  • Stage 3.1 - Snake Reverse.
  • Stage 3.2 - One-Way Passage.
  • Stage 3.3 - Snake Split.
  • Stage 3.4 - Reset.
  • Stage 3.5 - Portals.

Stage 4: Gameplay Phase (Extra Mechanics)

  • Stage 4.1 - Exploding Apples.
  • Stage 4.2 - Ready Player 2.

Extension (not for marks)

  • SplashKit - Create and Share a Graphical User Interface.

Your Tasks

This assignment consists of four stages. Each stage builds on the work of the previous stage, and each stage has a higher complexity than its predecessor. You should complete the stages in order.

A video explanation to help you get started with the assignment can be found here:

Stage 1

In Stage 1, you will implement the Setup Phase of CS Snake. This stage has been divided into four substages:

  • Stage 1.1 - Basic Setup Loop.
  • Stage 1.2 - Error Checking.
  • Stage 1.3 - Adding Long Walls.
  • Stage 1.4 - Spawn Snake.

Stage 1.1 - Basic Setup Loop

The first step of the Setup Phase is to add features to our game. By the end of this substage your program will prompt the user to add features, add them to the game board and then display this.

The starter code:

  • Prints a welcome message to CS Snake.
  • Declares the board array.
  • Initialises the board by setting every tile’s entity to be EMPTY.
  • Prints the board without showing the snake.

A description of the starter code can be found in Starter Code and Data Structures.

Task

In this substage, you will modify the starter code to:

  1. Prompt the user by printing: "--- Map Setup ---\n".
  2. Implement a Setup Loop to repeatedly read-in commands and add features to the board until the stop command s is entered:
    1. Given the command w [row] [col], add a WALL to the tile at [row] [col].
    2. Given the command e [row] [col], add an EXIT_LOCKED to the tile at [row] [col].
    3. Given the command a n [row] [col], add an APPLE_NORMAL to the tile at [row] [col].
  3. When the user enters s:
    1. End the Setup Loop.
    2. Display the board with the provided print_board() function without showing the snake.
    3. At this point, the program should end.

Assumptions / Restrictions / Clarifications

When your code is tested in this substage:

  • Your program should ignore commands other than w, e, or a n.
  • All features will be placed within the map boundaries (until Stage 1.2).
  • No feature will be placed at the same location as another feature (until Stage 1.2).

For this substage and all future substages:

  • The row and col entered will always be integers.
  • Incomplete commands will not be tested e.g. when a w is entered, it will always be followed by a [row] and [col] value.

Examples

Input:

s

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +

Input:

w 0 0
w 1 5
w 6 3
w 4 2
s

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
w 0 0
w 1 5
w 6 3
w 4 2
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 |||                                    
+   +   +   +   +   +   +   +   +   +   +
                     |||                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         |||                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             |||                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +

Input:

e 1 4
e 5 3
e 8 2
s

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
e 1 4
e 5 3
e 8 2
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 [X]                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             [X]                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         [X]                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +

Input:

a n 1 4
a n 3 8
a n 6 3
s

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
a n 1 4
a n 3 8
a n 6 3
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 (`)                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                 (`)    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             (`)                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +

Autotest

Stage 1.2 - Error Checking

In Stage 1.1, we didn’t check whether the given values were outside the bounds of our board. Currently, our cs_snake.c program will crash in these cases, so let’s fix that now!

Task

In this substage, you will need to modify your setup loop to ensure that features are only added to valid locations.

Errors

  1. If the user attempts to place a feature in a position that’s not on the board:
    • Print "ERROR: Invalid position, [row] [col] is out of bounds!\n".
    • Continue reading the next command.
  2. If the user attempts to place a feature on an occupied tile:
    • Print "ERROR: Invalid tile, [row] [col] is occupied!\n".
    • Continue reading the next command.

Assumptions / Restrictions / Clarifications

  • A tile is considered occupied if it contains any other entity value besides EMPTY.
  • Error handling must follow the specified priority. For each command, identify and print only the first error, in the above order, if any.
  • If an error is encountered, the command should not modify the board in any way.

Examples

Input:

w 10 0
a n 5 10
e -1 3
w 9 -1
s

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
w 10 0
ERROR: Invalid position, 10 0 is out of bounds!
a n 5 10
ERROR: Invalid position, 5 10 is out of bounds!
e -1 3
ERROR: Invalid position, -1 3 is out of bounds!
w 9 -1
ERROR: Invalid position, 9 -1 is out of bounds!
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +

Input:

w 5 4
a n 5 4
e 2 8
e 3 6
w 3 6
s

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
w 5 4
a n 5 4
ERROR: Invalid tile, 5 4 is occupied!
e 2 8
e 3 6
w 3 6
ERROR: Invalid tile, 3 6 is occupied!
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                 [X]    
+   +   +   +   +   +   +   +   +   +   +
                         [X]            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 |||                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +

Autotest

Stage 1.3 - Adding Long Walls

Task

In this substage, you will implement a command to add WALL tiles to the board as one continuous row or column.

You will need to:

Modify your Setup Loop from Stage 1.1 to handle a new W command:

W [direction] [row] [col] [length]

This command specifies the:

  • Direction of the wall, h for horizontal and v for vertical.
  • Start position of the wall at [row], [col].
  • Length of the wall with [length].

After reading this command, your program should add WALL to every tile from the start position with the specified length in the specified direction.

Errors

When adding the long wall, if any of the following conditions are met, the long wall should not be added, and the corresponding error message should be printed out instead:

  1. If the user attempts to place a long wall where the starting position is out of bounds:
    • Print "ERROR: Invalid position, [row] [col] is out of bounds!\n".
    • Continue reading the next command.
  2. If the user attempts to place a long wall where any part of the wall is out of bounds:
    • Print "ERROR: Invalid position, part of the wall is out of bounds!\n".
    • Continue reading the next command.
  3. If the user attempts to place a long wall where any part of the wall is occupied by another tile:
    • Print "ERROR: Invalid tile, part of the wall is occupied!\n".
    • Continue reading the next command.

Assumptions / Restrictions / Clarifications

  • The direction entered will only be h or v.
  • The row and col entered will always be integers.
  • The length entered will always be an integer and will be greater than 0.
  • Horizontal walls increment towards the right.
  • Vertical walls increment towards the bottom.
  • Error handling must follow the specified priority. Identify and print only the first error, in the above order, if any.
  • If an error is encountered, the command should not modify the board in any way.

Examples

Input:

W h 3 2 2
W h 3 6 2
W h 6 2 1
W h 6 7 1
W h 7 3 4
s

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
W h 3 2 2
W h 3 6 2
W h 6 2 1
W h 6 7 1
W h 7 3 4
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ||| |||         ||| |||        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         |||                 |||        
+   +   +   +   +   +   +   +   +   +   +
             ||| ||| ||| |||            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +

Input:

W v 0 0 10
W v 1 2 8
W v 2 4 6
W v 3 6 4
W v 4 8 2
s

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
W v 0 0 10
W v 1 2 8
W v 2 4 6
W v 3 6 4
W v 4 8 2
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 |||                                    
+   +   +   +   +   +   +   +   +   +   +
 |||     |||                            
+   +   +   +   +   +   +   +   +   +   +
 |||     |||     |||                    
+   +   +   +   +   +   +   +   +   +   +
 |||     |||     |||     |||            
+   +   +   +   +   +   +   +   +   +   +
 |||     |||     |||     |||     |||    
+   +   +   +   +   +   +   +   +   +   +
 |||     |||     |||     |||     |||    
+   +   +   +   +   +   +   +   +   +   +
 |||     |||     |||     |||            
+   +   +   +   +   +   +   +   +   +   +
 |||     |||     |||                    
+   +   +   +   +   +   +   +   +   +   +
 |||     |||                            
+   +   +   +   +   +   +   +   +   +   +
 |||                                    
+   +   +   +   +   +   +   +   +   +   +

Input:

W v -1 0 1
W v 0 -9 2
W v 1 10 2
W h 5 99 5
W h 10 1 10
W h 1 10 2
s

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
W v -1 0 1
ERROR: Invalid position, -1 0 is out of bounds!
W v 0 -9 2
ERROR: Invalid position, 0 -9 is out of bounds!
W v 1 10 2
ERROR: Invalid position, 1 10 is out of bounds!
W h 5 99 5
ERROR: Invalid position, 5 99 is out of bounds!
W h 10 1 10
ERROR: Invalid position, 10 1 is out of bounds!
W h 1 10 2
ERROR: Invalid position, 1 10 is out of bounds!
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +

Input:

W v 0 0 11
W v 5 4 6
W v 9 9 2
W h 5 5 6
W h 0 0 11
W h 2 3 99
s

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
W v 0 0 11
ERROR: Invalid position, part of the wall is out of bounds!
W v 5 4 6
ERROR: Invalid position, part of the wall is out of bounds!
W v 9 9 2
ERROR: Invalid position, part of the wall is out of bounds!
W h 5 5 6
ERROR: Invalid position, part of the wall is out of bounds!
W h 0 0 11
ERROR: Invalid position, part of the wall is out of bounds!
W h 2 3 99
ERROR: Invalid position, part of the wall is out of bounds!
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +

Input:

e 6 7
a n 4 4
W v 5 7 3
W h 6 7 1
W h 4 1 7
s

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
e 6 7
a n 4 4
W v 5 7 3
ERROR: Invalid tile, part of the wall is occupied!
W h 6 7 1
ERROR: Invalid tile, part of the wall is occupied!
W h 4 1 7
ERROR: Invalid tile, part of the wall is occupied!
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 (`)                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                             [X]        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +

Autotest

Stage 1.4 - Spawn Snake

We will now spawn the snake onto the board!

Task

In this substage, we will add a Snake Spawning Loop after the Setup Loop is complete. You will need to make this spawning loop:

  1. Print the header: "--- Spawning Snake ---\n".
  2. Prompt the user by printing: "Enter the snake's starting position: ".
  3. Add a new loop to accept integer inputs in the format [row] [col] until a valid starting position is entered.
  4. If the position entered is invalid (i.e. if the position is out of bounds, or is already occupied):
    • Print the appropriate error message specified in Stage 1.2.
    • Prompt the user for another starting position by printing "Enter the snake's starting position: ".
  5. Otherwise, if the position entered is valid:
    • End the loop.
    • Use the provided print_board() function to display the board with the snake.
    • At this point, the program should end.

Assumptions / Restrictions / Clarifications

  • The row and col entered will always be integers.
  • You can assume that there is always at least one valid position to place the snake after the Setup Phase.

Examples

Input:

s
0 0

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 0 0
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 ^~^                                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +

Input:

w 5 5
a n 2 3
e 1 4
s
-1 -1
10 5
5 5
2 3
6 7

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
w 5 5
a n 2 3
e 1 4
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 [X]                    
+   +   +   +   +   +   +   +   +   +   +
             (`)                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     |||                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: -1 -1
ERROR: Invalid position, -1 -1 is out of bounds!
Enter the snake's starting position: 10 5
ERROR: Invalid position, 10 5 is out of bounds!
Enter the snake's starting position: 5 5
ERROR: Invalid tile, 5 5 is occupied!
Enter the snake's starting position: 2 3
ERROR: Invalid tile, 2 3 is occupied!
Enter the snake's starting position: 6 7
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 [X]                    
+   +   +   +   +   +   +   +   +   +   +
             (`)                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     |||                
+   +   +   +   +   +   +   +   +   +   +
                             ^~^        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +

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_snake.c
1511 autotest-stage 01 cs_snake
give cs1511 ass1_cs_snake cs_snake.c

Stage 2

In Stage 2, you will begin implementing the Gameplay Phase of CS Snake. This stage has been divided into four substages:

  • Stage 2.1 - Basic Slithering.
  • Stage 2.2 - Eating Apples and Unlocking Exits.
  • Stage 2.3 - Points and Statistics.
  • Stage 2.4 - Winning and Losing.

Stage 2.1: Basic Slithering

Wakey Wakey, Eggs and Snakey!

The first step of the Gameplay Phase is to introduce snake movement. By the end of this substage, your program will allow the user to control our snake and move around the map.

Task

In this substage, you will need to:

  1. Start the Gameplay Phase by printing "--- Gameplay Phase ---\n".

    This indicates that the Setup Phase is complete, and the user can start playing cs_snake.

  2. Implement a Gameplay Loop that:

    • Repeatedly reads in and handles user commands (this is the Snake Turn).
    • When Ctrl+D is entered by the user, immediately:
      1. Prints "--- Quitting Game ---\n".
      2. Exits without any other outputs.
  3. Implement the first set of Gameplay Loop commands, which will be used for controlling snake movement:

    • When the user enters one of these commands below, move the snake one tile in the corresponding direction.

      • w moves the snake up.
      • a moves the snake left.
      • s moves the snake down.
      • d moves the snake right.
    • When the snake moves, its tail remains fixed at its original spawning position, causing the snake to elongate by adding new body segments behind the head without moving the tail forward. You will need to replace the entity value of the snake’s previous head position with BODY_SEGMENT as the snake moves.

  4. End each Snake Turn by displaying the board with the provided print_board() function. This completes the turn.

Reminder: this is a Gameplay Loop. After each command is scanned and handled, the program should continue to read and handle the next user command until Ctrl+D is entered.

Assumptions / Restrictions / Clarifications

  • The "tail" of the snake is simply a BODY_SEGMENT entity.
  • As per the assumptions at the top of the page, you can assume your program will never be given a non-existent Gameplay Loop command.

When your code is tested in this substage:

  • No movement command will attempt to move the snake onto a consumable feature (apples) on the map (until Stage 2.2).
  • No movement command will attempt to move the snake onto an exit, wall, or onto the snake itself (until Stage 2.4).
  • No movement command will attempt to move the snake off the board (until Stage 2.4).

Examples

Input:

s
5 6
w
w
a
a
a
s
s
d
[CTRL+D]

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 5 6
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                         ^~^            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
w
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                         ^~^            
+   +   +   +   +   +   +   +   +   +   +
                         ###            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
w
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                         ^~^            
+   +   +   +   +   +   +   +   +   +   +
                         ###            
+   +   +   +   +   +   +   +   +   +   +
                         ###            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
a
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     ^~^ ###            
+   +   +   +   +   +   +   +   +   +   +
                         ###            
+   +   +   +   +   +   +   +   +   +   +
                         ###            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
a
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ^~^ ### ###            
+   +   +   +   +   +   +   +   +   +   +
                         ###            
+   +   +   +   +   +   +   +   +   +   +
                         ###            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
a
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             ^~^ ### ### ###            
+   +   +   +   +   +   +   +   +   +   +
                         ###            
+   +   +   +   +   +   +   +   +   +   +
                         ###            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             ### ### ### ###            
+   +   +   +   +   +   +   +   +   +   +
             ^~^         ###            
+   +   +   +   +   +   +   +   +   +   +
                         ###            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             ### ### ### ###            
+   +   +   +   +   +   +   +   +   +   +
             ###         ###            
+   +   +   +   +   +   +   +   +   +   +
             ^~^         ###            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             ### ### ### ###            
+   +   +   +   +   +   +   +   +   +   +
             ###         ###            
+   +   +   +   +   +   +   +   +   +   +
             ### ^~^     ###            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
[CTRL+D]
--- Quitting Game ---

Input:

s
1 1
s
d
s
d
d
w
d
d
s
s
s
s
[CTRL+D]

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 1 1
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ^~^                                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ###                                
+   +   +   +   +   +   +   +   +   +   +
     ^~^                                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ###                                
+   +   +   +   +   +   +   +   +   +   +
     ### ^~^                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ###                                
+   +   +   +   +   +   +   +   +   +   +
     ### ###                            
+   +   +   +   +   +   +   +   +   +   +
         ^~^                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ###                                
+   +   +   +   +   +   +   +   +   +   +
     ### ###                            
+   +   +   +   +   +   +   +   +   +   +
         ### ^~^                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ###                                
+   +   +   +   +   +   +   +   +   +   +
     ### ###                            
+   +   +   +   +   +   +   +   +   +   +
         ### ### ^~^                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
w
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ###                                
+   +   +   +   +   +   +   +   +   +   +
     ### ###     ^~^                    
+   +   +   +   +   +   +   +   +   +   +
         ### ### ###                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ###                                
+   +   +   +   +   +   +   +   +   +   +
     ### ###     ### ^~^                
+   +   +   +   +   +   +   +   +   +   +
         ### ### ###                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ###                                
+   +   +   +   +   +   +   +   +   +   +
     ### ###     ### ### ^~^            
+   +   +   +   +   +   +   +   +   +   +
         ### ### ###                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ###                                
+   +   +   +   +   +   +   +   +   +   +
     ### ###     ### ### ###            
+   +   +   +   +   +   +   +   +   +   +
         ### ### ###     ^~^            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ###                                
+   +   +   +   +   +   +   +   +   +   +
     ### ###     ### ### ###            
+   +   +   +   +   +   +   +   +   +   +
         ### ### ###     ###            
+   +   +   +   +   +   +   +   +   +   +
                         ^~^            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ###                                
+   +   +   +   +   +   +   +   +   +   +
     ### ###     ### ### ###            
+   +   +   +   +   +   +   +   +   +   +
         ### ### ###     ###            
+   +   +   +   +   +   +   +   +   +   +
                         ###            
+   +   +   +   +   +   +   +   +   +   +
                         ^~^            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ###                                
+   +   +   +   +   +   +   +   +   +   +
     ### ###     ### ### ###            
+   +   +   +   +   +   +   +   +   +   +
         ### ### ###     ###            
+   +   +   +   +   +   +   +   +   +   +
                         ###            
+   +   +   +   +   +   +   +   +   +   +
                         ###            
+   +   +   +   +   +   +   +   +   +   +
                         ^~^            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
[CTRL+D]
--- Quitting Game ---

Input:

s
0 0
[CTRL+D]

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 0 0
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 ^~^                                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
[CTRL+D]
--- Quitting Game ---

Autotest

Stage 2.2: Eating Apples and Unlocking Exits

Our snake is gluttonous and hungry! It wants to eat all the apples it can before escaping the map.

Task

In this substage, you will need to:

  1. Modify your Snake Movement mechanic to allow for apple consumption.
    • When the snake moves onto a normal apple, it will consume the apple, removing it from the board by setting the tile entity to EMPTY.
  2. Update every EXIT_LOCKED tile to be EXIT_UNLOCKED if all apples on the board have been consumed and removed. Note that this check should happen at the end of every Snake Turn before the board is printed.

Assumptions / Restrictions / Clarifications

  • If there are no apples to start with, all exits should be unlocked at the end of the first Snake Turn.

When your code is tested in this substage:

  • No movement command will attempt to move the snake onto either a locked or unlocked exit, a wall, or onto the snake itself (until Stage 2.4).
  • No movement command will attempt to move the snake off the board (until Stage 2.4).

Examples

Input:

a n 1 1
a n 3 2
e 4 5
s
0 0
s
d
s
d
s
[CTRL+D]

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
a n 1 1
a n 3 2
e 4 5
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     (`)                                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         (`)                            
+   +   +   +   +   +   +   +   +   +   +
                     [X]                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 0 0
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 ^~^                                    
+   +   +   +   +   +   +   +   +   +   +
     (`)                                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         (`)                            
+   +   +   +   +   +   +   +   +   +   +
                     [X]                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ^~^ (`)                                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         (`)                            
+   +   +   +   +   +   +   +   +   +   +
                     [X]                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ### ^~^                                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         (`)                            
+   +   +   +   +   +   +   +   +   +   +
                     [X]                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ### ###                                
+   +   +   +   +   +   +   +   +   +   +
     ^~^                                
+   +   +   +   +   +   +   +   +   +   +
         (`)                            
+   +   +   +   +   +   +   +   +   +   +
                     [X]                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ### ###                                
+   +   +   +   +   +   +   +   +   +   +
     ### ^~^                            
+   +   +   +   +   +   +   +   +   +   +
         (`)                            
+   +   +   +   +   +   +   +   +   +   +
                     [X]                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ### ###                                
+   +   +   +   +   +   +   +   +   +   +
     ### ###                            
+   +   +   +   +   +   +   +   +   +   +
         ^~^                            
+   +   +   +   +   +   +   +   +   +   +
                     [ ]                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
[CTRL+D]
--- Quitting Game ---

Input:

e 5 5
s
0 0
s
[CTRL+D]

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
e 5 5
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     [X]                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 0 0
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 ^~^                                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     [X]                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ^~^                                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     [ ]                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
[CTRL+D]
--- Quitting Game ---

Input:

e 3 6
e 4 2
e 7 5
a n 1 1
s
0 0
s
d
[CTRL+D]

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
e 3 6
e 4 2
e 7 5
a n 1 1
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     (`)                                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                         [X]            
+   +   +   +   +   +   +   +   +   +   +
         [X]                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     [X]                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 0 0
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 ^~^                                    
+   +   +   +   +   +   +   +   +   +   +
     (`)                                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                         [X]            
+   +   +   +   +   +   +   +   +   +   +
         [X]                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     [X]                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ^~^ (`)                                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                         [X]            
+   +   +   +   +   +   +   +   +   +   +
         [X]                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     [X]                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ### ^~^                                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                         [ ]            
+   +   +   +   +   +   +   +   +   +   +
         [ ]                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     [ ]                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
[CTRL+D]
--- Quitting Game ---

Autotest

Stage 2.3: Points and Statistics

Pointsss to earn, ssscores to beat, and statissstics to see?

"Fang-tastic," hisses our snake.

Task

In this substage, you will need to:

  1. Keep track of points:
    • The snake starts the game with 0 points.
    • If the snake eats a normal apple, add 5 points to the snake’s score.
  2. Modify the Gameplay Loop to handle a new p command that prints statistics about the game. When the p command is entered, your program will need to calculate and print:
    • The total points collected by the snake so far.

    • The total number of moves made by the snake so far.

    • The total number of apples eaten by the snake so far.

    • The total number of apples remaining.

    • The "apple completion" percentage. This is the proportion of eaten apples to the total number of apples initially placed on the board. It is defined by the following formula:

      completion_percentage = 100.0 * num_eaten / num_initial_apples.

    • The number of points remaining. This is the total number of points that can still be scored by the snake before the exit(s) is unlocked.

You should call the provided helper function print_game_statistics() to display this information to the snake.

// Prints statistics about the game
void print_game_statistics(
    int points,
    int moves_made,
    int num_apples_eaten,
    int num_apples_remaining,
    double completion_percentage,
    int maximum_points_remaining
) {
    printf("============ Game Statistics ============\n");
    printf("Totals:\n");
    printf("  - Points: %d\n", points);
    printf("  - Moves Made: %d\n", moves_made);
    printf("  - Number of Apples Eaten: %d\n", num_apples_eaten);
    printf("Completion:\n");
    printf("  - Number of Apples Remaining: %d\n", num_apples_remaining);
    printf("  - Apple Completion Percentage: %.1f%%\n", completion_percentage);
    printf("  - Maximum Points Remaining: %d\n", maximum_points_remaining);
    printf("=========================================\n");
}

Assumptions / Restrictions / Clarifications

  • If there are no apples to start with, the completion percentage is by default 100%.
  • Only snake movement is counted towards the total number of "moves made". This includes movements that cause the snake’s death (implemented in Stage 2.4).

Examples

Input:

s
1 1
p
d
p
s
s
p
[CTRL+D]

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 1 1
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ^~^                                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
p
============ Game Statistics ============
Totals:
  - Points: 0
  - Moves Made: 0
  - Number of Apples Eaten: 0
Completion:
  - Number of Apples Remaining: 0
  - Apple Completion Percentage: 100.0%
  - Maximum Points Remaining: 0
=========================================
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ### ^~^                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
p
============ Game Statistics ============
Totals:
  - Points: 0
  - Moves Made: 1
  - Number of Apples Eaten: 0
Completion:
  - Number of Apples Remaining: 0
  - Apple Completion Percentage: 100.0%
  - Maximum Points Remaining: 0
=========================================
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ### ###                            
+   +   +   +   +   +   +   +   +   +   +
         ^~^                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ### ###                            
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ^~^                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
p
============ Game Statistics ============
Totals:
  - Points: 0
  - Moves Made: 3
  - Number of Apples Eaten: 0
Completion:
  - Number of Apples Remaining: 0
  - Apple Completion Percentage: 100.0%
  - Maximum Points Remaining: 0
=========================================
[CTRL+D]
--- Quitting Game ---

Input:

a n 1 1
a n 1 2
a n 2 3
s
0 0
p
s
d
p
d
p
s
d
p
[CTRL+D]

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
a n 1 1
a n 1 2
a n 2 3
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     (`) (`)                            
+   +   +   +   +   +   +   +   +   +   +
             (`)                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 0 0
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 ^~^                                    
+   +   +   +   +   +   +   +   +   +   +
     (`) (`)                            
+   +   +   +   +   +   +   +   +   +   +
             (`)                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
p
============ Game Statistics ============
Totals:
  - Points: 0
  - Moves Made: 0
  - Number of Apples Eaten: 0
Completion:
  - Number of Apples Remaining: 3
  - Apple Completion Percentage: 0.0%
  - Maximum Points Remaining: 15
=========================================
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ^~^ (`) (`)                            
+   +   +   +   +   +   +   +   +   +   +
             (`)                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ### ^~^ (`)                            
+   +   +   +   +   +   +   +   +   +   +
             (`)                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
p
============ Game Statistics ============
Totals:
  - Points: 5
  - Moves Made: 2
  - Number of Apples Eaten: 1
Completion:
  - Number of Apples Remaining: 2
  - Apple Completion Percentage: 33.3%
  - Maximum Points Remaining: 10
=========================================
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ### ### ^~^                            
+   +   +   +   +   +   +   +   +   +   +
             (`)                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
p
============ Game Statistics ============
Totals:
  - Points: 10
  - Moves Made: 3
  - Number of Apples Eaten: 2
Completion:
  - Number of Apples Remaining: 1
  - Apple Completion Percentage: 66.7%
  - Maximum Points Remaining: 5
=========================================
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ### ### ###                            
+   +   +   +   +   +   +   +   +   +   +
         ^~^ (`)                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ### ### ###                            
+   +   +   +   +   +   +   +   +   +   +
         ### ^~^                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
p
============ Game Statistics ============
Totals:
  - Points: 15
  - Moves Made: 5
  - Number of Apples Eaten: 3
Completion:
  - Number of Apples Remaining: 0
  - Apple Completion Percentage: 100.0%
  - Maximum Points Remaining: 0
=========================================
[CTRL+D]
--- Quitting Game ---

Input:

s
0 0
p
[CTRL+D]

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 0 0
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 ^~^                                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
p
============ Game Statistics ============
Totals:
  - Points: 0
  - Moves Made: 0
  - Number of Apples Eaten: 0
Completion:
  - Number of Apples Remaining: 0
  - Apple Completion Percentage: 100.0%
  - Maximum Points Remaining: 0
=========================================
[CTRL+D]
--- Quitting Game ---

Autotest

Stage 2.4: Winning and Losing

Our snake has eaten all the apples and found the exit!

Or it's crashed into something and fainted…

Task

In this substage, you will need to:

  • Handle when the snake wins.
    1. The snake wins when it moves onto an unlocked exit.
    2. Print "--- Game Over ---\n".
    3. Print "Ssslithered out with a full stomach!\n"
    4. Print board statistics, as per Stage 2.3.
    5. End the program.
  • Handle when the snake loses.
    1. The snake loses when it:
      • Moves onto a non-consumable entity, i.e. its own BODY_SEGMENT, an EXIT_LOCKED, or a WALL.
      • Moves off the map, i.e. out of the boundaries of the board.
    2. Print "--- Game Over ---\n".
    3. Print "Guessss I was the prey today.\n".
    4. Print board statistics, as per Stage 2.3.
    5. End the program.

Assumptions / Restrictions / Clarifications

  • Make sure that the last state of the map gets printed out before declaring the win or loss.
  • Your program should not print "--- Quitting Game ---\n" if the game concludes with a win or loss. It should only be printed if the user enters Ctrl+D before the game has ended.
    • Board statistics should not be printed when the user quits using Ctrl+D.

Examples

Input:

a n 1 1
e 2 2
s
0 0
s
d
s
d

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
a n 1 1
e 2 2
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     (`)                                
+   +   +   +   +   +   +   +   +   +   +
         [X]                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 0 0
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 ^~^                                    
+   +   +   +   +   +   +   +   +   +   +
     (`)                                
+   +   +   +   +   +   +   +   +   +   +
         [X]                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ^~^ (`)                                
+   +   +   +   +   +   +   +   +   +   +
         [X]                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ### ^~^                                
+   +   +   +   +   +   +   +   +   +   +
         [ ]                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ### ###                                
+   +   +   +   +   +   +   +   +   +   +
     ^~^ [ ]                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ### ###                                
+   +   +   +   +   +   +   +   +   +   +
     ### ^~^                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Game Over ---
Ssslithered out with a full stomach!
============ Game Statistics ============
Totals:
  - Points: 5
  - Moves Made: 4
  - Number of Apples Eaten: 1
Completion:
  - Number of Apples Remaining: 0
  - Apple Completion Percentage: 100.0%
  - Maximum Points Remaining: 0
=========================================

Input:

w 5 5
s
5 3
d
d

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
w 5 5
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     |||                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 5 3
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             ^~^     |||                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             ### ^~^ |||                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             ### ### ^~^                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Game Over ---
Guessss I was the prey today.
============ Game Statistics ============
Totals:
  - Points: 0
  - Moves Made: 2
  - Number of Apples Eaten: 0
Completion:
  - Number of Apples Remaining: 0
  - Apple Completion Percentage: 100.0%
  - Maximum Points Remaining: 0
=========================================

Autotest

Testing & Submission

Are you finished with this stage? If so, you should make sure to do the following:

  • Run 1511 style, and clean up any issues a human may have reading your code. Don't forget -- 20% of your mark in the assignment is based on style!
  • Autotest for this stage of the assignment by running the autotest-stage command as shown below.
  • Remember -- give early, and give often. Only your last submission counts, but why not be safe and submit right now?
1511 style cs_snake.c
1511 autotest-stage 02 cs_snake
give cs1511 ass1_cs_snake cs_snake.c

Stage 3

In Stage 3, you will continue implementing the Gameplay Phase of CS Snake. This stage has been divided into four substages:

  • Stage 3.1 - Snake Reverse.
  • Stage 3.2 - One-Way Passage.
  • Stage 3.3 - Snake Split.
  • Stage 3.4 - Reset.
  • Stage 3.5 - Portals.

By the end of this stage, you will have brought the core features of CS Snake to life, allowing it to slither on its own while still leaving room for additional features!

Stage 3.1 - Snake Reverse

Our snake is hungry for more! Shall we prepare a different flavour of apple to satiate its appetite?

Task

In this substage, you will need to:

  1. Modify your Setup Loop to handle the command a r [row] [col], which adds an APPLE_REVERSE entity to the tile at [row] [col].
  2. Modify the apple consumption mechanic (from Stage 2.2) so that when the snake consumes the Reverse Apple:
    1. The snake’s head and tail swap position - i.e. it reverses in direction.
    2. 10 points are added to the snake’s score.

Errors

For this new command, you should follow the input error handling cases and order described in Stage 1.2.

Assumptions / Restrictions / Clarifications

  • The row and col entered will always be integers.

Examples

Input:

a r 5 7
s
2 4
s
s
d
s
d
d
[CTRL+D]

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
a r 5 7
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                             (R)        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 2 4
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ^~^                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                             (R)        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ###                    
+   +   +   +   +   +   +   +   +   +   +
                 ^~^                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                             (R)        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ###                    
+   +   +   +   +   +   +   +   +   +   +
                 ###                    
+   +   +   +   +   +   +   +   +   +   +
                 ^~^                    
+   +   +   +   +   +   +   +   +   +   +
                             (R)        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ###                    
+   +   +   +   +   +   +   +   +   +   +
                 ###                    
+   +   +   +   +   +   +   +   +   +   +
                 ### ^~^                
+   +   +   +   +   +   +   +   +   +   +
                             (R)        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ###                    
+   +   +   +   +   +   +   +   +   +   +
                 ###                    
+   +   +   +   +   +   +   +   +   +   +
                 ### ###                
+   +   +   +   +   +   +   +   +   +   +
                     ^~^     (R)        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ###                    
+   +   +   +   +   +   +   +   +   +   +
                 ###                    
+   +   +   +   +   +   +   +   +   +   +
                 ### ###                
+   +   +   +   +   +   +   +   +   +   +
                     ### ^~^ (R)        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ^~^                    
+   +   +   +   +   +   +   +   +   +   +
                 ###                    
+   +   +   +   +   +   +   +   +   +   +
                 ### ###                
+   +   +   +   +   +   +   +   +   +   +
                     ### ### ###        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
[CTRL+D]
--- Quitting Game ---

Input:

a r 3 4
a r 1 2
s
2 2
s
d
d
w
[CTRL+D]

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
a r 3 4
a r 1 2
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         (R)                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 (R)                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 2 2
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         (R)                            
+   +   +   +   +   +   +   +   +   +   +
         ^~^                            
+   +   +   +   +   +   +   +   +   +   +
                 (R)                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         (R)                            
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ^~^     (R)                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         (R)                            
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ### ^~^ (R)                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         (R)                            
+   +   +   +   +   +   +   +   +   +   +
         ^~^                            
+   +   +   +   +   +   +   +   +   +   +
         ### ### ###                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
w
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ### ### ^~^                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
[CTRL+D]
--- Quitting Game ---

Input:

a r 4 5
a r 4 2
s
4 4
p
d
p
a
a
p
[CTRL+D]

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
a r 4 5
a r 4 2
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         (R)         (R)                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 4 4
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         (R)     ^~^ (R)                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
p
============ Game Statistics ============
Totals:
  - Points: 0
  - Moves Made: 0
  - Number of Apples Eaten: 0
Completion:
  - Number of Apples Remaining: 2
  - Apple Completion Percentage: 0.0%
  - Maximum Points Remaining: 20
=========================================
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         (R)     ^~^ ###                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
p
============ Game Statistics ============
Totals:
  - Points: 10
  - Moves Made: 1
  - Number of Apples Eaten: 1
Completion:
  - Number of Apples Remaining: 1
  - Apple Completion Percentage: 50.0%
  - Maximum Points Remaining: 10
=========================================
a
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         (R) ^~^ ### ###                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
a
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ### ### ### ^~^                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
p
============ Game Statistics ============
Totals:
  - Points: 20
  - Moves Made: 3
  - Number of Apples Eaten: 2
Completion:
  - Number of Apples Remaining: 0
  - Apple Completion Percentage: 100.0%
  - Maximum Points Remaining: 0
=========================================
[CTRL+D]
--- Quitting Game ---

Autotest

Stage 3.2 - One-Way Passage

Our snake is saying that its job is too easssssy. Let's make the puzzle a bit harder to solve.

Task

In this substage, you will need to:

  1. Modify your Setup Loop to add directional passages using the command p [direction] [row] [col], where [direction] is one of four possibilities:
    1. ^ adds a PASSAGE_UP tile at [row] [col].
    2. v adds a PASSAGE_DOWN tile at [row] [col].
    3. < adds a PASSAGE_LEFT tile at [row] [col].
    4. > adds a PASSAGE_RIGHT tile at [row] [col].
  2. Modify your snake movement mechanic to ensure that:
    1. The snake can only move onto the directional passage in the correct direction.
    2. When the snake successfully moves onto a directional passage, the passage is immediately removed from the board and the tile’s entity set to EMPTY.
    3. If the snake attempts to move onto the directional passage in any other direction, it is counted as a loss and the game is ended (as per Stage 2.4).

Errors

For this new command, you should follow the input error handling cases and order described in Stage 1.2.

Assumptions / Restrictions / Clarifications

  • Input for [direction] will only be ^, v, <, or >.
  • The row and col entered will always be integers.

Examples

Input:

p > 5 5
p ^ 3 5
p < 3 4
s
5 4
d
w
w
a
[CTRL+D]

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
p > 5 5
p ^ 3 5
p < 3 4
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 <<< ^^^                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     >>>                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 5 4
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 <<< ^^^                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ^~^ >>>                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 <<< ^^^                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ### ^~^                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
w
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 <<< ^^^                
+   +   +   +   +   +   +   +   +   +   +
                     ^~^                
+   +   +   +   +   +   +   +   +   +   +
                 ### ###                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
w
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 <<< ^~^                
+   +   +   +   +   +   +   +   +   +   +
                     ###                
+   +   +   +   +   +   +   +   +   +   +
                 ### ###                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
a
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ^~^ ###                
+   +   +   +   +   +   +   +   +   +   +
                     ###                
+   +   +   +   +   +   +   +   +   +   +
                 ### ###                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
[CTRL+D]
--- Quitting Game ---

Input:

p ^ 5 5
s
5 4
d

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
p ^ 5 5
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     ^^^                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 5 4
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ^~^ ^^^                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ### ^~^                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Game Over ---
Guessss I was the prey today.
============ Game Statistics ============
Totals:
  - Points: 0
  - Moves Made: 1
  - Number of Apples Eaten: 0
Completion:
  - Number of Apples Remaining: 0
  - Apple Completion Percentage: 100.0%
  - Maximum Points Remaining: 0
=========================================

Autotest

Stage 3.3 - Snake Split

Our snake has eaten too many apples... it wants to go on a diet.

Task

In this substage, you will need to:

  • Modify your Setup Loop to handle the command a s [row] [col], which adds an APPLE_SPLIT entity to the tile at [row] [col].
  • Modify the apple consumption mechanic (from Stage 2.2) so that when the snake consumes the Split Apple:
    1. The snake is split in half and its "tail half" is removed, causing all the BODY_SEGMENT tiles in its latter half to revert to EMPTY tiles.
    2. 20 points are added to the snake’s score.

Definitions

  • By default, the "tail" of the snake refers to the oldest body segment currently on the board.
  • If the number of body segments (excluding the snake’s head) n is:
    • an even number, then n / 2 body segments counted in time-based priority from the tail should be removed.
    • an odd number, then (n + 1) / 2 body segments counted in time-based priority from the tail should be removed.

Errors

For this new command, you should follow the input error handling cases and order described in Stage 1.2.

Assumptions / Restrictions / Clarifications

  • The row and col entered will always be integers.

Examples

Input:

a s 3 5
s
1 1
s
s
d
d
d
d
[CTRL+D]

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
a s 3 5
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     (S)                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 1 1
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ^~^                                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     (S)                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ###                                
+   +   +   +   +   +   +   +   +   +   +
     ^~^                                
+   +   +   +   +   +   +   +   +   +   +
                     (S)                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ###                                
+   +   +   +   +   +   +   +   +   +   +
     ###                                
+   +   +   +   +   +   +   +   +   +   +
     ^~^             (S)                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ###                                
+   +   +   +   +   +   +   +   +   +   +
     ###                                
+   +   +   +   +   +   +   +   +   +   +
     ### ^~^         (S)                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ###                                
+   +   +   +   +   +   +   +   +   +   +
     ###                                
+   +   +   +   +   +   +   +   +   +   +
     ### ### ^~^     (S)                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ###                                
+   +   +   +   +   +   +   +   +   +   +
     ###                                
+   +   +   +   +   +   +   +   +   +   +
     ### ### ### ^~^ (S)                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ### ### ### ^~^                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
[CTRL+D]
--- Quitting Game ---

Input:

a s 6 5
s
2 2
s
s
s
s
d
d
d
[CTRL+D]

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
a s 6 5
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     (S)                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 2 2
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ^~^                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     (S)                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ^~^                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     (S)                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ^~^                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     (S)                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ^~^                            
+   +   +   +   +   +   +   +   +   +   +
                     (S)                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ^~^         (S)                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ### ^~^     (S)                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ### ### ^~^ (S)                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ### ### ### ^~^                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
[CTRL+D]
--- Quitting Game ---

Input:

a s 3 8
a s 5 6
a s 2 3
s
3 2
d
w
d
d
d
s
s
s
d
d
w
w
[CTRL+D]

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
a s 3 8
a s 5 6
a s 2 3
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             (S)                        
+   +   +   +   +   +   +   +   +   +   +
                                 (S)    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                         (S)            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 3 2
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             (S)                        
+   +   +   +   +   +   +   +   +   +   +
         ^~^                     (S)    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                         (S)            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             (S)                        
+   +   +   +   +   +   +   +   +   +   +
         ### ^~^                 (S)    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                         (S)            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
w
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             ^~^                        
+   +   +   +   +   +   +   +   +   +   +
             ###                 (S)    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                         (S)            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             ### ^~^                    
+   +   +   +   +   +   +   +   +   +   +
             ###                 (S)    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                         (S)            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             ### ### ^~^                
+   +   +   +   +   +   +   +   +   +   +
             ###                 (S)    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                         (S)            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             ### ### ### ^~^            
+   +   +   +   +   +   +   +   +   +   +
             ###                 (S)    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                         (S)            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             ### ### ### ###            
+   +   +   +   +   +   +   +   +   +   +
             ###         ^~^     (S)    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                         (S)            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             ### ### ### ###            
+   +   +   +   +   +   +   +   +   +   +
             ###         ###     (S)    
+   +   +   +   +   +   +   +   +   +   +
                         ^~^            
+   +   +   +   +   +   +   +   +   +   +
                         (S)            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                         ###            
+   +   +   +   +   +   +   +   +   +   +
                         ###     (S)    
+   +   +   +   +   +   +   +   +   +   +
                         ###            
+   +   +   +   +   +   +   +   +   +   +
                         ^~^            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                         ###            
+   +   +   +   +   +   +   +   +   +   +
                         ###     (S)    
+   +   +   +   +   +   +   +   +   +   +
                         ###            
+   +   +   +   +   +   +   +   +   +   +
                         ### ^~^        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                         ###            
+   +   +   +   +   +   +   +   +   +   +
                         ###     (S)    
+   +   +   +   +   +   +   +   +   +   +
                         ###            
+   +   +   +   +   +   +   +   +   +   +
                         ### ### ^~^    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
w
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                         ###            
+   +   +   +   +   +   +   +   +   +   +
                         ###     (S)    
+   +   +   +   +   +   +   +   +   +   +
                         ###     ^~^    
+   +   +   +   +   +   +   +   +   +   +
                         ### ### ###    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
w
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                 ^~^    
+   +   +   +   +   +   +   +   +   +   +
                                 ###    
+   +   +   +   +   +   +   +   +   +   +
                             ### ###    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
[CTRL+D]
--- Quitting Game ---

Input:

a s 5 5
s
5 4
p
d
p
[CTRL+D]

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
a s 5 5
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     (S)                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 5 4
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ^~^ (S)                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
p
============ Game Statistics ============
Totals:
  - Points: 0
  - Moves Made: 0
  - Number of Apples Eaten: 0
Completion:
  - Number of Apples Remaining: 1
  - Apple Completion Percentage: 0.0%
  - Maximum Points Remaining: 20
=========================================
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     ^~^                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
p
============ Game Statistics ============
Totals:
  - Points: 20
  - Moves Made: 1
  - Number of Apples Eaten: 1
Completion:
  - Number of Apples Remaining: 0
  - Apple Completion Percentage: 100.0%
  - Maximum Points Remaining: 0
=========================================
[CTRL+D]
--- Quitting Game ---

Autotest

Stage 3.4 - Reset

Our snake is worried it might get stuck in some peculiar situations where it won't be able to escape. Let's make sure our snake can reset back to the beginning if it gets stuck!

Task

In this substage, you will need to:

  • Modify the Gameplay Loop to handle a new r command that resets the map. When the r command is entered, your program should:
    1. Print "--- Resetting Map ---\n".
    2. Reset the map, snake position, and points to the original state. The original state is the point at which the map has been setup, and the snake is first positioned.
    3. Use the provided print_board() function to display the board with the snake in the reset state.

Assumptions / Restrictions / Clarifications

  • The original state of points is 0.
  • If there are no apples to start with, all exits should be unlocked at the end of the first Snake Turn after the reset (as per Stage 2.2).

Examples

Input:

e 5 3
s
0 0
s
s
d
r
[CTRL+D]

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
e 5 3
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             [X]                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 0 0
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 ^~^                                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             [X]                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ^~^                                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             [ ]                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ^~^                                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             [ ]                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ### ^~^                                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             [ ]                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
r
--- Resetting Map ---
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
 ^~^                                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             [X]                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
[CTRL+D]
--- Quitting Game ---

Input:

a n 6 7
a r 5 5
e 3 4
s
6 8
a
a
a
w
p
r
p
[CTRL+D]

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
a n 6 7
a r 5 5
e 3 4
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 [X]                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     (R)                
+   +   +   +   +   +   +   +   +   +   +
                             (`)        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 6 8
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 [X]                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     (R)                
+   +   +   +   +   +   +   +   +   +   +
                             (`) ^~^    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
a
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 [X]                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     (R)                
+   +   +   +   +   +   +   +   +   +   +
                             ^~^ ###    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
a
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 [X]                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     (R)                
+   +   +   +   +   +   +   +   +   +   +
                         ^~^ ### ###    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
a
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 [X]                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     (R)                
+   +   +   +   +   +   +   +   +   +   +
                     ^~^ ### ### ###    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
w
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 [ ]                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     ###                
+   +   +   +   +   +   +   +   +   +   +
                     ### ### ### ^~^    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
p
============ Game Statistics ============
Totals:
  - Points: 15
  - Moves Made: 4
  - Number of Apples Eaten: 2
Completion:
  - Number of Apples Remaining: 0
  - Apple Completion Percentage: 100.0%
  - Maximum Points Remaining: 0
=========================================
r
--- Resetting Map ---
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 [X]                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     (R)                
+   +   +   +   +   +   +   +   +   +   +
                             (`) ^~^    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
p
============ Game Statistics ============
Totals:
  - Points: 0
  - Moves Made: 0
  - Number of Apples Eaten: 0
Completion:
  - Number of Apples Remaining: 2
  - Apple Completion Percentage: 0.0%
  - Maximum Points Remaining: 15
=========================================
[CTRL+D]
--- Quitting Game ---

Input:

e 4 5
e 7 8
s
2 2
s
d
r
s
[CTRL+D]

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
e 4 5
e 7 8
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     [X]                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                 [X]    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 2 2
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ^~^                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     [X]                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                 [X]    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ^~^                            
+   +   +   +   +   +   +   +   +   +   +
                     [ ]                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                 [ ]    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ### ^~^                        
+   +   +   +   +   +   +   +   +   +   +
                     [ ]                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                 [ ]    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
r
--- Resetting Map ---
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ^~^                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     [X]                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                 [X]    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ^~^                            
+   +   +   +   +   +   +   +   +   +   +
                     [ ]                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                 [ ]    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
[CTRL+D]
--- Quitting Game ---

Autotest

Stage 3.5 - Portals

Moving one tile at a time is good and all, but our snake wants faster transportation!

It’s portal time.

We will now create pairs of portals that allow the snake to move across the map. The snake can enter either portal, in any direction, and its head should pop out from the paired portal in the same direction of movement.

Task

In this substage, you will need to:

  • Modify your Setup Loop to handle the command t [row1] [col1] [row2] [col2], which adds a PORTAL entity to the tile at [row1] [col1] and another PORTAL entity at [row2] [col2].
    • Only up to a maximum of 5 portal pairs can be placed on the map. This means that there should only ever be a maximum of 10 portal entities on the board.
  • Modify your snake movement mechanic to ensure that:
    1. The snake can move into a portal from any direction.
    2. When the snake moves into a portal, its head should appear out from the paired portal in the same direction of movement.
    3. If the snake attempts to move into a portal which causes the snake’s death upon moving through, the game should end like usual.

Errors

When adding pairs of portals, if any of the following conditions are met, the pair of portals should not be added, and the corresponding error message should be printed out instead:

  1. If the user attempts to place a portal pair after the maximum number of portal pairs have already been placed:
    • Print "ERROR: Invalid placement, maximum number of portal pairs already reached!\n".
    • Continue reading the next command.
  2. If the user attempts to place a portal pair where the first portal in the pair is out of bounds:
    • Print "ERROR: Invalid position for first portal in pair, [row] [col] is out of bounds!\n".
    • Continue reading the next command.
  3. If the user attempts to place a portal pair where the first portal in the pair is occupied by another tile:
    • Print "ERROR: Invalid tile for first portal in pair, [row] [col] is occupied!\n".
    • Continue reading the next command.
  4. If the user attempts to place a portal pair where the second portal in the pair is out of bounds:
    • Print "ERROR: Invalid position for second portal in pair, [row] [col] is out of bounds!\n".
    • Continue reading the next command.
  5. If the user attempts to place a portal pair where the second portal in the pair is occupied by another tile that is not the first portal in the pair:
    • Print "ERROR: Invalid tile for second portal in pair, [row] [col] is occupied!\n".
    • Continue reading the next command.

Side Effects

Portals may cause the snake's body segments to no longer appear as contiguous on the board. However, the effects of consuming Reverse Apples and Split Apples should remain the same.

  • Any body segment that remains on the board is still considered part of the snake, even if it is visually disconnected from the head.
  • By default, the "tail" of the snake refers to the oldest body segment currently on the board (as per Stage 3.1).
  • When a Reverse Apple is consumed, this time-based ordering is reversed throughout all the segments of the snake: the oldest segment becomes the new head, and the previous head becomes the tail.
  • When a Split Apple is consumed, the "tail half" of the snake, counted in time-based pirority from the tail, is removed (as per Stage 3.3).

Assumptions / Restrictions / Clarifications

  • The snake can enter the same portal more than one time.
  • Portals will not be recursive. This is undefined behaviour and will not be tested.
    • You may assume that in all tests and examples, moving into a portal will not cause the snake to enter another portal after exiting the paired portal.
  • A portal pair can be placed such that both its portals are in the same position - that is, they are stacked on each other.
    • This portal pair placement still contributes 1 portal pair to the maximum of 5 portal pairs able to be placed on the board.

Examples

Input:

t 2 3 8 5
s
2 1
d
d
w
d
w
[CTRL+D]

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
t 2 3 8 5
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             ~O~                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     ~O~                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 2 1
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ^~^     ~O~                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     ~O~                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ### ^~^ ~O~                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     ~O~                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ### ### ~O~                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     ~O~ ^~^            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
w
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ### ### ~O~                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                         ^~^            
+   +   +   +   +   +   +   +   +   +   +
                     ~O~ ###            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ### ### ~O~                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                         ### ^~^        
+   +   +   +   +   +   +   +   +   +   +
                     ~O~ ###            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
w
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ### ### ~O~                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                             ^~^        
+   +   +   +   +   +   +   +   +   +   +
                         ### ###        
+   +   +   +   +   +   +   +   +   +   +
                     ~O~ ###            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
[CTRL+D]
--- Quitting Game ---

Input:

t 2 7 7 3
s
7 1
d
d
s
a
w
w
[CTRL+D]

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
t 2 7 7 3
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                             ~O~        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             ~O~                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 7 1
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                             ~O~        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ^~^     ~O~                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                             ~O~        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ### ^~^ ~O~                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                             ~O~ ^~^    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ### ### ~O~                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                             ~O~ ###    
+   +   +   +   +   +   +   +   +   +   +
                                 ^~^    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ### ### ~O~                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
a
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                             ~O~ ###    
+   +   +   +   +   +   +   +   +   +   +
                             ^~^ ###    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ### ### ~O~                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
w
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                             ~O~ ###    
+   +   +   +   +   +   +   +   +   +   +
                             ### ###    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             ^~^                        
+   +   +   +   +   +   +   +   +   +   +
     ### ### ~O~                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
w
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                             ~O~ ###    
+   +   +   +   +   +   +   +   +   +   +
                             ### ###    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             ^~^                        
+   +   +   +   +   +   +   +   +   +   +
             ###                        
+   +   +   +   +   +   +   +   +   +   +
     ### ### ~O~                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
[CTRL+D]
--- Quitting Game ---

Input:

t 4 1 7 5
t 5 6 1 3
s
1 1
d
d
s
s
a
a
s
s
[CTRL+D]

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
t 4 1 7 5
t 5 6 1 3
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             ~O~                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ~O~                                
+   +   +   +   +   +   +   +   +   +   +
                         ~O~            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     ~O~                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 1 1
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ^~^     ~O~                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ~O~                                
+   +   +   +   +   +   +   +   +   +   +
                         ~O~            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     ~O~                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ### ^~^ ~O~                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ~O~                                
+   +   +   +   +   +   +   +   +   +   +
                         ~O~            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     ~O~                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ### ### ~O~                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ~O~                                
+   +   +   +   +   +   +   +   +   +   +
                         ~O~ ^~^        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     ~O~                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ### ### ~O~                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ~O~                                
+   +   +   +   +   +   +   +   +   +   +
                         ~O~ ###        
+   +   +   +   +   +   +   +   +   +   +
                             ^~^        
+   +   +   +   +   +   +   +   +   +   +
                     ~O~                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ### ### ~O~                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ~O~                                
+   +   +   +   +   +   +   +   +   +   +
                         ~O~ ###        
+   +   +   +   +   +   +   +   +   +   +
                             ###        
+   +   +   +   +   +   +   +   +   +   +
                     ~O~     ^~^        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
a
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ### ### ~O~                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ~O~                                
+   +   +   +   +   +   +   +   +   +   +
                         ~O~ ###        
+   +   +   +   +   +   +   +   +   +   +
                             ###        
+   +   +   +   +   +   +   +   +   +   +
                     ~O~ ^~^ ###        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
a
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ### ### ~O~                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
 ^~^ ~O~                                
+   +   +   +   +   +   +   +   +   +   +
                         ~O~ ###        
+   +   +   +   +   +   +   +   +   +   +
                             ###        
+   +   +   +   +   +   +   +   +   +   +
                     ~O~ ### ###        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ### ### ~O~                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
 ### ~O~                                
+   +   +   +   +   +   +   +   +   +   +
 ^~^                     ~O~ ###        
+   +   +   +   +   +   +   +   +   +   +
                             ###        
+   +   +   +   +   +   +   +   +   +   +
                     ~O~ ### ###        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ### ### ~O~                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
 ### ~O~                                
+   +   +   +   +   +   +   +   +   +   +
 ###                     ~O~ ###        
+   +   +   +   +   +   +   +   +   +   +
 ^~^                         ###        
+   +   +   +   +   +   +   +   +   +   +
                     ~O~ ### ###        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
[CTRL+D]
--- Quitting Game ---

Input:

t 2 2 6 3
w 6 4
s 2 1
d

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
t 2 2 6 3
w 6 4
s 2 1
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ~O~                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             ~O~ |||                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: +---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ^~^ ~O~                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             ~O~ |||                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ### ~O~                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             ~O~ ^~^                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Game Over ---
Guessss I was the prey today.
============ Game Statistics ============
Totals:
  - Points: 0
  - Moves Made: 1
  - Number of Apples Eaten: 0
Completion:
  - Number of Apples Remaining: 0
  - Apple Completion Percentage: 100.0%
  - Maximum Points Remaining: 0
=========================================

Autotest

Testing & Submission

Are you finished with this stage? If so, you should make sure to do the following:

  • Run 1511 style, and clean up any issues a human may have reading your code. Don't forget -- 20% of your mark in the assignment is based on style!
  • Autotest for this stage of the assignment by running the autotest-stage command as shown below.
  • Remember -- give early, and give often. Only your last submission counts, but why not be safe and submit right now?
1511 style cs_snake.c
1511 autotest-stage 03 cs_snake
give cs1511 ass1_cs_snake cs_snake.c

Stage 4

Welcome to Stage 4! In this stage you will have to opportunity to extend the core functionality of CS Snake with some advanced features. This milestone consists of two substages:

  • Stage 4.1 - Exploding Apples.
  • Stage 4.2 - Ready Player 2.

Stage 4.1 - Exploding Apples

HEY! HEY! APPLE! HEY APPLE!!

The apples so far haven't been exquisite enough for our snake's taste - annoying right? This time, we'll go all out with a new explosive flavour! Let's blow our snake's taste buds into Granny Smithereens.

Task

In this substage, you will need to:

  • Modify your Setup Loop to handle the command a e [radius] [row] [col], where [radius] is a value from 1 to 6 inclusive, which adds an APPLE_EXPLODE entity to the tile at [row] [col] with explosion radius [radius].

  • Modify the provided print_board() function to display APPLE_EXPLODE entities in the following format:

    If the apple has an explosion radius of n, it should be printed as (n) on the board.

  • Modify the apple consumption mechanic (from Stage 2.2) so that when the snake consumes an Exploding Apple:

    1. 20 points are added to the snake's score.

    2. Immediately after the apple is consumed, the four directly adjacent tiles (up, down, left, right) should have their entity values be replaced with EXPLOSION.

      However, EXIT_LOCKED and EXIT_UNLOCKED entities should not be replaced and should be left as is on the board.

    3. At the start of the following Snake Turn, before the snake's movement command input is processed:

      • The previously placed EXPLOSION entities should be removed and reverted to EMPTY tiles.
      • If the original explosion radius is greater than 1, then the explosion continues to propagate outwards in a diamond ring shape (see examples).

      Explosions should not propagate if the player inputs the print game statistics command p as this does not count as an action turn.

    4. The previous step is repeated until the original explosion radius is reached. After the final ring of tiles have been set to EXPLOSION and then cleared, the explosion should stop propagating on the board.

Errors

For this new command, you should follow the input error handling cases and order described in Stage 1.2.

Side Effects

  • As with portals, explosions may cause the snake's body segments to appear non-contiguous on the board. However, the effects of consuming Reverse Apples and Split Apples should remain the same.
    • Any body segment that remains on the board is still considered part of the snake, even if it is visually disconnected from the head.
    • By default, the "tail" of the snake refers to the oldest body segment currently on the board (as per Stage 3.1).
    • When a Reverse Apple is consumed, this time-based ordering is reversed throughout all the segments of the snake: the oldest segment becomes the new head, and the previous head becomes the tail (see Example 4.1.6).
    • When a Split Apple is consumed, the "tail half" of the snake, counted in time-based pirority from the tail, is removed (as per Stage 3.3).
  • If an apple of any type (including Exploding Apples) is destroyed by the explosion, it should not be considered as directly consumed by the snake - its effect should not be triggered nor should points be added to the snake's score.
    • This should, however, contribute to an increase in the "Apple Completion Percentage" when the print statistics p command is used. This is because the apple is no longer on the board and so should be considered as part of num_eaten in the formula given in Stage 2.3.
    • The total initial apple count should remain the same in the completion percentage calculation.
  • As per Stage 2.2, if there are no apples on the board at the end of a Snake Turn, then all exits should be unlocked. See Example 4.1.5.
  • When the reset command r is entered and one or more explosions are still propagating:
    • All active explosions should immediately stop.
    • The map and points should be reset as usual.
  • If a portal is destroyed by an explosion, its paired portal should no longer function as a portal, but rather now act as a WALL entity. It should still be printed as a portal.
    • If the snake attempts to enter a portal that does not have an existing paired portal, the move will be counted as a loss and the game will end.
  • If, at the end of a turn, the snake's head is on an EXPLOSION tile, this should be counted as a loss and cause the game to end.
    • This clarification will be relevant in Stage 4.2 when there are two snakes on the board.

Assumptions / Restrictions / Clarifications

  • Input for [radius] will only be 1, 2, 3, 4, 5, or 6.
  • The row and col entered will always be integers.
  • Entities that can be destroyed by the explosion include walls, body segments, all apple types, all one-way passage types, and portals.

Examples

Input:

a e 2 4 4
s
1 4
s
s
s
s
s
[CTRL+D]

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
a e 2 4 4
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 (2)                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 1 4
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ^~^                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 (2)                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ###                    
+   +   +   +   +   +   +   +   +   +   +
                 ^~^                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 (2)                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ###                    
+   +   +   +   +   +   +   +   +   +   +
                 ###                    
+   +   +   +   +   +   +   +   +   +   +
                 ^~^                    
+   +   +   +   +   +   +   +   +   +   +
                 (2)                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ###                    
+   +   +   +   +   +   +   +   +   +   +
                 ###                    
+   +   +   +   +   +   +   +   +   +   +
                 ***                    
+   +   +   +   +   +   +   +   +   +   +
             *** ^~^ ***                
+   +   +   +   +   +   +   +   +   +   +
                 ***                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ###                    
+   +   +   +   +   +   +   +   +   +   +
                 ***                    
+   +   +   +   +   +   +   +   +   +   +
             ***     ***                
+   +   +   +   +   +   +   +   +   +   +
         ***     ###     ***            
+   +   +   +   +   +   +   +   +   +   +
             *** ^~^ ***                
+   +   +   +   +   +   +   +   +   +   +
                 ***                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ###                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ###                    
+   +   +   +   +   +   +   +   +   +   +
                 ###                    
+   +   +   +   +   +   +   +   +   +   +
                 ^~^                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
[CTRL+D]
--- Quitting Game ---

Input:

a e 4 5 5
w 3 4
a n 5 6
a r 2 2
a r 8 1
a s 6 7
a s 9 8
w 0 2
p > 3 7
p ^ 4 9
p v 7 3
p < 2 3
s
5 1
d
d
d
d
w
w
w
w
[CTRL+D]

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
a e 4 5 5
w 3 4
a n 5 6
a r 2 2
a r 8 1
a s 6 7
a s 9 8
w 0 2
p > 3 7
p ^ 4 9
p v 7 3
p < 2 3
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
         |||                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         (R) <<<                        
+   +   +   +   +   +   +   +   +   +   +
                 |||         >>>        
+   +   +   +   +   +   +   +   +   +   +
                                     ^^^
+   +   +   +   +   +   +   +   +   +   +
                     (4) (`)            
+   +   +   +   +   +   +   +   +   +   +
                             (S)        
+   +   +   +   +   +   +   +   +   +   +
             vvv                        
+   +   +   +   +   +   +   +   +   +   +
     (R)                                
+   +   +   +   +   +   +   +   +   +   +
                                 (S)    
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 5 1
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
         |||                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         (R) <<<                        
+   +   +   +   +   +   +   +   +   +   +
                 |||         >>>        
+   +   +   +   +   +   +   +   +   +   +
                                     ^^^
+   +   +   +   +   +   +   +   +   +   +
     ^~^             (4) (`)            
+   +   +   +   +   +   +   +   +   +   +
                             (S)        
+   +   +   +   +   +   +   +   +   +   +
             vvv                        
+   +   +   +   +   +   +   +   +   +   +
     (R)                                
+   +   +   +   +   +   +   +   +   +   +
                                 (S)    
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
         |||                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         (R) <<<                        
+   +   +   +   +   +   +   +   +   +   +
                 |||         >>>        
+   +   +   +   +   +   +   +   +   +   +
                                     ^^^
+   +   +   +   +   +   +   +   +   +   +
     ### ^~^         (4) (`)            
+   +   +   +   +   +   +   +   +   +   +
                             (S)        
+   +   +   +   +   +   +   +   +   +   +
             vvv                        
+   +   +   +   +   +   +   +   +   +   +
     (R)                                
+   +   +   +   +   +   +   +   +   +   +
                                 (S)    
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
         |||                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         (R) <<<                        
+   +   +   +   +   +   +   +   +   +   +
                 |||         >>>        
+   +   +   +   +   +   +   +   +   +   +
                                     ^^^
+   +   +   +   +   +   +   +   +   +   +
     ### ### ^~^     (4) (`)            
+   +   +   +   +   +   +   +   +   +   +
                             (S)        
+   +   +   +   +   +   +   +   +   +   +
             vvv                        
+   +   +   +   +   +   +   +   +   +   +
     (R)                                
+   +   +   +   +   +   +   +   +   +   +
                                 (S)    
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
         |||                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         (R) <<<                        
+   +   +   +   +   +   +   +   +   +   +
                 |||         >>>        
+   +   +   +   +   +   +   +   +   +   +
                                     ^^^
+   +   +   +   +   +   +   +   +   +   +
     ### ### ### ^~^ (4) (`)            
+   +   +   +   +   +   +   +   +   +   +
                             (S)        
+   +   +   +   +   +   +   +   +   +   +
             vvv                        
+   +   +   +   +   +   +   +   +   +   +
     (R)                                
+   +   +   +   +   +   +   +   +   +   +
                                 (S)    
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
         |||                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         (R) <<<                        
+   +   +   +   +   +   +   +   +   +   +
                 |||         >>>        
+   +   +   +   +   +   +   +   +   +   +
                     ***             ^^^
+   +   +   +   +   +   +   +   +   +   +
     ### ### ### *** ^~^ ***            
+   +   +   +   +   +   +   +   +   +   +
                     ***     (S)        
+   +   +   +   +   +   +   +   +   +   +
             vvv                        
+   +   +   +   +   +   +   +   +   +   +
     (R)                                
+   +   +   +   +   +   +   +   +   +   +
                                 (S)    
+   +   +   +   +   +   +   +   +   +   +
w
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
         |||                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         (R) <<<                        
+   +   +   +   +   +   +   +   +   +   +
                 ||| ***     >>>        
+   +   +   +   +   +   +   +   +   +   +
                 *** ^~^ ***         ^^^
+   +   +   +   +   +   +   +   +   +   +
     ### ### ***     ###     ***        
+   +   +   +   +   +   +   +   +   +   +
                 ***     *** (S)        
+   +   +   +   +   +   +   +   +   +   +
             vvv     ***                
+   +   +   +   +   +   +   +   +   +   +
     (R)                                
+   +   +   +   +   +   +   +   +   +   +
                                 (S)    
+   +   +   +   +   +   +   +   +   +   +
w
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
         |||                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         (R) <<<     ***                
+   +   +   +   +   +   +   +   +   +   +
                 *** ^~^ *** >>>        
+   +   +   +   +   +   +   +   +   +   +
             ***     ###     ***     ^^^
+   +   +   +   +   +   +   +   +   +   +
     ### ***         ###         ***    
+   +   +   +   +   +   +   +   +   +   +
             ***             ***        
+   +   +   +   +   +   +   +   +   +   +
             vvv ***     ***            
+   +   +   +   +   +   +   +   +   +   +
     (R)             ***                
+   +   +   +   +   +   +   +   +   +   +
                                 (S)    
+   +   +   +   +   +   +   +   +   +   +
w
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
         |||                            
+   +   +   +   +   +   +   +   +   +   +
                     ***                
+   +   +   +   +   +   +   +   +   +   +
         (R) <<< *** ^~^ ***            
+   +   +   +   +   +   +   +   +   +   +
             ***     ###     ***        
+   +   +   +   +   +   +   +   +   +   +
         ***         ###         *** ^^^
+   +   +   +   +   +   +   +   +   +   +
     ***             ###             ***
+   +   +   +   +   +   +   +   +   +   +
         ***                     ***    
+   +   +   +   +   +   +   +   +   +   +
             ***             ***        
+   +   +   +   +   +   +   +   +   +   +
     (R)         ***     ***            
+   +   +   +   +   +   +   +   +   +   +
                     ***         (S)    
+   +   +   +   +   +   +   +   +   +   +
w
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
         |||                            
+   +   +   +   +   +   +   +   +   +   +
                     ^~^                
+   +   +   +   +   +   +   +   +   +   +
         (R) <<<     ###                
+   +   +   +   +   +   +   +   +   +   +
                     ###                
+   +   +   +   +   +   +   +   +   +   +
                     ###             ^^^
+   +   +   +   +   +   +   +   +   +   +
                     ###                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     (R)                                
+   +   +   +   +   +   +   +   +   +   +
                                 (S)    
+   +   +   +   +   +   +   +   +   +   +
[CTRL+D]
--- Quitting Game ---

Input:

a e 4 4 4
e 3 7
s
1 0
s
s
d
s
s
d
d
d
w
d
w
d
d

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
a e 4 4 4
e 3 7
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                             [X]        
+   +   +   +   +   +   +   +   +   +   +
                 (4)                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 1 0
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
 ^~^                                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                             [X]        
+   +   +   +   +   +   +   +   +   +   +
                 (4)                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ^~^                                    
+   +   +   +   +   +   +   +   +   +   +
                             [X]        
+   +   +   +   +   +   +   +   +   +   +
                 (4)                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ^~^                         [X]        
+   +   +   +   +   +   +   +   +   +   +
                 (4)                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ### ^~^                     [X]        
+   +   +   +   +   +   +   +   +   +   +
                 (4)                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ### ###                     [X]        
+   +   +   +   +   +   +   +   +   +   +
     ^~^         (4)                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ### ###                     [X]        
+   +   +   +   +   +   +   +   +   +   +
     ###         (4)                    
+   +   +   +   +   +   +   +   +   +   +
     ^~^                                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ### ###                     [X]        
+   +   +   +   +   +   +   +   +   +   +
     ###         (4)                    
+   +   +   +   +   +   +   +   +   +   +
     ### ^~^                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ### ###                     [X]        
+   +   +   +   +   +   +   +   +   +   +
     ###         (4)                    
+   +   +   +   +   +   +   +   +   +   +
     ### ### ^~^                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ### ###                     [X]        
+   +   +   +   +   +   +   +   +   +   +
     ###         (4)                    
+   +   +   +   +   +   +   +   +   +   +
     ### ### ### ^~^                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
w
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ### ###         ***         [ ]        
+   +   +   +   +   +   +   +   +   +   +
     ###     *** ^~^ ***                
+   +   +   +   +   +   +   +   +   +   +
     ### ### ### ***                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ###             ***                    
+   +   +   +   +   +   +   +   +   +   +
 ### ###     ***     ***     [ ]        
+   +   +   +   +   +   +   +   +   +   +
     ### ***     ### ^~^ ***            
+   +   +   +   +   +   +   +   +   +   +
     ### ### ***     ***                
+   +   +   +   +   +   +   +   +   +   +
                 ***                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
w
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
 ###             ***                    
+   +   +   +   +   +   +   +   +   +   +
 ###         ***     ***                
+   +   +   +   +   +   +   +   +   +   +
 ### ### ***         ^~^ *** [ ]        
+   +   +   +   +   +   +   +   +   +   +
     ***         ### ###     ***        
+   +   +   +   +   +   +   +   +   +   +
     ### ***             ***            
+   +   +   +   +   +   +   +   +   +   +
             ***     ***                
+   +   +   +   +   +   +   +   +   +   +
                 ***                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                 ***                    
+   +   +   +   +   +   +   +   +   +   +
 ###         ***     ***                
+   +   +   +   +   +   +   +   +   +   +
 ###     ***             ***            
+   +   +   +   +   +   +   +   +   +   +
 ### ***             ### ^~^ [ ]        
+   +   +   +   +   +   +   +   +   +   +
 ***             ### ###         ***    
+   +   +   +   +   +   +   +   +   +   +
     ***                     ***        
+   +   +   +   +   +   +   +   +   +   +
         ***             ***            
+   +   +   +   +   +   +   +   +   +   +
             ***     ***                
+   +   +   +   +   +   +   +   +   +   +
                 ***                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ###                                    
+   +   +   +   +   +   +   +   +   +   +
 ###                 ### ### ^~^        
+   +   +   +   +   +   +   +   +   +   +
                 ### ###                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Game Over ---
Ssslithered out with a full stomach!
============ Game Statistics ============
Totals:
  - Points: 20
  - Moves Made: 13
  - Number of Apples Eaten: 1
Completion:
  - Number of Apples Remaining: 0
  - Apple Completion Percentage: 100.0%
  - Maximum Points Remaining: 0
=========================================

Input:

a e 6 5 5
a e 4 9 9
s
5 4
d
d
d
d
d
s
s
s
s
a
a
a
a
[CTRL+D]

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
a e 6 5 5
a e 4 9 9
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     (6)                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                     (4)
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 5 4
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ^~^ (6)                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                     (4)
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     ***                
+   +   +   +   +   +   +   +   +   +   +
                 *** ^~^ ***            
+   +   +   +   +   +   +   +   +   +   +
                     ***                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                     (4)
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     ***                
+   +   +   +   +   +   +   +   +   +   +
                 ***     ***            
+   +   +   +   +   +   +   +   +   +   +
             ***     ### ^~^ ***        
+   +   +   +   +   +   +   +   +   +   +
                 ***     ***            
+   +   +   +   +   +   +   +   +   +   +
                     ***                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                     (4)
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     ***                
+   +   +   +   +   +   +   +   +   +   +
                 ***     ***            
+   +   +   +   +   +   +   +   +   +   +
             ***             ***        
+   +   +   +   +   +   +   +   +   +   +
         ***         ### ### ^~^ ***    
+   +   +   +   +   +   +   +   +   +   +
             ***             ***        
+   +   +   +   +   +   +   +   +   +   +
                 ***     ***            
+   +   +   +   +   +   +   +   +   +   +
                     ***                
+   +   +   +   +   +   +   +   +   +   +
                                     (4)
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     ***                
+   +   +   +   +   +   +   +   +   +   +
                 ***     ***            
+   +   +   +   +   +   +   +   +   +   +
             ***             ***        
+   +   +   +   +   +   +   +   +   +   +
         ***                     ***    
+   +   +   +   +   +   +   +   +   +   +
     ***             ### ### ### ^~^ ***
+   +   +   +   +   +   +   +   +   +   +
         ***                     ***    
+   +   +   +   +   +   +   +   +   +   +
             ***             ***        
+   +   +   +   +   +   +   +   +   +   +
                 ***     ***            
+   +   +   +   +   +   +   +   +   +   +
                     ***             (4)
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                     ***                
+   +   +   +   +   +   +   +   +   +   +
                 ***     ***            
+   +   +   +   +   +   +   +   +   +   +
             ***             ***        
+   +   +   +   +   +   +   +   +   +   +
         ***                     ***    
+   +   +   +   +   +   +   +   +   +   +
     ***                             ***
+   +   +   +   +   +   +   +   +   +   +
 ***                 ### ### ### ### ^~^
+   +   +   +   +   +   +   +   +   +   +
     ***                             ***
+   +   +   +   +   +   +   +   +   +   +
         ***                     ***    
+   +   +   +   +   +   +   +   +   +   +
             ***             ***        
+   +   +   +   +   +   +   +   +   +   +
                 ***     ***         (4)
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                 ***     ***            
+   +   +   +   +   +   +   +   +   +   +
             ***             ***        
+   +   +   +   +   +   +   +   +   +   +
         ***                     ***    
+   +   +   +   +   +   +   +   +   +   +
     ***                             ***
+   +   +   +   +   +   +   +   +   +   +
 ***                                    
+   +   +   +   +   +   +   +   +   +   +
                     ### ### ### ### ###
+   +   +   +   +   +   +   +   +   +   +
 ***                                 ^~^
+   +   +   +   +   +   +   +   +   +   +
     ***                             ***
+   +   +   +   +   +   +   +   +   +   +
         ***                     ***    
+   +   +   +   +   +   +   +   +   +   +
             ***             ***     (4)
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     ### ### ### ### ###
+   +   +   +   +   +   +   +   +   +   +
                                     ###
+   +   +   +   +   +   +   +   +   +   +
                                     ^~^
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                     (4)
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     ### ### ### ### ###
+   +   +   +   +   +   +   +   +   +   +
                                     ###
+   +   +   +   +   +   +   +   +   +   +
                                     ###
+   +   +   +   +   +   +   +   +   +   +
                                     ^~^
+   +   +   +   +   +   +   +   +   +   +
                                     (4)
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     ### ### ### ### ###
+   +   +   +   +   +   +   +   +   +   +
                                     ###
+   +   +   +   +   +   +   +   +   +   +
                                     ###
+   +   +   +   +   +   +   +   +   +   +
                                     ***
+   +   +   +   +   +   +   +   +   +   +
                                 *** ^~^
+   +   +   +   +   +   +   +   +   +   +
a
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     ### ### ### ### ###
+   +   +   +   +   +   +   +   +   +   +
                                     ###
+   +   +   +   +   +   +   +   +   +   +
                                     ***
+   +   +   +   +   +   +   +   +   +   +
                                 ***    
+   +   +   +   +   +   +   +   +   +   +
                             *** ^~^ ###
+   +   +   +   +   +   +   +   +   +   +
a
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     ### ### ### ### ###
+   +   +   +   +   +   +   +   +   +   +
                                     ***
+   +   +   +   +   +   +   +   +   +   +
                                 ***    
+   +   +   +   +   +   +   +   +   +   +
                             ***        
+   +   +   +   +   +   +   +   +   +   +
                         *** ^~^ ### ###
+   +   +   +   +   +   +   +   +   +   +
a
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     ### ### ### ### ***
+   +   +   +   +   +   +   +   +   +   +
                                 ***    
+   +   +   +   +   +   +   +   +   +   +
                             ***        
+   +   +   +   +   +   +   +   +   +   +
                         ***            
+   +   +   +   +   +   +   +   +   +   +
                     *** ^~^ ### ### ###
+   +   +   +   +   +   +   +   +   +   +
a
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     ### ### ### ###    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     ^~^ ### ### ### ###
+   +   +   +   +   +   +   +   +   +   +
[CTRL+D]
--- Quitting Game ---

Input:

a e 5 3 4
a s 3 6
a n 3 1
e 3 8
s
3 3
d
d
d
d
d

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
a e 5 3 4
a s 3 6
a n 3 1
e 3 8
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     (`)         (5)     (S)     [X]    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 3 3
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     (`)     ^~^ (5)     (S)     [X]    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ***                    
+   +   +   +   +   +   +   +   +   +   +
     (`)     *** ^~^ *** (S)     [X]    
+   +   +   +   +   +   +   +   +   +   +
                 ***                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ***                    
+   +   +   +   +   +   +   +   +   +   +
             ***     ***                
+   +   +   +   +   +   +   +   +   +   +
     (`) ***     ### ^~^ ***     [X]    
+   +   +   +   +   +   +   +   +   +   +
             ***     ***                
+   +   +   +   +   +   +   +   +   +   +
                 ***                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                 ***                    
+   +   +   +   +   +   +   +   +   +   +
             ***     ***                
+   +   +   +   +   +   +   +   +   +   +
         ***             ***            
+   +   +   +   +   +   +   +   +   +   +
     ***         ### ### ^~^ *** [ ]    
+   +   +   +   +   +   +   +   +   +   +
         ***             ***            
+   +   +   +   +   +   +   +   +   +   +
             ***     ***                
+   +   +   +   +   +   +   +   +   +   +
                 ***                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
             ***     ***                
+   +   +   +   +   +   +   +   +   +   +
         ***             ***            
+   +   +   +   +   +   +   +   +   +   +
     ***                     ***        
+   +   +   +   +   +   +   +   +   +   +
 ***             ### ### ### ^~^ [ ]    
+   +   +   +   +   +   +   +   +   +   +
     ***                     ***        
+   +   +   +   +   +   +   +   +   +   +
         ***             ***            
+   +   +   +   +   +   +   +   +   +   +
             ***     ***                
+   +   +   +   +   +   +   +   +   +   +
                 ***                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
         ***             ***            
+   +   +   +   +   +   +   +   +   +   +
     ***                     ***        
+   +   +   +   +   +   +   +   +   +   +
 ***                             ***    
+   +   +   +   +   +   +   +   +   +   +
                 ### ### ### ### ^~^ ***
+   +   +   +   +   +   +   +   +   +   +
 ***                             ***    
+   +   +   +   +   +   +   +   +   +   +
     ***                     ***        
+   +   +   +   +   +   +   +   +   +   +
         ***             ***            
+   +   +   +   +   +   +   +   +   +   +
             ***     ***                
+   +   +   +   +   +   +   +   +   +   +
                 ***                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Game Over ---
Ssslithered out with a full stomach!
============ Game Statistics ============
Totals:
  - Points: 20
  - Moves Made: 5
  - Number of Apples Eaten: 1
Completion:
  - Number of Apples Remaining: 0
  - Apple Completion Percentage: 100.0%
  - Maximum Points Remaining: 0
=========================================

Input:

a e 3 5 5
a r 7 3
s
1 2
s
d
s
d
s
d
s
s
s
a
a
[CTRL+D]

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
a e 3 5 5
a r 7 3
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     (3)                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             (R)                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 1 2
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ^~^                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     (3)                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             (R)                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ^~^                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     (3)                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             (R)                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ### ^~^                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     (3)                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             (R)                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ### ###                        
+   +   +   +   +   +   +   +   +   +   +
             ^~^                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     (3)                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             (R)                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ### ###                        
+   +   +   +   +   +   +   +   +   +   +
             ### ^~^                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     (3)                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             (R)                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ### ###                        
+   +   +   +   +   +   +   +   +   +   +
             ### ###                    
+   +   +   +   +   +   +   +   +   +   +
                 ^~^                    
+   +   +   +   +   +   +   +   +   +   +
                     (3)                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             (R)                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ### ###                        
+   +   +   +   +   +   +   +   +   +   +
             ### ###                    
+   +   +   +   +   +   +   +   +   +   +
                 ### ^~^                
+   +   +   +   +   +   +   +   +   +   +
                     (3)                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             (R)                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ### ###                        
+   +   +   +   +   +   +   +   +   +   +
             ### ###                    
+   +   +   +   +   +   +   +   +   +   +
                 ### ***                
+   +   +   +   +   +   +   +   +   +   +
                 *** ^~^ ***            
+   +   +   +   +   +   +   +   +   +   +
                     ***                
+   +   +   +   +   +   +   +   +   +   +
             (R)                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ### ###                        
+   +   +   +   +   +   +   +   +   +   +
             ### ### ***                
+   +   +   +   +   +   +   +   +   +   +
                 ***     ***            
+   +   +   +   +   +   +   +   +   +   +
             ***     ###     ***        
+   +   +   +   +   +   +   +   +   +   +
                 *** ^~^ ***            
+   +   +   +   +   +   +   +   +   +   +
             (R)     ***                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ### ###     ***                
+   +   +   +   +   +   +   +   +   +   +
             ### ***     ***            
+   +   +   +   +   +   +   +   +   +   +
             ***             ***        
+   +   +   +   +   +   +   +   +   +   +
         ***         ###         ***    
+   +   +   +   +   +   +   +   +   +   +
             ***     ###     ***        
+   +   +   +   +   +   +   +   +   +   +
             (R) *** ^~^ ***            
+   +   +   +   +   +   +   +   +   +   +
                     ***                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
a
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ###                            
+   +   +   +   +   +   +   +   +   +   +
         ### ###                        
+   +   +   +   +   +   +   +   +   +   +
             ###                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     ###                
+   +   +   +   +   +   +   +   +   +   +
                     ###                
+   +   +   +   +   +   +   +   +   +   +
             (R) ^~^ ###                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
a
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ^~^                            
+   +   +   +   +   +   +   +   +   +   +
         ### ###                        
+   +   +   +   +   +   +   +   +   +   +
             ###                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     ###                
+   +   +   +   +   +   +   +   +   +   +
                     ###                
+   +   +   +   +   +   +   +   +   +   +
             ### ### ###                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
[CTRL+D]
--- Quitting Game ---

Stage 4.2 - Ready Player 2

Our snake is feeling lonely, so let's give it a friend!

Except instead of a friend, we'll be adding a rival for our snake. The goal of the game now is for either snake to beat the other to the exit. As usual, the exit is only unlocked once all apples on the map have been consumed.

The first snake to slither out the exit wins! Unless one crashes and faints before that happens…

Task

In this substage, you will need to:

  • Modify your program so that when the user enters S during the Setup Loop, the loop is ended and:
    • The board is displayed as usual with the provided print_board() function.
    • The original snake is spawned as usual with the first Snake Spawning Loop.
    • The board is displayed as usual with the original snake.
    • Another Snake Spawning Loop runs, now for the rival (see below).
    • The board is displayed with both the original and rival snake. The rival snake should have a head that is printed as ^v^.
    • The Gameplay Phase begins as usual.
  • Make the second Snake Spawning Loop:

    1. Print the header: "--- Spawning Rival Snake ---\n".
    2. Prompt the user by printing: "Enter the rival snake's starting position: ".
    3. Once again, accept integer inputs in the format [row] [col] until a valid starting position is entered, and if invalid:
      • Print the appropriate error message specified in Stage 1.2.
      • Prompt the user for another starting position by printing: "Enter the rival snake's starting position: ".
    4. Otherwise, if the position entered is valid:
      • End the loop.
      • Print the board with both snakes now on the board.
      • Begin the Gameplay Phase.
  • Modify your Gameplay Loop to cycle between turns for the original snake and the rival snake.

    • The original snake should always have the first turn.
    • Only movement commands should count as a turn. This means the p command should not count as a turn for either snake (see clarifications).
  • Modify your program so that upon a win or loss condition:

    • Display the same win or loss message as described in Stage 2.4.
    • If the original snake ultimately wins the game, print "Original snake wins!\n".
    • Otherwise, if the rival snake ultimately wins the game, print "Rival snake wins!\n".
    • Print the final game statistics using the provided helper function print_game_statistics_with_rival().

// Prints statistics about the game for both snakes when there are two players
void print_game_statistics_with_rival(
    int original_points,
    int original_moves_made,
    int original_num_apples_eaten,
    int rival_points,
    int rival_moves_made,
    int rival_num_apples_eaten,
    int num_apples_remaining,
    double completion_percentage,
    int maximum_points_remaining
) {
    printf("============ Game Statistics ============\n");
    printf("Original Snake Totals:\n");
    printf("  - Points: %d\n", original_points);
    printf("  - Moves Made: %d\n", original_moves_made);
    printf("  - Number of Apples Eaten: %d\n", original_num_apples_eaten);
    printf("Rival Snake Totals:\n");
    printf("  - Points: %d\n", rival_points);
    printf("  - Moves Made: %d\n", rival_moves_made);
    printf("  - Number of Apples Eaten: %d\n", rival_num_apples_eaten);
    printf("Completion:\n");
    printf("  - Number of Apples Remaining: %d\n", num_apples_remaining);
    printf("  - Apple Completion Percentage: %.1f%%\n", completion_percentage);
    printf("  - Maximum Points Remaining: %d\n", maximum_points_remaining);
    printf("=========================================\n");
}

Assumptions / Restrictions / Clarifications

  • The row and col entered in the second Snake Spawning Loop will always be integers.
  • You can assume that there are always at least two valid positions to place both snakes when S is entered to end the Setup Phase.
  • The original snake's head has higher priority in printing than the rival snake's head if they are on the same tile.
    • This printing priority should only matter when the two snakes collide directly which leads to a game end (see Example 4.2.6).
  • If the rival Snake Spawning Loop is given the position where the original snake has been spawned, this should be considered as an occupied tile error (see corresponding error message in Stage 1.2).
  • When the reset command r is entered during either snake's turn:
    • The map and points should be reset as usual.
    • Both snakes should be returned to their initial spawn positions.
    • The turn counter should be reset to start with the original snake.
  • When the statistics command p is entered during either snake's turn:
    • The print_game_statistics_with_rival() function should be called to print the game statistics of both snakes.
    • This should not count as a turn for the snake.
  • If the game is played without a rival (i.e. the s command is used to end the Setup Phase), the win and loss output should remain the same as described in Stage 2.4.

Examples

Input:

w 5 5
S
1 2
5 5
-1 9
10 10
3 -99
1 2
3 4
[CTRL+D]

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
w 5 5
S
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     |||                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 1 2
--- Spawning Rival Snake ---
Enter the rival snake's starting position: 5 5
ERROR: Invalid tile, 5 5 is occupied!
Enter the rival snake's starting position: -1 9
ERROR: Invalid position, -1 9 is out of bounds!
Enter the rival snake's starting position: 10 10
ERROR: Invalid position, 10 10 is out of bounds!
Enter the rival snake's starting position: 3 -99
ERROR: Invalid position, 3 -99 is out of bounds!
Enter the rival snake's starting position: 1 2
ERROR: Invalid tile, 1 2 is occupied!
Enter the rival snake's starting position: 3 4
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ^~^                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ^v^                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     |||                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
[CTRL+D]
--- Quitting Game ---

Input:

S
1 1
7 8
s
w
d
a
s
a
d
a
d
w
[CTRL+D]

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
S
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 1 1
--- Spawning Rival Snake ---
Enter the rival snake's starting position: 7 8
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ^~^                                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                 ^v^    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ###                                
+   +   +   +   +   +   +   +   +   +   +
     ^~^                                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                 ^v^    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
w
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ###                                
+   +   +   +   +   +   +   +   +   +   +
     ^~^                                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                 ^v^    
+   +   +   +   +   +   +   +   +   +   +
                                 ###    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ###                                
+   +   +   +   +   +   +   +   +   +   +
     ### ^~^                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                 ^v^    
+   +   +   +   +   +   +   +   +   +   +
                                 ###    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
a
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ###                                
+   +   +   +   +   +   +   +   +   +   +
     ### ^~^                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                             ^v^ ###    
+   +   +   +   +   +   +   +   +   +   +
                                 ###    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ###                                
+   +   +   +   +   +   +   +   +   +   +
     ### ###                            
+   +   +   +   +   +   +   +   +   +   +
         ^~^                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                             ^v^ ###    
+   +   +   +   +   +   +   +   +   +   +
                                 ###    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
a
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ###                                
+   +   +   +   +   +   +   +   +   +   +
     ### ###                            
+   +   +   +   +   +   +   +   +   +   +
         ^~^                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                         ^v^ ### ###    
+   +   +   +   +   +   +   +   +   +   +
                                 ###    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ###                                
+   +   +   +   +   +   +   +   +   +   +
     ### ###                            
+   +   +   +   +   +   +   +   +   +   +
         ### ^~^                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                         ^v^ ### ###    
+   +   +   +   +   +   +   +   +   +   +
                                 ###    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
a
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ###                                
+   +   +   +   +   +   +   +   +   +   +
     ### ###                            
+   +   +   +   +   +   +   +   +   +   +
         ### ^~^                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     ^v^ ### ### ###    
+   +   +   +   +   +   +   +   +   +   +
                                 ###    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ###                                
+   +   +   +   +   +   +   +   +   +   +
     ### ###                            
+   +   +   +   +   +   +   +   +   +   +
         ### ### ^~^                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     ^v^ ### ### ###    
+   +   +   +   +   +   +   +   +   +   +
                                 ###    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
w
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
     ###                                
+   +   +   +   +   +   +   +   +   +   +
     ### ###                            
+   +   +   +   +   +   +   +   +   +   +
         ### ### ^~^                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                     ^v^                
+   +   +   +   +   +   +   +   +   +   +
                     ### ### ### ###    
+   +   +   +   +   +   +   +   +   +   +
                                 ###    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
[CTRL+D]
--- Quitting Game ---

Input:

a n 2 6
a n 6 4
a n 9 8
S
3 4
7 5
w
a
d
p
w
p
d
p
[CTRL+D]

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
a n 2 6
a n 6 4
a n 9 8
S
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                         (`)            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 (`)                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                 (`)    
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 3 4
--- Spawning Rival Snake ---
Enter the rival snake's starting position: 7 5
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                         (`)            
+   +   +   +   +   +   +   +   +   +   +
                 ^~^                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 (`)                    
+   +   +   +   +   +   +   +   +   +   +
                     ^v^                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                 (`)    
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
w
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ^~^     (`)            
+   +   +   +   +   +   +   +   +   +   +
                 ###                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 (`)                    
+   +   +   +   +   +   +   +   +   +   +
                     ^v^                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                 (`)    
+   +   +   +   +   +   +   +   +   +   +
a
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ^~^     (`)            
+   +   +   +   +   +   +   +   +   +   +
                 ###                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 (`)                    
+   +   +   +   +   +   +   +   +   +   +
                 ^v^ ###                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                 (`)    
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ### ^~^ (`)            
+   +   +   +   +   +   +   +   +   +   +
                 ###                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 (`)                    
+   +   +   +   +   +   +   +   +   +   +
                 ^v^ ###                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                 (`)    
+   +   +   +   +   +   +   +   +   +   +
p
============ Game Statistics ============
Original Snake Totals:
  - Points: 0
  - Moves Made: 2
  - Number of Apples Eaten: 0
Rival Snake Totals:
  - Points: 0
  - Moves Made: 1
  - Number of Apples Eaten: 0
Completion:
  - Number of Apples Remaining: 3
  - Apple Completion Percentage: 0.0%
  - Maximum Points Remaining: 15
=========================================
w
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ### ^~^ (`)            
+   +   +   +   +   +   +   +   +   +   +
                 ###                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ^v^                    
+   +   +   +   +   +   +   +   +   +   +
                 ### ###                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                 (`)    
+   +   +   +   +   +   +   +   +   +   +
p
============ Game Statistics ============
Original Snake Totals:
  - Points: 0
  - Moves Made: 2
  - Number of Apples Eaten: 0
Rival Snake Totals:
  - Points: 5
  - Moves Made: 2
  - Number of Apples Eaten: 1
Completion:
  - Number of Apples Remaining: 2
  - Apple Completion Percentage: 33.3%
  - Maximum Points Remaining: 10
=========================================
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ### ### ^~^            
+   +   +   +   +   +   +   +   +   +   +
                 ###                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 ^v^                    
+   +   +   +   +   +   +   +   +   +   +
                 ### ###                
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                 (`)    
+   +   +   +   +   +   +   +   +   +   +
p
============ Game Statistics ============
Original Snake Totals:
  - Points: 5
  - Moves Made: 3
  - Number of Apples Eaten: 1
Rival Snake Totals:
  - Points: 5
  - Moves Made: 2
  - Number of Apples Eaten: 1
Completion:
  - Number of Apples Remaining: 1
  - Apple Completion Percentage: 66.7%
  - Maximum Points Remaining: 5
=========================================
[CTRL+D]
--- Quitting Game ---

Input:

w 6 3
S
1 2
5 3
d
s

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
w 6 3
S
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             |||                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 1 2
--- Spawning Rival Snake ---
Enter the rival snake's starting position: 5 3
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ^~^                            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             ^v^                        
+   +   +   +   +   +   +   +   +   +   +
             |||                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ### ^~^                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             ^v^                        
+   +   +   +   +   +   +   +   +   +   +
             |||                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
s
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ### ^~^                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             ###                        
+   +   +   +   +   +   +   +   +   +   +
             ^v^                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Game Over ---
Guessss I was the prey today.
Original snake wins!
============ Game Statistics ============
Original Snake Totals:
  - Points: 0
  - Moves Made: 1
  - Number of Apples Eaten: 0
Rival Snake Totals:
  - Points: 0
  - Moves Made: 1
  - Number of Apples Eaten: 0
Completion:
  - Number of Apples Remaining: 0
  - Apple Completion Percentage: 100.0%
  - Maximum Points Remaining: 0
=========================================

Input:

e 3 4
a n 7 8
S
7 7
3 3
d
d

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
e 3 4
a n 7 8
S
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                 [X]                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                 (`)    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 7 7
--- Spawning Rival Snake ---
Enter the rival snake's starting position: 3 3
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             ^v^ [X]                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                             ^~^ (`)    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             ^v^ [ ]                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                             ### ^~^    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
             ### ^v^                    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                             ### ^~^    
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Game Over ---
Ssslithered out with a full stomach!
Rival snake wins!
============ Game Statistics ============
Original Snake Totals:
  - Points: 5
  - Moves Made: 1
  - Number of Apples Eaten: 1
Rival Snake Totals:
  - Points: 0
  - Moves Made: 1
  - Number of Apples Eaten: 0
Completion:
  - Number of Apples Remaining: 0
  - Apple Completion Percentage: 100.0%
  - Maximum Points Remaining: 0
=========================================

Input:

S
3 2
3 6
d
a
d
a

Input and Output:

dcc cs_snake.c -o cs_snake
./cs_snake
Welcome to CS Snake!

--- Map Setup ---
S
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Spawning Snake ---
Enter the snake's starting position: 3 2
--- Spawning Rival Snake ---
Enter the rival snake's starting position: 3 6
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ^~^             ^v^            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Gameplay Phase ---
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ### ^~^         ^v^            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
a
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ### ^~^     ^v^ ###            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
d
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ### ### ^~^ ^v^ ###            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
a
+---+---+---+---+---+---+---+---+---+---+
|            C S _ S N A K E            |
+---+---+---+---+---+---+---+---+---+---+
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
         ### ### ^~^ ### ###            
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
                                        
+   +   +   +   +   +   +   +   +   +   +
--- Game Over ---
Guessss I was the prey today.
Original snake wins!
============ Game Statistics ============
Original Snake Totals:
  - Points: 0
  - Moves Made: 2
  - Number of Apples Eaten: 0
Rival Snake Totals:
  - Points: 0
  - Moves Made: 2
  - Number of Apples Eaten: 0
Completion:
  - Number of Apples Remaining: 0
  - Apple Completion Percentage: 100.0%
  - Maximum Points Remaining: 0
=========================================

Autotest

Testing & Submission

Are you finished with this stage? If so, you should make sure to do the following:

  • Run 1511 style, and clean up any issues a human may have reading your code. Don't forget -- 20% of your mark in the assignment is based on style!
  • Autotest for this stage of the assignment by running the autotest-stage command as shown below.
  • Remember -- give early, and give often. Only your last submission counts, but why not be safe and submit right now?
1511 style cs_snake.c
1511 autotest-stage 04 cs_snake
give cs1511 ass1_cs_snake cs_snake.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 Snake, 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_snake.c code.

ls
cs_snake.c 
cs_snake 
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 Stage 2.1 onwards).

Your file could look a bit like this:

w 1 5
a n 3 2
e 5 2
s
2 4

3. Run the code with your file

Next, instead of just running ./cs_snake, lets tell the computer to first read from the file we created.

If you have completed Stage 2.1 then use the following:

cat my_level.in - | ./cs_snake

Otherwise, use the following:

cat my_level.in | ./cs_snake

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_snake
cd cs_snake

Set up your directory for SplashKit with:

1511 setup-splashkit-directory

Run this cp command to retrieve the sample code.

cp -n /web/cs1511/25T3/activities/cs_snake/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_snake.c.

To compile and run your program, use:

skm clang++ splashkit_cs_snake.c -o splashkit_cs_snake
./splashkit_cs_snake

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




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_snake.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_snake cs_snake.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_snake.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 27 October 2025 17:00:00. For each day after that time, the maximum mark it can achieve will be reduced by 5% (off the ceiling).
  • For instance, at 1 day past the due date, the maximum mark you can get is 95%.
  • For instance, at 3 days past the due date, the maximum mark you can get is 85%.
  • For instance, at 5 days past the due date, the maximum mark you can get is 75%.
No submissions will be accepted after 5 days late, unless you have special provisions in place.

Change Log

Version 1.0
(2025-10-07 09:00)
  • Assignment released