Details
Your friend recently has shown you some chess puzzles he found somewhere. It’s not your ordinary chess: but the mysterious, distinct relative of chess, the legendary 象棋, also known as Xiangqi/Chinese chess! As a Chinese, you know that your friend doesn’t know anything in Chinese besides recognizing a few sigils (for example, he doesn’t know what is 七步擒士
or 雙馬飲泉
), so it’s probably likely that the “puzzles” he got is actually bogus, and the pieces are not placed properly. However, you don’t want to actually teach him Xiangqi either (yet), so the best tactic you could come up with is to write a validator program and let your friend use it instead of using you.
You will be given an ASCII board. Xiangqi board is 9 tiles wide and 10 tiles high, with the pieces placed as follows:
Example (the starting Xiangqi board):
車馬象士將士象馬車
|X|
砲 +-+ 砲
卒 卒 卒 卒 卒
---------
---------
兵 兵 兵 兵 兵
炮 +-+ 炮
|X|
俥傌相仕帥仕相傌俥
The bottom and top half corresponds to red and black pieces, respectively.
Note that red and black have different characters to distinguish the same piece of both sides.
Your function, chessValidator
, should determine whether the pieces in argument board
are placed legally. Unlike the chess you’re familiar with, there are restrictions as to where the various chess pieces can be at: