编程介的小学生 2020-03-02 21:45 采纳率: 20.5%
浏览 136

King’s Case 象棋问题

Problem Description
As you maybe know, Chess is a board game played between two players. It is played on a chessboard, which is a square-checkered board with 64 squares arranged in an eight-by-eight grid. At the start, each player controls sixteen pieces: one king, one queen, two rooks, two knights, two bishops, and eight pawns. The object of the game is to checkmate the opponent's king, whereby the king is under immediate attack (in "check") and there is no way to remove or defend it from attack on the next move.

The board has eight rows (called ranks and denoted with numbers 1 to 8) and eight columns (called files and denoted with letters a to h).
White always moves first. After the initial move, the players alternately move one piece at a time (with the exception of castling, when two pieces are moved). Pieces are moved to either an unoccupied square, or one occupied by an opponent's piece, capturing it and removing it from play. With the sole exception of en passant, all pieces capture opponent's pieces by moving to the square that the opponent's piece occupies. (In this problem, there will not be ‘en passant’, ‘Castling’ or ‘Promotion’. This simplifies the problem a little.)

Each chess piece has its own style of moving.

● The king moves one square in any direction. The king has also a special move which is called castling and also involves a rook, but not in this problem!
● The rook can move any number of squares along any rank or file, but may not leap over other pieces. Along with the king, the rook is also involved during the king's castling move, but not in this problem!
● The bishop can move any number of squares diagonally, but may not leap over other pieces.
● The queen combines the power of the rook and bishop and can move any number of squares along rank, file, or diagonal, but it may not leap over other pieces.
● The knight moves to any of the closest squares which are not on the same rank, file or diagonal, thus the move forms an "L"-shape two squares long and one square wide. The knight is the only piece which can leap over other pieces.
● The pawn may move forward to the unoccupied square immediately in front of it on the same file, or on its first move it may advance two squares along the same file provided both squares are unoccupied, or it may move to a square occupied by an opponent’s piece, which is diagonally in front of it on an adjacent file, capturing that piece. The pawn has two special moves, the en passant capture, and pawn promotion, but not in this problem! Just as you see, the white pawn move upward and the black pawn move downward.

A player may not make any move which allows the King to be captured. If such a move is not possible, the game ends. The result will be a checkmate, if king is under immediate attack or stalemate, if it is not. -----Wikipedia.
The question your program should answer is when a player makes a move, determine the result of the move. The result can be one of these,

Checkmate! -----------------This move result a win.
Draw -------------------------This move result a stalemate
Check! -----------------------The game has not finished yet, but this move is a check
Just a normal move --------The game has not finished yet, and this move is not a check
This is not a legal move --This is happened when move a piece not belongs to it, want to eat a piece belongs to it, want to move a piece not under the style of that kind of piece, when you under check that move is not a right response or after that move you king will be capture.

Input
The input will consist of one or more test cases.
The first line of the input will be a single integer T, indicates the number of the cases.
Each test case adheres to the following format:
● On the first line there will be “White makes a move” or “Black makes a move”.
● On the second line have two positions indicate the move from and to. The position is such is “e4”, in a lowercase character ‘a’ to ‘h’ and a number from 1 to 8. So the positions are always in the board.
● On the next 8 lines will represent the board before the move.
● The Black pieces will be represented by uppercase characters. K for King, Q for Queen, R for Rook, B for Bishop, N for Knight, P for Pawn. The White pieces will be represented by lowercase characters, just like the Blacks. You may assume the board before move is legal and the game have not finished yet. Squares has no piece in is represented by ‘.’.
There is not white line between cases.

Output
Output “Checkmate!”, “Draw”, “Check!”, “Just a normal move” or “This is not a legal move” in a line.

Sample Input
2
White makes a move
e2 e4
RNBQKBNR
PPPPPPPP
........
........
........
........
pppppppp
rnbqkbnr
Black makes a move
b8 b1
.R....K.
.....PPP
........
......r.
........
........
.....ppp
......k.

Sample Output
Just a normal move
Checkmate!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Stata 面板数据模型选择
    • ¥20 idea运行测试代码报错问题
    • ¥15 网络监控:网络故障告警通知
    • ¥15 django项目运行报编码错误
    • ¥15 请问这个是什么意思?
    • ¥15 STM32驱动继电器
    • ¥15 Windows server update services
    • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
    • ¥15 模糊pid与pid仿真结果几乎一样
    • ¥15 java的GUI的运用