2014
11-05

# King’s Case

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.

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.

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.

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

Just a normal move
Checkmate!

1. 第2题，TCP不支持多播，多播和广播仅应用于UDP。所以B选项是不对的。第2题，TCP不支持多播，多播和广播仅应用于UDP。所以B选项是不对的。

2. 思路二可以用一个长度为k的队列来实现，入队后判断下队尾元素的next指针是否为空，若为空，则出队指针即为所求。