Problem 046——UVa 220 - Othello

 Othello 

Othello is a game played by two people on an 8 x 8 board, using disks that are white on one side and black on the other. One player places disks with the white side up and the other player places disks with the black side up. The players alternate placing one disk on an unoccupied space on the board. In placing a disk, the player must bracket at least one of the other color disks. Disks are bracketed if they are in a straight line horizontally, vertically, or diagonally, with a disk of the current player's color at each end of the line. When a move is made, all the disks that were bracketed are changed to the color of the player making the move. (It is possible that disks will be bracketed across more than one line in a single move.)

tex2html_wrap73 tex2html_wrap75

Write a program to read a series of Othello games. The first line of the input is the number of games to be processed. Each game consists of a board configuration followed by a list of commands. The board configuration consists of 9 lines. The first 8 specify the current state of the board. Each of these 8 lines contains 8 characters, and each of these characters will be one of the following:

 
		    `-' 		 indicating an unoccupied square

`B' indicating a square occupied by a black disk

`W' indicating a square occupied by a white disk

The ninth line is either a `B' or a `W' to indicate which is the current player. You may assume that the data is legally formatted.

The commands are to list all possible moves for the current player, make a move, or quit the current game. There is one command per line with no blanks in the input. Commands are formatted as follows:

List all possible moves for the current player.
The command is an ` L' in the first column of the line. The program should go through the board and print all legal moves for the current player in the format ( x, y) where  x represents the row of the legal move and  y represents its column. These moves should be printed in row major order which means:

1)
all legal moves in row number  i will be printed before any legal move in row number  j if  j is greater than  i
and 2)
if there is more than one legal move in row number  i, the moves will be printed in ascending order based on column number.

All legal moves should be put on one line. If there is no legal move because it is impossible for the current player to bracket any pieces, the program should print the message ``No legal move."

Make a move.
The command is an ` M' in the first column of the line, followed by 2 digits in the second and third column of the line. The digits are the row and the column of the space to place the piece of the current player's color,  unless the current player has no legal move. If the current player has no legal move, the current player is first changed to the other player and the move will be the move of the new current player. You may assume that the move is then legal. You should record the changes to the board, including adding the new piece and changing the color of all bracketed pieces. At the end of the move, print the number of pieces of each color on the board in the format `` Black - xx White - yy" where  xx is the number of black pieces on the board and  yy is the number of white pieces on the board. After a move, the current player will be changed to the player that did not move.

Quit the current game.
The command will be a ` Q' in the first column of the line. At this point, print the final board configuration using the same format as was used in the input. This terminates input for the current game.

You may assume that the commands will be syntactically correct. Put one blank line between output from separate games and no blank lines anywhere else in the output.

Sample Input

2
--------
--------
--------
---WB---
---BW---
--------
--------
--------
W
L
M35
L
Q
WWWWB---
WWWB----
WWB-----
WB------
--------
--------
--------
--------
B
L
M25
L
Q

Sample Output

(3,5) (4,6) (5,3) (6,4)
Black -  1 White -  4
(3,4) (3,6) (5,6)
--------
--------
----W---
---WW---
---BW---
--------
--------
--------

No legal move.
Black -  3 White - 12
(3,5)
WWWWB---
WWWWW---
WWB-----
WB------
--------
--------
--------
--------

首先我说明下,这个题目跟那个练习的一题象棋很像的,分吧个方向讨论就可以了,思路简单,就是麻烦的要命,后来好不容易写出来代码还丢掉了,这还不是第一次丢了代码,我也是醉了。哎,实在不想重写,我就不贴代码了说说要注意的地方就好了。


在这个题目中,有两个地方要注意下。一个是输出黑白棋个数的时候一定是两位数,就像酱紫:

printf("Black - %2d White - %2d\n",num_b,num_w);
还有就是关于空行的问题,他是在两个样例间,中间有空行,建议酱紫写:

#include <bits/stdc++.h> 
int main()
{
    int T;
    cin >> T;
    while(T--)
    {
        input();
        operation();
        output();
        if(T) cout << endl;
    }
    return 0;
}
别的就不用多说了,写就是了。不过,还真是麻烦啊~


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值