The objective of this assignment is to become familiar with a problem that you will implement in several different programming languages/paradigms this quarter.
For this assignment you are to write a program in C, C++, C#, Java, or Python (your choice). The program will compute and print the number of liberties for stones on a Go board, and identify which stones are connected into groups.
Go is played on a square grid with 9, 13, or 19 vertical and horizontal lines. There are two players and they take turns placing black or white stones (one color for each player) on the intersections of the lines.
A ÒlibertyÓ is an unoccupied intersection, adjacent to a stone. Adjacent means connected by a line (diagonals are not adjacent). For example, a single stone placed away from any edge has four liberties (one north, one south, one east, and one west).
A group of stones of the same color is connected if you can move from any stone in the group to any other stone passing only through intersections occupied by stones of the same color. For example, the following board has three groups (two black groups and one white group).
......W..
..BB..W..
...BWWW..
....B....
....B....
.........
.........
.........
.........
Liberties are shared by stones in a group. For example, the upper left black group in the previous example has 6 liberties marked with L in the following:
..LL..W..
.LBBL.W..
..LBWWW..
...LB....
....B....
.........
.........
.........
.........
The white group has 8 liberties.
That is all you need to know about Go for this assignment. You can learn more at any of the many Go sites on the web. This looks like a reasonable place to start: http://www.well.com/user/mmcadams/gointro.html .
Your program must adhere precisely to the input and output specifications stated here.
Input: Your program should read its input from standard input. The first line of input will be a single integer, either 9, 13, or 19, specifying the size of the board. If S is the size of the board, then the next S lines will each contain a sequence of S characters from the set {., B, W}. ThatÕs a dot for empty, a B for a black stone, or a W for a white stone.
Output:
The Stones
ABCDEFGHI
1 ......W..
2 ..BB..W..
3 ...BWWW..
4 ....B....
5 ....B....
6 .........
7 .........
8 .........
9 .........
The Liberties
AA BB CC DD EE FF GG HH II
1
.. .. .. .. .. .. 8 .. ..
2
.. .. 6 6 .. .. 8 .. ..
3
.. .. .. 6
8 8 8 .. ..
4
.. .. .. .. 5 .. .. .. ..
5
.. .. .. .. 5 .. .. .. ..
6
.. .. .. .. .. .. .. .. ..
7
.. .. .. .. .. .. .. .. ..
8
.. .. .. .. .. .. .. .. ..
9
.. .. .. .. .. .. .. .. ..
The Groups
AA BB CC DD EE FF GG HH II
1
.. .. .. .. .. .. 1 .. ..
2
.. .. 2 2 .. .. 1 .. ..
3
.. .. .. 2
1 1 1 .. ..
4
.. .. .. .. 3 .. .. .. ..
5
.. .. .. .. 3 .. .. .. ..
6
.. .. .. .. .. .. .. .. ..
7
.. .. .. .. .. .. .. .. ..
8
.. .. .. .. .. .. .. .. ..
9
.. .. .. .. .. .. .. .. ..