编程介的小学生 2017-08-03 14:30 采纳率: 20.5%
浏览 670
已采纳

Reversi

Problem Description
Reversi, also called Othello, is a two-sided game.
Each of the two sides corresponds to one player; they are referred to here as light and dark after the sides of Othello pieces, but "heads" and "tails" would identify them equally as well, so long as each marker has sufficiently distinctive sides.
Originally, Reversi did not have a defined starting position. Later it adopted Othello's rules, which state that the game begins with four markers placed in a square in the middle of the grid, two facing light-up, two pieces with the dark side up. The dark player makes the first move.

Dark must place a piece with the dark side up on the board, in such a position that there exists at least one straight (horizontal, vertical, or diagonal) occupied line between the new piece and another dark piece, with one or more contiguous light pieces between them. In the below situation, dark has the following options indicated by transparent pieces:

After placing the piece, dark turns over (flips, captures) all light pieces lying on a straight line between the new piece and any anchoring dark pieces. All reversed pieces now show the dark side, and dark can use them in later moves—unless light has reversed them back in the meantime. In other words, a valid move is one where at least one piece is reversed.
If dark decided to put a piece in the topmost location (all choices are strategically equivalent at this time), one piece gets turned over, so that the board appears thus:

Now light plays. This player operates under the same rules, with the roles reversed: light lays down a light piece, causing a dark piece to flip. Possibilities at this time appear thus (indicated by transparent pieces):

Light takes the bottom left option and reverses one piece:

Players take alternate turns. If one player cannot make a valid move, play passes back to the other player. When neither player can move, the game ends. This occurs when the grid has filled up, or when one player has no more pieces on the board, or when neither player can legally place a piece in any of the remaining squares. The player with the most pieces on the board at the end of the game wins.
Now after several rounds, it’s dark’s turn. Can you figure out the largest number of light pieces he can turn over?

Input
The first line contains one integer T representing the number of test cases.
For each test case, there’re 8 lines. Each line contains 8 characters (D represents dark, L represents light, * represents nothing here).
Every two adjacent cases are separated by a blank line.

Output
For each test case, in one line print the case number and the largest number of light pieces the dark player can turn over. If he can’t put one piece in any position, then print 0.
Please follow the format of the sample output.

Sample Input
3




LD
DL






DLL*
DLLL
DLD*






D*****
DLLD**
LL
D*D*



Sample Output
Case 1: 1
Case 2: 3
Case 3: 0

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-08-18 15:53
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。