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

Checker's Check

Description

The game of checkers is played on an 8 by 8 red-black board using alternate squares. Two players (Red and White) each start with 12 pieces which are set up in the starting position shown below:

Rules for movement and capture are as follows (Note: a forward move is one in which a piece moves towards the opponent's side of the board):
1. Players alternate moves.
2. A piece may move one square forward diagonally to any empty square.
3. A piece may jump forward over an opposing player's piece if the opposing piece is adjacent to the piece and the square directly beyond the opposing piece is empty. After a jump, the opposing piece is removed from the board (captured). If after a jump, the jumping piece can make another jump, it must do so. This continues until it can make no other jumps. This is called a multiple jump.
4. A player must make a jump if possible. If several jumps are possible, the player may choose any,even choosing a single jump over a multiple jump. (However, if a multiple jump is chosen, it must be completed.)
5. The last row on the opponent's side of the board (the row where the piece can make no more forward moves) is the player's promotion row. When a piece reaches the promotion row it is promoted to a king and may now move and capture backward as well as forward. Once a piece is promoted, its move ends|it cannot start to jump or continue a multiple jump after becoming a king until the next turn.
6. A piece may be jumped at most once during a move (only a consideration when a king is doing the jumping).

Games are recorded using the square numbering shown above. For example, a simple forward move for White might be 22-18; a single jump for Red might be 14-23 (capturing a White piece at square 18);and a multiple jump for a White king might be 22-31-24-15 (capturing Red pieces at 26, 27 and 19).
For this problem, you will be given a position of a game in progress and a set of moves to be applied starting at that position, and you must determine if all the moves are legal by writing an Advanced Checkers Machine.
Input

Input will consist of multiple problem instances. Each instance will start with two integers r and w,indicating the number of Red and White pieces on the board (values of r = w = 0 indicates end of input, otherwise 1 <= r, w <= 12). The next line will contain r square numbers indicating the Red piece positions and the next line will contain w square numbers for the White piece positions. Positive square values will indicate that a normal piece lies on that square, while a negative value -sq will indicate that a promoted piece lies on square sq. The next line will contain a single integer m >= 1 indicating the number of moves to make, followed by a space and then a single character (either R or W) indicating whose move it is. The next m lines will contain the m moves, using the notation described above. (You may assume that there are no more than 13 square numbers listed in any one move.)
All board positions will be legal positions (e.g., there will never be two pieces occupying the same square). You may assume that pieces that have advanced to their promotion row are indeed promoted;that is, there will be no pieces on their promotion row that are not kings.
Output

For each problem instance, output either All moves valid or Move n is invalid, where n=1 corresponds to the first move in the problem instance. If there are multiple illegal moves, you should list only the first such move.
Sample Input

4 3
6 7 8 -16
9 18 19
3 W
9-2
16-23-14
2-11-4
4 3
6 10 15 19
18 22 23
6 R
19-26
18-11
10-14
22-18
6-10
10-15
0 0
Sample Output

All moves valid
Move 5 is invalid

  • 写回答

1条回答 默认 最新

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

报告相同问题?

悬赏问题

  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事: