The Territory of Go The Territory of Go
Moderate
RU English

This is the second mission about the Go game. The first one is the Eaten Go Stones.
In this mission you will learn how to count territory in the Go. Pay attention that this mission is simplified compared to the real game rules (the tests are haven't cases where stones of one color is on the territory of the other player).

So what is territory in the Go game? This is all unoccupied points which are surrounded by the complete and solid border of the stones of one color. It can be the form in the center of the board, which uses only own stones for bounds or it also can be form near the edge of the board and use this edge to complete the boundary. The complete and solid boundary is that one which consists of the stones connected to each other only vertically and horizontally. Also it should be 'closed'.
Look at this picture that describes the input data and the 'territory' conception:

example

Your task is to count the territory which belongs to the each player. For this example the answer is: {'B': 13, 'W': 12}.

Input: Two-dimensional array (the list of the strings).

Output: Dictionary with the amount of the territory of the each player.

Example:

territory(['++B++++++',
           '+BB++++++',
           'BB+++++++',
           '+++++++++',
           '+++++++++',
           '++WWW++++',
           '++W+W++++',
           '++WWW++++',
           '+++++++++']) == {'B': 3, 'W': 1}

How it is used: For game AI development and game analysis.

Precondition:
Board - 9х9, 7x7, 5x5