Assignment 1 (50 Points) - Due W September 14, 11:59PM

Announcements and Clarification

September 01: Details regarding how to format the output reporting the number eyes, two eyes, or eyespaces, have been added to the assignment description. Be sure to correctly pluralize the output messages.

August 31: The submission date for Assignment 1 has been revised to W September 14, 11:59PM.

August 30: Using the provided distribution files, please note that you will either have to move the declaration of the go_board array to the main.c or use a extern declaration for away in main.c as follows:

extern char go_board[GO_BOARD_SIZE][GO_BOARD_SIZE];

Go Sensei Program

Create a gosensei program capable of analyzing a 9x9 go board specified by a go board configuration file to determine the number of eyes (-eyes), the number of two eyes (-twoeyes), and the number of eye spaces (-eyespaces) for the player playing black stones.

For this assignment, you do not need to understand the complete rules of go, as definition and requirements are sufficiently described below. For a brief overview of how to play go, Karl Baker's The Way to Go is a good introductory guide.

Commandline Arguments

Your program must be capable of utilizing a commandline argument to specify the current operation (-eyes, -doubleeyes, and -eyespaces) and location of the file describing the go board configuration.

gosensei -eyes goBoardFile


Your program must ensure the user has correctly provided the required commandline options and display a usage statement if the provided arguments are incorrect.

Go Board Configuration File

For this assignment, we will consider a 9x9 go, as shown below, in which a-i are used to represent the columns from left to right, and 1-9 are used to represent the rows bottom to top.

The go board can be represented as a two dimensional array or characters, in which the size of the go board is specified as a constant.

enum { GO_BOARD_SIZE = 9 };
char go_board[GO_BOARD_SIZE][GO_BOARD_SIZE];

In go, black and white stones are played on the intersection between horizontal and vertical lines. The go board configuration file will specify the current location of all stones, in which one stone location will be specified per line, using the following format:

stonecolor column row
  • stone color will specify the color of the stone, where black stones will be denoted with either an uppercase B or lowercase b, and white stones will be denoted with either an uppercase W or lowercase w.
  • column will specify the column in which the stone is located denoted by a through i or A through I. In other word, the column location is case sensitive.
  • row will specify the row in which the stone is located denoted by the number 1 through 9.
  • The stone color, column, and two will be separated by whitespace.

While reading the input, your program should minimally check for and report the following errors:

  1. Invalid stone color, column, or row specification.
  2. Multiple stones (even if they are the same color) located in the same position.

The go board configuration file reading should be implemented within the following function:

bool read_go_board(char *inputFileName, char go_board[GO_BOARD_SIZE][GO_BOARD_SIZE]);

Go Board Configuration Display

For all commandline options, after successfully reading the go board configuration file, the current go board configuration should be displayed using ASCII characters where:

  • A lowercase b represents black stones. Note: Although either uppercase B and lowercase b are used to represent black stones within the go board configuration file, when displaying the go board configuration, a lowercase b should be used.
  • A lowercase w represent white stones. Note: Although either uppercase W and lowercase w are used to represent white stones within the go board configuration file, when displaying the go board configuration, a lowercase w should be used.
  • A plus sign + represents an empty location.
  • A minus sign - and pipe character | are used to create the go board grid.
  • Column labels are displayed using uppercase A through I.
  • Row labels are displayed using the number 1 through 9.

The following provides an example display output for the go board configuration:

9 +-+-+-+-+-+-+-+-+
  | | | | | | | | |
8 +-+-+-+-+-+-+-+-+
  | | | | | | | | |
7 +-+-+-+-+-+-+-+-+
  | | | | | | | | |
6 +-+-+-+-+-+-+-+-+
  | | | | | | | | |
5 +-+-+-+-+-+-+-+-+
  | | | | | | | | |
4 b-b-+-+-+-+-+-+-+
  | | | | | | | | |
3 w-w-b-+-+-+-+-+-+
  | | | | | | | | |
2 +-w-b-+-+-+-+-+-+
  | | | | | | | | |
1 w-b-+-+-+-+-+-+-+

  A B C D E F G H I

The go board display operation should be implemented within the following function:

void display_go_board(char go_board[GO_BOARD_SIZE][GO_BOARD_SIZE]);

-eyes Options

