编程介的小学生 2016-12-24 14:11 采纳率: 18.6%
浏览 853
已采纳

滑铁卢的围棋问题

Description

Go is played on a square board with an odd number of vertical and horizontal lines. The usual board sizes are 9x9, 13x13 and 19x19. But we'll assume the size in nxn for 3 ≤ n ≤ 19.

Black and White alternately play stones on the intersection between two lines. Black starts. At any time one player may pass – not play a stone – but if both players pass the game ends. We'll denote playing a stone by P(x,y) where P is either B (for Black) or W (for White) and (1−n)/2 ≤ x,y ≤ (n−1)/2 gives the grid position of the stone to be played. The centre intersection of the board has coordinates (0,0).

The rules of Go are reasonably straightforward, but the nuances of strategy make it an extremely challenging game. You are to use the following rules.

Black plays first.
Black and White alternate; at each turn a player may place a stone or may pass. The game ends when Black and White pass consecutively.
A stone may be played only on an unoccupied intersection.
If one player P places a stone so that his or her stones (along with the edge of the board) completely surround a connected area occupied by stones belonging to the other player, Q, Q's stones are said to be captured and removed from the board. More precisely, two intersections are connected if they are horizontally or vertically (but not diagonally) adjacent. Stones in an area are completely surrounded if no stone is connected with a vacant intersection.
If P places a stone that causes Q's stones to be captured, P's stone is not captured.
A connected area surrounded by P's stones which contains none of Q's stones is said to be owned by P.
The score for player P is the number of vacant intersections owned by P in the final board configuration plus the number of Q's stones captured by P at any time during the game.
Input

The input consists of several test cases. Each test case begins with a line containing n – the size of the board – and m – the number of stones placed in the game. m lines follow, each giving a placement in the format above. Note that m counts only stone placements – passes may result in two consecutive placements by the same player. You may assume that each move is legal. A line containing 0 0 follows the last test case.

Output

For each test case, output a line with two numbers: Black's score followed by White's score.

Sample Input

7 6
B(-2,-2)
W(2,2)
B(-2,-3)
W(2,3)
B(-3,-2)
W(3,2)
7 6
B(-2,-3)
W(-3,-3)
B(-2,-2)
W(3,2)
B(-3,-2)
W(2,3)
0 0
Sample Output

1 1
2 1

  • 写回答

1条回答 默认 最新

  • devmiao 2016-12-24 16:29
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

    报告相同问题?

    悬赏问题

    • ¥15 使用matlab进行手眼标定的仿真验证,得到齐次矩阵与opencv相差较大
    • ¥15 Python词频统计,运行出的Excel没有内容
    • ¥15 求推荐一个好用的录屏软件
    • ¥15 kali显示no x11 display variable was set;
    • ¥15 如何实现这个Python开发问题
    • ¥15 Erasure Code纠删码表
    • ¥15 用vite创建的vue3项目,404重定向不起作用??
    • ¥15 关于#c语言#的问题:一个球从80米高度自由落下,每次落地后反弹的高度为原高度的一半计算6次小球反弹的高度.(反弹结果取整,使用走走for循环结构)
    • ¥15 SurfaceControl的screenshot问题
    • ¥15 基于51单片机的oled菜单代码,要C语言,模块化编程!