Go


General

  • All submissions must include a work history to be worth credit.
  • Submit all files to elearn. Make sure to name file(s) EXACTLY as specified - including capitalization.
  • Make sure your program accepts input in EXACTLY the order and format given. Do not ask for extra input or change the order of inputs.
    If you want to make an expanded version of a program that and get feedback on it, email it to me or show me in class.
  • Slight variations in output wording/formatting are usually fine (as long as formatting isn't part of the assignment).
    If you do not get the right final output, print out some evidence of the work your program did to demonstrate your progress.
  • Readability and maintainability of your code counts. Poor formatting, confusing variable names, unnecessarily complex code, etc… will all result in deductions to your score.

Assignment Instructions

Submit file: assign7.zip

Make sure to compress your entire folder, not just your code file.

I should be able to do this to build your code:

g++ -g -std=c++17 main.cpp -o program.exe

Background

A go board with a game in progress

Go is a popular game in which players place black and white tiles and attempt to capture as much of a square board as possible. The size of the board can vary from 9x9 to 19x19 – these measurements refer to the number of intersections in the grid lines – stones are placed on those intersections.

Central to Go are the ideas of "groups" and "liberties". A group is a set of tiles, all of the same color, that are connected either horizontally or vertically. A group’s liberties are the number of moves that can extend the group to a new open location. If a group has 0 liberties, it is captured and removed from the board.

Below are shown some samples of the number of liberties that exist for the groups that various tiles are a part of. The selected tile is shown in dark blue, its group in light blue, and the liberties are shown in dark green.

Example inputs and outputs

Group/Liberty Counter

We will represent the 81 intersections in a 9x9 Go board with a 9x9 array and represent black and white pieces with the chars B and W.

An example 9x9 array representing a board

Write a program that will read in a 9x9 go board from a file called "go.txt" that is formatted like this sample file. (I might use a different board for testing your program. but it will have the same format.)

Your program should then read in a row and column from the console indicating a starting location. It should print out: 1) the board, with the squares that are in the group made uppercase and the liberties for the group marked as *'s; 2) the number of pieces in the group based at the starting location; 3) how many liberties there are. If the row, col the user enters does not have a piece in it (is a - instead of w or b), print an error message.

You can (should) use normal loops to read in the input and print the board.

Your program must make use of recursion for determining the size of the group and number of liberties.

You must use parameters to pass information from one recursive call to another. No global variables allowed (constants are OK). You may not make a class that contains your functions.

A solution for the group and liberty count that does not use recursion will NOT receive points.

Printing the group cells in upper case and the group size is 80% credit. Worry about that problem first. Marking liberty squares and counting them is the last 20% of the assignment and should involve similar logic as your group count. It is fine to use separate functions for the two jobs.

Here are some sample runs using the board shown above and provided in the sample file. (Each run of the program should only ask for one location).

Sample run 1

Enter row & col: 3 4
Board:
-  -  -  -  -  -  *  -  -
b  -  -  -  *  w  B  w  -
w  b  b  w  B  B  B  *  w
-  -  w  w  B  *  *  w  b
-  -  -  w  B  w  -  b  w
w  -  -  w  w  -  -  w  -
b  b  w  -  -  -  b  w  -
-  b  w  -  b  b  b  w  -
-  -  b  -  -  b  w  -  -
Group size: 6
Liberties: 5

Sample run 2

Enter row & col: 2 0
Board:
-  -  -  -  -  -  -  -  -
b  -  -  -  -  w  b  w  -
W  b  b  w  b  b  b  -  w
*  -  w  w  b  -  -  w  b
-  -  -  w  b  w  -  b  w
w  -  -  w  w  -  -  w  -
b  b  w  -  -  -  b  w  -
-  b  w  -  b  b  b  w  -
-  -  b  -  -  b  w  -  -
Group size: 1
Liberties: 1

Sample run 3

Enter row & col: 0 4
No tile at 0 4