If the user specifies the -eyes option, the program should analyze the current go board configuration to determine the number of eyes for black. While determining an eye can be complex, we will utilize the following simplified definition for this assignment:

An eye is a single empty space that is surrounded by stones of the same color vertically and horizontally in all adjacent locations, and diagonally in all or all but one location. Importantly, an eye may be located on the edge of the board for which there are fewer adjacent locations.

The following example includes three eyes for black:

9 +-+-+-+-+-+-+-+-+
  | | | | | | | | |
8 +-+-w-w-w-+-+-+-+
  | | | | | | | | |
7 w-w-b-b-b-+-+-+-+
  | | | | | | | | |
6 +-w-b-+-b-+-+-+-+
  | | | | | | | | |
5 +-w-b-b-b-+-+-+-+
  | | | | | | | | |
4 +-+-+-+-+-+-+-b-b
  | | | | | | | | |
3 +-+-+-+-+-+-+-b-+
  | | | | | | | | |
2 +-+-+-+-+-+-+-b-b
  | | | | | | | | |
1 +-+-+-+-+-+-+-b-+

  A B C D E F G H I

The operation to determine the number of eyes for black should be implemented within the following function:

int determine_eyes_black(char go_board[GO_BOARD_SIZE][GO_BOARD_SIZE]);

The main function should report the number of eye with the following simple sentence structure, be sure to correctly pluralize the output sentence:

There are 0 eyes for black.

or:

There is 1 eye for black.

-twoeyes Options

In go, a formation consisting of connected stones with at least two eyes cannot be captured by ones opponent. If the user specifies the -twoeyes option, the program should analyze the current go board configuration to determine the number of eyes that are closely connected to another eye. For this assignment, if two eyes are located within 2 rows or 2 columns of each other, they are considered closely connected.

Hint: Once you have found the individual eyes, you can then check the distance between the eyes to determine the closely connected eyes.

For example, the connected black stones in the lower right corner of the previous go board configuration have two closely connected eyes. The eye at location I1 is within two rows of the eye at location I3.

The operation to determine the number of two eyes for black should be implemented within the following function:

int determine_twoeyes_black(char go_board[GO_BOARD_SIZE][GO_BOARD_SIZE]);

The main function should report the number of two eye with the following simple sentence structure, be sure to correctly pluralize the output sentence:

There are 2 two eye for blacks.

or:

There is 1 two eye for black.

-eyespaces Options

If the user specifies the -eyespaces option, the program should analyze the current go board configuration to determine the number of eye spaces for black. We will utilize the following simplified definition of an eye space for this assignment:

An eye space is a group of adjacent empty spaces surrounded entirely by connected stones of the same color.

The following example includes two eye spaces for black, ones with two empty spaces and one with five empty spaces:

9 +-+-+-+-+-+-+-+-+
  | | | | | | | | |
8 +-+-w-w-w-+-+-+-+
  | | | | | | | | |
7 w-w-b-b-b-+-+-+-+
  | | | | | | | | |
6 +-w-b-+-b-+-+-+-+
  | | | | | | | | |
5 +-w-b-+-b-+-+-+-+
  | | | | | | | | |
4 +-+-b-b-b-+-b-b-b
  | | | | | | | | |
3 +-+-+-+-+-+-b-+-+
  | | | | | | | | |
2 +-+-+-+-+-+-b-+-+
  | | | | | | | | |
1 +-+-+-+-+-+-b-b-+

  A B C D E F G H I

The operation to determine the number of eye spaces for black should be implemented within the following function:

int determine_eyesspaces_black(char go_board[GO_BOARD_SIZE][GO_BOARD_SIZE]);

The main function should report the number of eyespaces with the following simple sentence structure, be sure to correctly pluralize the output sentence:

There are 4 eyespaces for black.

or:

There is 1 eyespace for black.

Distribution Files

gosensei.tgz

The following distribution files gosensei.tgz for this assignment include a basic example of checking commandline arguments along with a simple framework for using CMake. The distribution files also include two sample go board configuration files. Please note that the requirements for your assignment differ from this distribution archive. Please consult the Assignments page for complete details on submission requirements and C coding style and standards requirements.

Given the provided distribution archive, the following commands can be used to extract, compile, and execute the example on ece3.ece.arizona.edu:

/usr/local/bin/tar xvzf gosensei.tgz
cd gosensei
mkdir build
cd build
cmake ..
make
./src/gosensei