编程介的小学生 2017-05-05 06:10 采纳率: 20.5%
浏览 719
已采纳

Othello

Before asking you to predict the winner of the Othello game, a description of the game is given below:

CONTENTS

  • Othello game board has 64 squares, plus storage compartments with roll-down covers on both sides for discs.

  • 64 discs: white on one side, black on the other.

PREPARATION

Fill each compartment with 32 discs.

OBJECT OF THE GAME

To outflank your opponent and flip your opponent's discs to your color, ending up with the majority of discs on the board in your color.

GAME RULES

  1. Each player chooses one color to use throughout the game.

  2. Black places two black discs, and White places two white discs on the board as shown in Figure 1. The game always begins with this set-up.

  3. Players choose who goes first.

  4. A move consists of taking a disc from the compartment and placing it so that it completes the outflanking of one or more opposite color discs, then flipping the outflanked disc(s) over to your color.

For example, white disc A is already in place on the board. By the placement of white disc B, the black row of discs has been outflanked.

Thus all the captured discs are flipped and this row becomes . . .

  1. A PLAYER MUST ALWAYS OUTFLANK HIS OPPONENT AND FLIP AT LEAST ONE OPPOSING DISC IN ORDER TO MOVE.
    If he cannot make a move, he loses his turn and his opponent moves. This is called a PASS.

  2. A disc may outflank any number of opposing discs in one or more rows. (A row may be one disc or many discs in a straight line.)

  3. A disc may outflank in any direction: horizontal, vertical, diagonal, forward or backward.

  4. A disc may outflank in any number of directions at the same time. (Theoretically, it is possible to flip in up to 8 directions at once.) DISCS MAY ONLY BE FLIPPED AS A DIRECT RESULT OF A MOVE.

  5. The game is over when the board is entirely filled with discs, or when it is not possible for either player to move (i.e., out flank an opponent's row and flip an opponent's disc), or when the board is filled (or partially filled) with all one color.
    At this point, discs are counted up. The player with the most discs is the winner.

Now given a configuration of the Othello game, what is the maximum possible advantage the black can gain after T moves? The formula of advantage is the number of black discs minus the number of white discs.

Note:

  1. Pass is also considered as one move.

  2. Assume the game is never end. The players just keep ��pass�� on the end of game.

  3. Assume both of the players may make mistakes.

  4. Assume it is always black's turn.

Input

The input begins with an integer n, indicates the number of test cases. For each test case, the first line gives an integer t (0 < t <= 4), and the following 8 lines give a valid configuration. Every line contains 8 characters, 'B' for black and 'W' for white.

Output

For each test case, output an integer indicates the maximum advantage the black can gain.

Sample Input

1
1

BW

WB

Sample Output

3

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3