Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

COMP2017 9017

Assignment 1

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.

You are encouraged to ask questions on Ed2 .  Make sure your question post is of "Question" post type and is under "Assignment" category → "A1" subcategory → "Debugging"/"Spec"/"General" sub-subcategory. As with any assignment, make sure that your work is your own3, 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 nd 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 rst. 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 rst 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.

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 rst 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:

xmist  = 1 + (5xs(2)tone  + 3xstone  + 4) % 19,

ymist  = 1 + (4ys(2)tone  + 2ystone 4) % 19.

% is the modulo operator.

(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 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 , is a column character ranging from A (the first English upper letter) to S (the nineteenth English upper letter); is a row number ranging from 1 to 19.

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.

Functionalities of the Game Controller

The Game Controller is a command prompt that supports the following commands:

who

term

resign

view

place  

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.

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.

19   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .

18   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .

17   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .

16   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .

15   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .

14   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .

13   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .

12   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .

11   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .

10   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .

9     .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .

8     .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .

7     .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .

6     .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .

5     .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .

4     .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .

3     .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .

2     .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .

1     .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .

A  B  C  D  E  F  G  H  I  J  K  L  M  N  O  P  Q  R  S

numerical:            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     .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .

A  B  C  D  E  F  G  H  I  J  K  L  M  N  O  P  Q  R  S

Figure 2: An ASCII art of the Go board when Black stone wins, where #, o , .  represents Black stone, White stone and no stone (empty).

19  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @

18  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @

17  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @

16  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @

15  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @

14  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @

13  @  @  @  @  @  @   .   .   .   .   .   .   .  @  @  @  @  @  @

12  @  @  @  @  @  @   .   .   .   .   .   .   .  @  @  @  @  @  @

11  @  @  @  @  @  @   .   .   .   .   .   .   .  @  @  @  @  @  @

10  @  @  @  @  @  @   .   .   .  A   .   .   .  @  @  @  @  @  @

9     @  @  @  @  @  @   .   .   .   .   .   .   .  @  @  @  @  @  @

8     @  @  @  @  @  @   .   .   .   .   .   .   .  @  @  @  @  @  @

7     @  @  @  @  @  @   .   .   .   .   .   .   .  @  @  @  @  @  @

6     @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @

5     @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @

4     @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @

3     @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @

2     @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @

1     @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @  @

A  B  C  D  E  F  G  H  I  J  K  L  M  N  O  P  Q  R  S

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.

1

8

15

22

29

36

43

2

9

16

23

30

37

44

3

10

17

24

31

38

45

4

11

18

25

32

39

46

5

12

19

26

33

40

47

6

13

20

27

34

41

48

7

14

21

28

35

42

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  (from the greatest row number 19 to the least row number 1) , and each row starts with the lowest column (from A to  S ).  See Figure 4.

#, 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 . 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 respond with a one-line error message without alternating the player. If the placement (e.g. Z100) cannot be recognised as a valid board coordinate, then it outputs Invalid  coordinate. If the placement can be recognised as a valid board coordinate however the coordinate is occupied, then it outputs

Occupied  coordinate. This command can be executed at any time.

Placements in the Mist are allowed.

history

history command can be executed to obtain all history of moves in Go coordinates . 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.

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.

Examples

User inputs are highlighted in green . Program outputs are not highlighted.

Example 1

B

term

Example 2

B

W

resign

Black wins!

A1

Thank you for playing!

Example 3

A1B2C3D4

term

Example 4

view

J10, . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

place A1

view

M3, . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxxxxxx

place B2

view

L17,xxxxxxx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

place C3

view

B1,xx . . . . .xx . .# . .xx .o . . .xx# . . . .xxxxxxxxxxxxxxxxxxxxx

place D4

view

B12,xx . . . . .xx . . . . .xx . . . . .xx . . . . .xx . . . . .xx . . . . .xx . . . . .

history

A1B2C3D4

term

Example 5

place A1

place B1