Problem C
Glacial Game 1: Oh Rats!
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.
|
|
|
|
|
(a) White to move |
(b) One newly formed sandwich |
(c) Three tokens flipped |
|
|
|
|
|
(a) Black to move |
(b) Two newly formed sandwiches |
(c) Two tokens flipped |
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 would like to have 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).
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 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 yield the highest possible number of black pieces on the board, 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 |
