C代写:COMP2129 Atoms

代写一个叫Atoms的棋盘游戏,根据操作菜单,实现游戏的各类逻辑。

Task Description

This assignment is based on a game called Atoms. You will be tasked with writing this game in the C programming language with dynamic data structures.

This game revolves around placing atoms on a gridded game board. Each grid space has a limit of how many atoms it can contain. Once the limit is reached, the atoms will expand to the adjacent spaces. This creates an interesting property in the game where chains can be triggered by a single placement.

The game will be accompanied by a number of utility functions for players to utilise such as saving, game statistics and loading. You will also need to implement a set of commands that will allow the players to interact with the game.

In summary:

  • There is a game board that is n x m grid spaces.
  • There is a minimum of 2 players and a maximum of 6.
  • Initially a grid space is unoccupied until a player places an atom in that grid space.
  • A player can place an atom in a grid space owned by them or that is unoccupied.
  • Once a grid space has hit its limit (number of atoms == limit), a single atom will expand out to the adjacent grid spaces.
  • After the first k moves players can be removed from the game if they no longer own any grid spaces that player is then to be removed from the game.
  • The user interacts with a set of commands that are specified later in this document
  • The player colour order is RGPBYW (Red, Green, Purple, Blue, Yellow, White).

Working On Your Assignment

You can work on this assignment on your own computer or lab machines. It is important that you continually back up your assignment files onto your own machine, external drives and/or the cloud.

You are encouraged to submit your assignment on Ed while you are in the process of completing it. By submitting you will obtain some feedback of your progress on the sample test cases later provided.

During the practical assessment session you will only be able to submit your final solution within the time period allocated. You will be required to submit your assignment on Ed.

Implementation Details

Write a program in C that implements the game atoms. The sample test cases on ed will only contain valid input command, it is up to you to handle any invalid input. Commands are case sensitive.

Game rules and features:

  • There are k players and each player takes a turn starting from player 1. there is a minimum of 2 players and a maximum of 6 players per a game
  • A player can place an atom on a grid space that they already own or is unoccupied
  • If the grid space is a corner, then the limit is 2
  • If the grid space is on a side then the limit is 3
  • If the grid space is neither a corner or a side space then the limit is 4
  • (The pattern is the adjacent grid spaces)
  • When a grid has reached its limit, the atoms will expand into the adjacent places. This can trigger other grids to reach their limit and expand.
  • Players can undo moves that they have performed
  • The maximum width of the board is 255, the minimum width is 2
  • The maximum height of the board is 255, the minimum height is 2
  • You may assume the maximum line length is 255
  • There is an option to save the game and load it when the program has been reloaded

Save file specification is specified below.
The file header contains: 1 byte for width 1 byte for height 1 byte for player
After the header, the move data will fill the rest of the file until the end of the file.
Each move is encoded by 4bytes, First 2 bytes are used for coordinates where the empty two bytes encoded by 0 padding.

Below we have specified a header file with the structs that we suggest you use. You may modify these structs to suit your need.

Commands

HELP

Provides list of commands

HELP displays this help message
QUIT quits the current game

DISPLAY draws the game board in terminal
START <width> <height> <number of players> starts the game
PLACE <x> <y> places an atom in a grid space
UNDO undoes the last move made
STAT displays game statistics

SAVE <filename> saves the state of the game
LOAD <filename> loads a save file
PLAYFROM <turn> plays from n steps into the game

START [k] [width] [height]

The start command will accept 3 arguments, first argument is how many players are going to be in the game.
The next two are the dimensions [width] and [height] of the gameboard.
This command needs to check the width * height >= n (number of players). Otherwise the program should respond with:

Cannot Start Game

If any of the input is invalid (width or height or n) are negative digits or character values, the program should respond with

Invalid command arguments

If the argument length is less than the required number (3) the program should specify

Missing Argument

The number of arguments is greater than the required number the program should respond with

Too Many Arguments

The START command cannot be used after the START command has been successfully executed. If this case is presented the program should respond with

Invalid Command

When START command is successfully executed the program should respond with, the colours are assumed to be in this order: RGPBYW (Red, Green, Purple, Blue, Yellow, White)

Game Ready
Red's Turn

STAT

Displays the current state of the game
STAT cannot be executed unless a game has been started, if it is executed in this state the program should respond with

