编程介的小学生 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 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测