Task description
In this assignment, we will develop a game controller that accommodates a two-player board game called Gomoku1 in the Mist. The controller should be programmed in the C programming language without using dynamic memory. And always ensure that no memory errors occur.
subcategory. As with any assignment, make sure that your work is your own , and that you do not share your code or solutions with other students.
Before attempting this assignment it would be a good idea to familiarise yourself with arrays, standard I/O and C strings. In particular, you may find the following functions helpful:
fscanf()
fgets()
Rules of the Game
Gomoku or Five in a Row is played on a 19×19 Go board (See Figure 1). The game starts with an empty board, and players Black and White alternate to place a stone of their colour on a grid point. Black goes first. The goal of the game is to create a line of five or more stones of your own colour, either horizontally, vertically or diagonally. The first player to achieve that goal wins (See Figure 2. If neither player creates five in a row when the board is full, then the game is a draw. The game finishes when a player wins, a player resigns or they draw.
You are encouraged to ask questions on Ed . Make sure your question post is of "Question" post type and is under "Assignment" category→"A1" subcategory "D→ebugging"/"Spec"/"General" sub-
Gomoku in the Mist is a new game based on Gomoku. It inherits all the rules from Gomoku and it introduces a game component called Mist. Mist blocks the visibility of both players and it covers the whole board except a 7 × 7 square hole (See Figure 3). Players can only see through the hole that is not covered by the Mist, however, the placement of stone is not blocked by the Mist at all. If the centre of the hole is so close to the border of the board that the hole cannot fit into the board, simply ignore the part that cannot fit.
Initially, the hole of the Mist locates at the centre of the board before the first move. The Mist (hole) changes after every placement of a stone. The position of hole depends on the previous placement of a stone. If a numerical coordinate system is used, the following rules apply:
% is the modulo operator.
xmist =1+(5x2 +3xstone +4)%19, stone
ymist =1+(4y2 +2ystone −4)%19. stone
(xmist, ymist) denotes the position of the hole’s centre, and (xstone, ystone) denotes the position of the previous placed stone.
To denote position on the board, a coordinate <C><R> can be specified. While it is natural to utilise a 19 × 19 purely numerical coordinate system, the Go style system is preferred. In particular, for a Go coordinate <C><R>, <C> is a column character ranging from A (the first English upper letter) to S (the nineteenth English upper letter); <R> is a row number ranging from 1 to 19.
Functionalities of the Game Controller
The Game Controller is a command prompt that supports the following commands:
who
term
resign
view
place <C><R> history
Note that a new game should be automatically started when the game controller is launched, and the game controller should terminate when a game is finished or the controller is forced to terminate.
In a numerical coordinate system, columns are denoted by numbers instead of characters. In particu- lar, the n-th English upper letter is equivalent to a number n. E.g. Column character A is equivalent to column number 1. See the numerical numbering in Figure 1.
Commands are case-sensitive and whitespace-sensitive. The game controller will reject unspecified commands or known commands with unspecified trailing whitespaces or parameters. The only com- mand that accepts a parameter is place and it can only be supplied with one parameter. The game controller should output Invalid! if it rejects the user input.
numerical:
19 . . . . . . . . . . . . . . . . . . . 18 . . . . . . . . . . . . . . . . . . . 17 . . . . . . . . . . . . . . . . . . . 16 . . . . . . . . . . . . . . . . . . . 15 . . . . . . . . . . . . . . . . . . . 14 . . . . . . . . . . . . . . . . . . . 13 . . . . . . . . . . . . . . . . . . . 12 . . . . . . . . . . . . . . . . . . . 11 . . . . . . . . . . . . . . . . . . . 10 . . . . . . . . . . . . . . . . . . . 9 ................... 8 ................... 7 ................... 6 ................... 5 ................... 4 ................... 3 ................... 2 ................... 1 ...................
ABCDEFGHIJKLMNOPQRS 1 2 3 4 5 6 7 8 9 ...................
Figure 1: An ASCII art of the Go board grid points with axes numbering
19 # # # # # . . . . . . . . . . . . . . 18 o o o o . . . . . . . . . . . . . . . 17 . . . . . . . . . . . . . . . . . . . 16 . . . . . . . . . . . . . . . . . . . 15 . . . . . . . . . . . . . . . . . . . 14 . . . . . . . . . . . . . . . . . . . 13 . . . . . . . . . . . . . . . . . . . 12 . . . . . . . . . . . . . . . . . . . 11 . . . . . . . . . . . . . . . . . . . 10 . . . . . . . . . . . . . . . . . . . 9 ................... 8 ................... 7 ................... 6 ................... 5 ................... 4 ................... 3 ................... 2 ................... 1 ...................
ABCDEFGHIJKLMNOPQRS
Figure 2: An ASCII art of the Go board when Black stone wins, where #, o ,. represents Black
stone, White stone and no stone (empty).
Systems Programming Page 3 of 13
19 @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ 18 @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ 17 @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ 16 @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ 15 @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ 14 @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ 13 @ @ @ @ @ @ . . . . . . . @ @ @ @ @ @ 12 @ @ @ @ @ @ . . . . . . . @ @ @ @ @ @ 11 @ @ @ @ @ @ . . . . . . . @ @ @ @ @ @ 10 @ @ @ @ @ @ . . . A . . . @ @ @ @ @ @ 9 @@@@@@.......@@@@@@ 8 @@@@@@.......@@@@@@ 7 @@@@@@.......@@@@@@ 6 @@@@@@@@@@@@@@@@@@@ 5 @@@@@@@@@@@@@@@@@@@ 4 @@@@@@@@@@@@@@@@@@@ 3 @@@@@@@@@@@@@@@@@@@ 2 @@@@@@@@@@@@@@@@@@@ 1 @@@@@@@@@@@@@@@@@@@
ABCDEFGHIJKLMNOPQRS
Figure 3: An ASCII art of the Go board covered by the Mist except the 7 × 7 hole, where @,.,A
represents the Mist, the hole and the centre of the hole. who
who command can be executed to show who is the current player. One character will be displayed, either B for Black stone or W for White stone.
This command can be executed at any time.
term
term command forces the controller to terminate with exit code 1. This command can be executed at any time. This command will suppress history moves messages and the exit message.
resign
resign command can be executed by a player to resign from the game. This command will cause the current player to end the game and lose. The other player will win the game. This command can be executed at any time.
1234567
8 91011121314 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
Figure 4: An ASCII art of the 7×7 hole in Figure 3, where the numbers represent the output ordering of the hole in view.
view
view command can be executed by a player to view the current board. The controller will respond with a one-line output, consisting of two strings separated by a comma.
The first string denotes the centre coordinate of the 7 ×7 hole that is not covered by the Mist.
The second string denotes the status of grid points in the hole. That is, whether each point is occu- pied by a black stone, a white stone, not occupied or off-board. This string is the concatenation of rows’ status , and each row starts with
the lowest column (from A to S ).
#, o ,.,x denotes black, white, empty and off-board.
If the hole is partially off-board, then the grid points that are off-board should be represented by x. See Example 4.
This command can be executed at any time.
place <C><R>
place command can be executed by a player to place a stone on the Go board according to the Go coordinate <C><R>. If the placement is successful, the controller will not respond with any output and silently alternate the player. However, if the given placement is invalid, then it will
<C><R>. In particular, a one-line output formed by a sequence of the Go coordinates. For example, if Black first places a stone at A1, then White at B2, followed by Black at C3 and finally White at D4, the history requested at this point should read A1B2C3D4. This command can be executed at any time.
(from the greatest row number 19 to the least row number 1)
See Figure 4.
End game conditions
A winner is decided when that player achieves a line of five stones with the same colour, either horizontally, vertically or diagonally, or the opposing player has resigned the game. A message will be displayed
[Black|White] wins!
The game will also end when no more stones can be placed A message will be displayed
Wow, a tie!
At the end of the game, the history command should be called silently to display all the moves. Finally, an exit message will be provided
Thank you for playing!
The controller will terminate with exit code 0 if a player wins or there is a tie.
term command will not lead to the end game.
Submission details
You are encouraged to submit multiple times, but only your last submission before the deadline will be marked.
Writing your own test cases
We have provided you with some test cases but these do not test all the functionality described in the assignment. It is important that you thoroughly test your code by writing your own test cases.
You should place all of your test cases in the tests/ directory. Ensure that each test case has the .in input file along with a corresponding .out output file. We recommend that the names of your test cases are descriptive so that you know what each is testing, e.g. basic-game.in and tie- condition.in. Please note that test case files must be located in tests/ directory and follow the above naming convention. Otherwise, they will NOT be marked.