Chinese chess, or Xiangqi is an extremely popular game in the Eastern Hemisphere. It is currently played by millions (or tens of millions) in China's mainland, Taiwan, Thailand, Singapore, Vietnam, Hong Kong and other Asian countries. Chinese chess has remained in its present form for centuries.
The name Chinese chess has an interesting origin. Of China's four traditional arts -- qin (music), qi (strategy games), shu (calligraphy) and hua (brush painting) -- the second term, qi, provides the final syllable of Chinese chess.
Here’s some more information about Chinese chess.
Chinese chess BoardPiecesEach player has the following pieces:
2 Rooks (R) (or chariots)
2 Knights (N) (or horses)
2 Elephants (M) (or bishops or ministers)
2 Mandarins (G) (or advisors or assistants or guards)
1 King (K) (or generals)
2 Cannons (C)
5 Pawns (P) (or soldiers)
Rulesa) The object of the game is to checkmate or stalemate the opponent. This is accomplished by:
Placing the opponent in check so that he has no legal move to get out of the check.
Stalemating your opponent so that he has no legal move (when you stalemate your opponent, you win--it is not a draw as in chess).
b) Red usually moves first.
c) You cannot check your opponent indefinitely by moving the same piece to the same squares (resulting in perpetual check and a draw in chess). You cannot put the opponent in check more than 3 times in a row with the same piece without either side moving any other piece.
d) Similar to the rule above, you cannot indefinitely "chase" an opposing piece from one square to another if your opponent has no other way to avoid losing the piece. The idea of this rule and the rule above is to avoid perpetual check draws. Some of these situations can be complicated but usually the person who is initiating the perpetual move loop must break it off.
e) The two kings cannot face each other on the same column without any pieces between them.
f) When neither side can capture the opposing king, the game is a draw.
Now your group is developing a Chinese chess software. It’s your task to write a program to check if the moves are legal or not. To simplify this problem, you needn’t to consider the rule b, c, d, f. It means that the result is not important. The only thing you need to do is to judge if the moves are legal. A move is illegal if:
a) The given coordinates of original and final position are illegal. Such as the position is out of the board, the original position is empty or your opponent’s piece or the final position is your own piece.
b) The move breaks the move rules and rules above (except rule b, c, d, f)
c) Something special, if after one move, one of the player’s king has been eaten, if it's the last move, it’s legal, or the next move is illegal. (look at the sample for more details)