Game Not In Progress

When executed successfully the STAT command should display the current statistics related to the players.

Player Red:
Grid Count: 5
Player Green:
Grid Count: 2

In the account where a player has given up or has been removed from the game the STAT command should show. (In this example Player P gave up).

Player Red
Grid Count: 5
Player Green:
Grid Count: 3
Player Purple:
Lost

When printing out the the players, it will be from first index to last. The player colours are in the order: RGPBYW (Red, Green, Purple, Blue, Yellow, White).

PLACE [x] [y]

Places an atom at an x, y position on the game board that is associated with the player’s turn
If the argument length does not equal two then the program should output Invalid Coordinates
If the x value is less than 0 or greater than or equal to the width and/or If the y value is less than 0 or greater than or equal to the height then the program should output

Invalid Coordinates

If the grid space selected is not owned by the player or is not unoccupied

Cannot Place Atom Here

In the case that PLACE command has not be executed successfully, the program should be ready for another command.

PLACE -1 -1
Invalid Coordinates
PLACE 0 0
Red's Turn

On success, the program should respond with whose move is next
PLACE 2 1
Red’s Turn
In relation to expansion (when the grid space has reached its limit), the expansions move clockwise starting with the grid space that is y-1.
After a PLACE command is entered and only one player is remaining after it successfully executes, the program should respond with and quit:

PLACE 5 4
Red Wins [program ends]

DISPLAY

Displays the gameboard using + to denote the corner and two - to denote the colour and the number of atoms located. Example Output

+--------------------+
|R1|  |  |  |  |  |  |
|  |  |  |  |  |  |  |
|  |G1|G3|  |  |  |  |
|  |  |  |  |  |  |  |
|  |  |  |R1|  |  |  |
+--------------------+

Empty spaces denote unknown grid spaces while [colour][number] (R1) denote the owner and the number of atoms in that grid space.

UNDO

Once a player has made a move, it is up to the will of the next player to let the other player undo it. We are to pretend that this game involves hotseating and therefore it is agreed upon the players if they are to allow an undo.

In the case that we perform UNDO at start of the game, the program should output

Cannot Undo

QUIT

Quits the game early

QUIT
Bye!

This quits the game early.

SAVE [filename]

Save the current state of the game with a filename
You will need to adhere to a strict file structure, the file is saved as a binary file. Where game information is stored in the header of the file and the leading data is the move set.
After the header has been read, the rest of the file can be assumed to be raw_move_data, each move is encoded as a 32bit integer (4 bytes). Each 32bit integer can be extracted as x (1 byte), y (1 byte) coordinates with 2 bytes of 0 padding afterwards.
When creating a save file, we do not need to include any move that has been undone.
This command creates a file and saves the current game details and move set, if a file already exists with this name the function should reject the save file.

File Already Exists

On success the program should output

Game Saved

LOAD [filename]

Load command takes a filename as an argument, if that file does not exist the program should remain in its original state and output.

Cannot Load Save

If a game has already started or load has been executed successfully, subsequently load commands should not attempt to load a new game and instead the program should respond with:

Restart Application To Load Save

If the command is executed successfully the program should respond with:

Game Loaded

If any other command besides QUIT or PLAYFROM after the LOAD command has been executed successfully, the program should output:

Invalid Command

PLAYFROM [turn]

This command allows the user to play from a turn n when a file has been loaded.
If the turn specified is greater than the number of turns loaded from the file the program should consider this as the last turn or if the turn argument is instead “END”

PLAYFROM END
Game Ready
Yellow's Turn

If the turn specified is less than 0

Invalid Turn Number

If PLAYFROM is executed prior to a LOAD command the program should ignore it and respond:

Invalid Command

If the turn specified is greater 0 and less and equals than the number of moves made, the program should output that the game is ready and what player’s turn it is.

Game Ready
Yellow's Turn

Writing Test Cases

Samples testcases will be made available but these do not test the entirety of the program specification. You will need to write your own test cases to ensure that your program covers as many cases as possible.
Test cases should be placed in the tests/ directory provided with the code scaffold. You need to provide input and output files. Typically this is in the form of testcase.in (for input) and testcase.out (for output).
Try to name your test cases to be brief but descriptive of the case they are testing.