Hide

Problem D
Glacial Game 2: Even Glacier

Theo is the CEO of the illustrious company Air Conditioning and Pest Control. His business model consists of installing huge air conditioners in his clients’ homes that have rat infestations, in order to make their houses so cold that the rats pack up and leave for somewhere warmer. Recently, however, it has come to Theo’s attention that the rats in one person’s house have been playing a tournament of a board game named Othello, the excitement of which has been keeping them warm enough to remain in his customer’s dwelling!

The board for Othello consists of an $8$ by $8$ square grid. Each of the $2$ players has an unlimited supply of circular tokens which are white on one side and black on the other. They each choose a colour at the beginning of the game (one white, one black), and each player’s goal is to have more tokens on the board displaying their colour at the end of the game than their opponent (it’s a draw if there are the same number of tokens of each colour). The players alternate turns, with black going first. On a player’s turn, they choose an empty square on the board to place a token showing their colour, and then all of the tokens showing their opponent’s colour in every newly formed sandwich get flipped to their colour as well. By sandwich, we mean a line of one or more tokens of the same colour, trapped by a token of the opposite colour on each end of the line. A sandwich can be in any direction (vertical, horizontal or diagonal). In order for a player’s move to be valid, the token they place must form at least one new sandwich. Also, all of their opponent’s tokens in all of the (up to $8)$ newly formed sandwiches must be flipped, even if it would somehow be advantageous for the player not to flip some of them. A player must make a move on their turn, again even if this would not be to their advantage, unless they have no valid moves, in which case their turn simply consists of doing nothing and it becomes their opponent’s turn. The game ends when neither player can move, at which point a winner (or a draw) is determined based on the number of tokens of each colour on the board. It is possible that this occurs before all $64$ squares on the board have been filled. One final thing to note is that only tokens in newly formed sandwiches, at the time they are formed, get flipped. Any other sandwiches which get formed indirectly by the flipping of these tokens are left as is.

The following two rows of figures show separate examples of moves by white and black respectively. In each, (a) gives the board position at the start of the turn, with the empty square that the player will place a token of their colour on highlighted in red, (b) shows the board after the token has been placed, along with sandwich icons indicating which tokens are part of a newly formed sandwich, and finally (c) is the board position after the appropriate tokens have been flipped and the player’s turn is over.

\includegraphics[width=12em]{figure1a.JPG}

\includegraphics[width=12em]{figure1b.JPG}

\includegraphics[width=12em]{figure1c.JPG}

(a) White to move

(b) One newly formed sandwich

(c) Three tokens flipped

\includegraphics[width=12em]{figure2a.JPG}

\includegraphics[width=12em]{figure2b.JPG}

\includegraphics[width=12em]{figure2c.JPG}

(a) Black to move

(b) Two newly formed sandwiches

(c) Two tokens flipped

PLEASE NOTE: The bold text in the following paragraph gives details specific to Glacial Game 2.

Theo has decided to wreck the rats’ Othello tournament by disguising himself as a rat, entering the tournament and winning the whole thing. Surely, this will disappoint the rats immensely, causing them to lose all body heat and exit the premises immediately. Towards this end, he has written a program which, given a position (an arrangement of tokens on the board), determines which move he can make that will maximize the number of black pieces on the board (Theo always plays as black). The program is also able to determine if no valid moves by black can be made. Unfortunately, because of a mole in Theo’s company, the rats have learned of his planned deception and have obtained the source code to his program, which they have modified to work for white pieces! Now, Theo needs a program that goes one step further: Given the current position, he needs it to determine the maximum number of black pieces that can be on the board after he takes a turn and his rat opponent takes a turn, assuming that after Theo moves his opponent will use the bootleg one-move-white-optimising program. The poor CEO has just learned that the rats at another client’s house are thwarting his air conditioning by wearing tiny mittens, so he has called upon you, an unpaid intern, to complete this important task, while he confiscates the mittens.

Input

There are $8$ lines of input, each of which consists of $8$ characters, describing the current position of the board, with black to move. A square occupied by a white token is represented by ‘W’, black tokens are ‘B’ and empty squares are ‘.’. The position will not necessarily be reachable in an actual game of Othello, however, it is guaranteed that black will have at least one valid move.

Output

Output a line containing the row and column, separated by a single space, of the move that Theo’s new program should choose (consider the rows to be numbered $0$ to $7$ from top to bottom and the columns to be numbered $0$ to $7$ from left to right). If more than one of black’s moves are tied for highest number of black pieces after white has had a turn in response, pick the one with the lowest row number. If there is still a tie, pick the one with the lowest column number.

Sample Input 1 Sample Output 1
........
........
........
...WB...
...BW...
........
........
........
2 3
Sample Input 2 Sample Output 2
........
........
..B...B.
..W..W..
..W.W...
..WW....
...WB...
........
6 2
Sample Input 3 Sample Output 3
........
........
..W...W.
..B..B..
..B.B...
..BB....
...BW...
........
1 2

Please log in to submit a solution to this problem

Log in