Introduction
:
#ifndef ATOMS_H
#define ATOMS_H
#include
#define MAX_LINE 255
#define MAX_PLAYERS 6
#define MIN_PLAYERS 2
#define MAX_WIDTH 255
#define MAX_HEIGHT 255
#define MIN_WIDTH 2
#define MIN_HEIGHT 2
typedef struct move_t move_t;
typedef struct player_t player_t;
typedef struct game_t game_t;
typedef struct grid_t grid_t;
typedef struct save_file_t save_file_t;
struct save_t
{
char filename;
save_file_t data;
};
struct move_t
{
int x;
int y;
move_t parent;
move_t extra;
player_t old_owner; //NULL if unoccupied
};
struct player_t
{
char colour;
int grids_owned;
};
struct game_t
{
move_t moves;
};
struct grid_t
{
player_t owner;
int atom_count;
};
struct save_file_t
{
uint8_t width;
uint8_t height;
uint8_t no_players;
uint32_t raw_move_data;
};
#endif
,
Requirement
COMP2129 Assignment 2
Atoms
Assignment Due: 8:00am Monday, 10 April, 2017
Morning Practical assessment to take place: 9:00am Monday, 10 April, 2017
Afternoon Practical assessment to take place: 4:00pm Monday, 10 April, 2017
This assessment is worth 8% of the course
Completion of this assignment alone counts towards 3% of your grade
Task Description
This assignment is based on a game called Atoms. You will be tasked with writing this game in the C program-
ming 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).
1
COMP2129 Atoms
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.
Academic Declaration
By submitting this assignment you declare the following:
I declare that I have read and understood the University of Sydney Academic Dishonesty and Plagiarism in Coursework Policy, and except where
specifically acknowledged, the work contained in this assignment or project is my own work, and has not been copied from other sources or been
previously submitted for award or assessment.
I understand that failure to comply with the the Academic Dishonesty and Plagiarism in Coursework Policy, can lead to severe penalties as outlined
under Chapter 8 of the University of Sydney By-Law 1999 (as amended). These penalties may be imposed in cases where any significant portion of my
submitted work has been copied without proper acknowledgement from other sources, including published works, the internet, existing programs, the
work of other students, or work previously submitted for other awards or assessments.
I realise that I may be asked to identify those portions of the work contributed by me and required to demonstrate my knowledge of the relevant material
by answering oral questions or by undertaking supplementary work, either written or in the laboratory, in order to arrive at the final assessment mark.
I acknowledge that the School of Information Technologies, in assessing this assignment, may reproduce it entirely, may provide a copy to another
member of faculty, and or communicate a copy of this assignment to a plagiarism checking service or in house computer program, and that a copy of
the assignment may be maintained by the service or the School of IT for the purpose of future plagiarism checking.
Operating Systems and Machine Principles Page 2 of 13
COMP2129 Atoms
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 hea㩥㱲⽮㹴ൡ੩䱮㰱⁹⽴㹥ഠ੦⁴⁴Ⱐ†⁴†⁴㩨㱥⽬㹥ഠੵ䝴䉬⡥Ɽ†䝯ⱥ†Ɫ䈠Ⰺ⁅ⱶ⥮㱯⼠㹢൹ਠ⁹†䵡㘠⁷ㅥ㌠㱴†⽥㹭൰ੴ䍹䵴㉯ㄠ㉢㥹⁴䅥㱣⽤㸠ൢ䱢䅲䌠䔯‾㰍†⽰㹡‾††ⱡ⁶††⁴⁴†⁵♵㭯†㱭⽦㹹ഠੴ䥨⁴††††⁔†䥣䌠㰠⽲㸠യਾ䤍⁏ど⁐″″′⼠䥭‼ ‼‾の†㰼†⼯㸾ਊ† ‾‼ 㰵⽲㸠യਾ䤍䍥㱒‶⼼㹢൲ਠ䤯†⁌ ‣⁁⁉‵‾㱈⁇⽈㹔ഠਲ䌵 䅦†䡍㱗⁔⽈㸠ല਼䥢† ⁉䱟䅈䍅䕉⁇† ⰻ‼ ⁵†⁰㰻⼠㸯ാ㰠⽵㹣൴ਠ䱡䅭䍥䕟⁴ⴠㅧㅥ㱟‼⽢㹲ഠਯ䤾䍥㱲 ⽴㸠൧ੲ䱤䅟䍴䔻‼ぢ〠㰯 ⽴㹹൰☠㭴㱦⽟㹴ഠੳⰻ‼ 㰍⽶㹥ൟ੦䱬䅥䍟䕴†㉤ㅴ㱡⽲㸠യਾ☻㬾 㱣⽯㹶䥴⁻† ⡩※†† ⤠ⱥ⁸※⁴㰠†⽵㹮൯ †⁵ㄠ㱬⽲㹟൴ਠ䅻 䱣䅨䍡䕲†‼††‼ ‼ ⱥ㰼†⼯㸾ਊ†⁻ ⁰㩲㱟⽷㹮ੲ䰼䅢䍲䔠 㔾㐊㱩†⽡㹴൯੭⁵㱢 ⼾㸍ഊ䐻䤼䰠䄯㰍⁴⽲㹵ൣੴ䐠†⁵⁴⬠⁷⁴ ⁵†‼♢㬊⁵⁴ ⁹ 㱤⼻㸼ൢੲ⸼䕲㱲‾⼍㸊൏ੰ⭥♲㬠♓㭳☠㭡♣㭐♲㭬♥㭥☠㬱⬳㰼†⼯㸾ਊㅍ′′†⁴‼㱲‾⼍㸊ൃ੯†‾ 㱅‼⽢㹲ഠਯ䝐ㅲ䝶㍩†⁴㱯⽯㹭൭‼ ⁈⁌㰠⽰㹬ൡ†ㅥ⁰㱡‼⽢㹲ഠਯ⬾☍㬠♱㭴♨㭲♥㭭♥㬾☍㭌♁㭷⭳㰠⼠㹧ൡ੭䕥‼⁓††⡭ㄼ⥢⁌††㱤⁰⽡㹣਼⁎†㱳⽯㹶ਠ‾䵡 㜾⁁ㅖ㍅㰠⁶⽥㹳ഠੴ䍨䴠㉴ㅡ㉴㥥†䅯㱥⽭㹥഼䰠䄯䌾䔍 㱤⼠㹳ൡ੶䰠䅦䍩䕬〼ひ㰠⼊㹐ൌੁ䝙☠㬠㰠⽰㹳ഠ੩䑮䥴䱴䅨㰠⽥㸼ൢੲ⬠☯㭁♒㬠☯㭥☠㬠♣㭤☠㭡♣㬳⬠㱡⁵⽭㹥൮ੴㄠ†⁵㱴⼠㹨൯†⁹†㱲⽯㹩൮੧⁴†††㱡⼼㹢൲ਠ‾ †⁴⁴㱯⽥㸠൴੨†㱤⼠㹴൨⬠♧㭡♲㬠☯㭩♳㭡♮㭤♳㭨♥㭥⬠㱷⁴⽨㸠൨䱧䅨䍴䔠‾㈽†の㰠⁵⽭㹢ੲ☠㭲
㱨⁷⽩㹳ਠ䑴䥨䱰䅲㱧⼠㹳൨੯♬㬯☾㭰♯㭴♨㬯☾㭮♯㭲♴㬼⭢㱲‾⼍㸊੦ㅮ†䝦ㄠ†⁵㰠†⽩㹮൶†⁷†㱥⽴㸠൯ੲ††㱥⽧㹩൴ੳ††㱡⽳㸬ഠੴ⁰㱬⽲㸠യਾ⬍☊㭮♤㬼♢㬊♉㭤☠㭮♤㭭♥㭲⬠㰯 ⽉㹦ഠੴ䱥䄠䍡䕲ふづ㱮⽥㹮൧ੴ䝨♬㭨㰠ⁱ⽵㹩൲䑤䤠䱭䅢㱲″⼩㸠൴੨⭥☠㭡♭㭬♤㭩♦㬯☾㭳♩㭧♵㭢⭲㰠⼊㹔൨ㅢ䝲ㄠ㱮†⽩㹳ഠ੧ㅡ†⁴㱲⁵⽩㹲††㱧⼠㹳൨੯†⁰†㱨⼠㸯ാ⁔⁍†⁵㱥⼼㹢൲ਠ⬯☾㬠♓㭣♯㬠♣㬠♢㭤☠㬠♴㭁⭒㱔⽭㹭ൡ੮䥨㱳⽥㹮ഠੳ䉵Ⅵ㱳⁵⽬㹬൹ਠ䱸䅥䍣䕵⁴づ〮㰠†⽴㹨൩ੳ䜠☼㬍㱥⽴㹥ਠ䑴䥨䱰䅲㱧⼠㹳൨੯♬㭰♯㭴♨㬾☍㭬♩㭭♡㬠☯㭥⭮㰠⁁⽒㹔ഠㅭ†㱳⽬㹹ഠ⁵††㱧⼠㹳൨੯†⁰†㱨⁴⽨㹥ഠ⁵㱭†⽴㹯഼†‾ †㱳⽤㹥൲⬠♒㬠☨㭇♲㭐♵㬠♂㭙♥㬠♗㬼⭢㱲‾⼍㸊േ䱥䄠䍒䕥㉤⁹〼㱢 ⼾㸍ഊ♲㭳⁔㱢 ⼾㸍ഊ䑰䥥䱴䅩㱧⁹⽳㹴੭⭳☠㭡♣㭐♲㭬♥㭥☠㬱☳㬾☍㬲⬱㰲⁁⽴㹯൭ੳㅲ 䜍ㄊ⁔⁔†㰾⁄⽩㹳൰੬⁹††⁵㰠⽴㹥ഠ੯†††㰾⁓⽔㹁ൔਠ⁴†⁸㱴†⽵㹮൬††㱥†⽳㹴ൡੲ♥㬠♩㭥♸㭤☠㭩♳㭥☠㭲♯㭳⭨㱯⼼㹢൲ਠ䰾䄍䌊䕲び⁰は㱮⁷⽩㹴൨਼䝢☍㬠㰠⽧㹲ੳ䑳䤼䰠䄯㰍⽥㹮ഠ⭸♥㬠♳㭳♦㭴♨㭔☠㭮♤㭬♤㭬⭡㱹⽥㸠ൣੵㅴ䝳ㅴ⁴㱲⽴㹥ਠㄠ†⁹㱢 ⼾㸍ഊ†›†㰾⁇⽲㹩ਠ›‵†‾㰊⽹㹥൲ਠ›†‾ 㱲†⽃㹯൵੮☺㬠☯㬠♴㭣♯㭨♥㭰♬㭨♡㭥⭮㰠†⽯㹲ഠ੨䱳䄠䍢䕥㉮†ひ㱥⁶⽥㹤ഠ੦☠㭡㰠⁁⽔㸠ൣ੯䑭䥭䱤䄠㱨⽤㸼ൢੲ⬠☯㭯♷㬠♴㭸♡㭐♬㭐☠㭵♰㬠⬯㰾⁐⽬㹡൹†ㅤ䝢㉲ ⁇㰠⁵⽮㹴ഺਠㅢ†‾ ⁹㱇⽮㸺഼†‾ ⁃⁵㱴″⼼㹢൲ਠ‾ ⁹⁐㱬†⽧㹡൭⁴㱥⽯㹧൲⭭☠㭤☠㭮♤㬺☼㬍☊㭲♴㭩♣㬠⭔㱯⽡㹤ഠ†䵡㡵†ㅴ㍨㱥⽯㹧൲䍭䵳㉯ㅵ㉬㥤†䅲㱮⁷⽩㹴൨䱢䅲䌠䔯‾ㄍ ぇ㱡†⽌㹯ൡ䝥☠㭦㱴⼠㹣൯੭䑭䥡䰠䅢㱳⽳㸠⭉♔㭌♁㬠♡㭴♨㭄☠㭮♤㭢♥㭥⭣㱵⼠㹳൵㉦䝬㉬†‾㰊⼠㹰൲੯ㅡ†⁵⁴㱵‼⽢㹲ഠਯ⁉⁶⁃㱡‼⽢㹲ഠਯ⁏⁓㱳⽳㸠ൡ੮††㱩⽳㸠⭧♥㭦☠㬠☯㭍♐㭁♴㭲☠㭌♁㬠⬼㱢 ⼾㸍ഊ䱩䅳䌠䕣㉭ち㱮⽬㹬൯♨㭲⁴㱡⽲㹯൭ਠ䑡䤠䱲䅮㱮⽥㹮ഠ⬠♦㭡♳㬠♬㬮☼㬍☊㭥☠㭳♰㭥⭤㰠†⼾㸠൴੨䜠ㅮ䝥ㅲ䝯ㅦ⁴㱬⽥㹤ഠ੦ㅭ䝴ㅨ䜠ㅦ††㱲⽡㹭ഠੳ†㱴⼠㹡൳ਠ†⁴†‾㰊⽮㸠൯ੲ††⁵㱧⽮㹴ഠ੩⭳☠㭡♤㭵♯㭲♤㭢♲㭐♌㭍☠㭲⬠㰯 ⽇㹡൭䱒䅥䍡䕤⁹〼ㅲ㰠⼊㹙੬☦㬻†㰼†⼯㸾ਊ䑉䥦䱨䅥㱴⼠㹳൰⭣♩㭩♳㭤☠㭥☠㭲☠㭶♥㭥☬㭰⭲㱯⽭㸠൳੨䝵ㅬ†䝵ㅴ䝵ㅴ⁴†㱨⽡㹭ਠ㈠䝥ㅡ䝹ㄼ 㱤⽡㹴ഠੰ…⁵※†㱵†⽩㹴ഠ੩†‾ 㱒⽹㸼ൢੲ ⁙…㱵⼠㹔൵ੲ⭮☼㬍☊㭴♩㭳♴㭮♤㭩♮㭮♣㬠⭐㱡†⼱㸲ഠ੯䰠䄱䌳䔼ひ†〯㰾⁃⽏㹍ਲ䜱⁴㱢 ⼾㸍ഊ䥴㱮⁔⽥㹳൴ਠ䉃Ⅵ㱳⼠㸯ാ⁴䵬†㥴ㄠ㍤㱯⽴㸠൴䍳䴠㉨ㅥ㈠㥥䅴㱹⼠㹴൨䑲㱧⼠㹳൰⁴ ⱥ⁴⁷⁴⁹†⁴⁴⁹††⁹㰠†⽰㹯൳ੳ‾⁰⁰††⁰㱶⼠㹩൮ੰ㰠⼊㹡൮䐠䥯䱰䅵㰠⽥㹳മਠ⭔♹㭬♹㬠♩㭴♨㭭☮㭥♳㬮♩㭲⬠㱩⁵⽴㸩ഠ⁴⁵㰠⽲㸠൯ੵ⁰⁴ㅲ ⁔㱹⼠㹮ൡ੭†䝯ㅵ†⁴㱳⼠㹢ਠ†⁵†㱩⽶㹥ഠ੯††ㅳ†⁹㱡†⽴㹥൳ੴ⭩♮㬠☯㭢♭㭮☠㭬♳㬾☍㭭♵㭢⭭㱩⁹⽯㹵൲ਠ䱯䅤䍥䔠⁰㉲ㅯ㱲⼠㹴൨♥㭲㱬⽳㹥൳ੳ⭭♥㭯♵㭲♥㭤☠㭴♥㭥☠㭩♣㬠⬯㰾⽳㹳ੳ†⁍㰠⽫㸠ശਠ‹‰䉡ㅭㅯ⁹†㰰⁰⽲㹩൬⁴䜠ㅣ⁴†㰠⽩㹧൮੭†‾ 㱲⽤㹥ഠ⁴ㄠ⁵⁴㰠⽭㹩൴ੴ⭥♤㭧☠㭯♵㭵♰㭹♯㭬♥㭴♨㭥⭳㱳⽴㸠൰䐠㱦⽥㸼ൢੲ䈠☊㭰㱡⽳㹳൭⭮♴㬯☾㬠♡㭣♯㭤☠㭢♭㭬♴㭴⭩㱭†⽢㹵൴ਠ⁹⁹⁵†⁴㱳⽩㹳൳੩⁷ㅢ†㱤⽲㸠യਾ 䝡ㅲ†‾㰊⁵⽲㸠൰ੲ††㱡⽤㸠ൡੵㅬ⁹†㱤⁐⽬㹥ൡੳ⭥☠㭥☠㭹♯㭥♦㭦♯㭴♨㭩♧㬼⭢㱲‾⼍㸊൳ੰ䥥䑭⁴†⁸⁴⁴Ⱪ⁴㱴⽳㹥൳ਠ䍯‼㰾″⼠㹭ൡੲ䤠㱲⽳㹳൩੧†⁵㱩⁴⽥㹳൴ੳ䥯㰠⽲㹥ൣੴ䉮ⅳ㰠†⽹㹯൵ੲ㱥⽳㹩൧੮†䵴ㄠべ†ㅰ㍲㱯⽭㸠൩੮䌠䵨㈠ㅰ㉲㥡䅴㰠⽥㹳൳੭䅮䔼㱲‾⼍㸊൳†⁁††㱩⁵⽰㹴ഠੴ⁵⁴†Ⱐ⁴ †㱥⽦㸠൹੯⁰⁷⁵†⸊㱣⼠㹩൳ਠ㱡⽹㸠൯⁰㱲⽮㹧ഠ㡭㭣㱨⼠㹐൲੩㡬†㬳㰠†⼱㸳഼㠍㭰㰻⁰⼾㸀ഀ㌀㈀ 㬀㰀 ⼀㸀ഀ㬀㰀 ⼀㸀ഀⰀ Ⰰ ㌀ Ⰰ 㰀 ⼀㸀ഀ Ⰰ ⸀㰀 ⼀㸀ഀ䄀 Ⰰ Ⰰ 㰀 ⼀㸀ഀ ㌀㈀ ⠀㐀 ⤀⸀ 䔀 ㌀㈀ ⠀ ⤀Ⰰ ⠀ ⤀ ㈀㰀 ⼀㸀ഀ ⸀㰀 ⼀㸀ഀ Ⰰ ⸀㰀 ⼀㸀ഀ Ⰰ 㰀 ⼀㸀ഀ ⸀㰀 ⼀㸀ഀ䘀 䄀 䔀㰀 ⼀㸀ഀ 㰀 ⼀㸀ഀ䜀 㰀 ⼀㸀ഀ䰀䄀䐀 㰀 ⼀㸀ഀ䰀 Ⰰ 㰀 ⼀㸀ഀ ⸀㰀 ⼀㸀ഀ䌀 䰀 㰀 ⼀㸀ഀ䤀 Ⰰ 㰀 ⼀㸀ഀ