【发布时间】:2014-05-13 18:05:42
【问题描述】:
Place a piece on the board (ex: Qld1 – place the white queen on D1, Kde8 – place the black king on E8). Piece abbreviations are:
K = king
Q = queen
B = bishop
N = knight
R = rook
P = pawn
and l = light, d = dark.
Move a single piece on the board (ex: d8 h4 – moves the piece at D8 to the square at H4, c4 d6* - moves the piece at C4 to D6 and captures the piece at D6).
Move two pieces in a single turn (ex: e1 g1 h1 f1 – moves the king from E1 to G1 and moves the rook from H1 to F1. This is called a “king-side castle”).
我需要帮助编写一个正则表达式来获取列出的所有选项。我已经走到这一步了:
([KQNBR]?([a-h]?[1-8]?x)?[a-h]([2-7]|[18](=[KQNBR])?)|0-0(-0)?)(\(ep\)|\+{1,2})?
或
([BKNPQR]?)([a-h]?)([0-9]?)([x=]?)([BKNPQR\*]|[a-h][1-8])([+#]?)
在决定棋盘将采用非常不同的自定义符号来处理移动之前。
问题是我需要帮助来创建将验证这些国际象棋动作的正则表达式。
一个例子是,这个程序不会实时操纵棋盘。但是,文件将从流中逐行读取,您的国际象棋游戏的控制台应用程序应读取每一行并为每个移动生成以下结果。
文件的前几行应该读取每个棋子 Qld1 的位置,它将白皇后放在 D1 上,kde8 将黑王放在 E8 上。
之后文件会读取每一个动作,d8 h4会将d8位置的棋子移动到h4。
单个正则表达式将验证要读取的文本文件是否是基于其表达式的有效移动。如果无效,请跳过移动并继续。
【问题讨论】:
-
这里有什么问题?
-
我想:“你能帮我写一个正则表达式来获取所有列出的选项吗”。
-
能否为类似问题提供正则表达式解决方案:codegolf.stackexchange.com/questions/25018/tell-me-the-moves
-
我更新了一些信息。它将全部从文件中读取。
标签: regex expression notation