Move validation inside Movebuilder using regex

This commit is contained in:
Alf Magne Kalleland
2013-02-18 20:31:36 +01:00
parent 1dfda67d61
commit ee52853327
3 changed files with 52 additions and 1 deletions

View File

@@ -18,7 +18,7 @@ class MoveBuilder {
}
private function addMove($move){
if(!$move || $move == '..' || $move == '*' || strstr($move, '1-') || strstr($move, '-1') || strstr($move, '1/2')){
if(!$this->isChessMove($move)){
return;
}
$move = preg_replace("/^([a-h])([18])([QRNB])$/", "$1$2=$3", $move );
@@ -26,6 +26,10 @@ class MoveBuilder {
$this->currentIndex ++;
}
private function isChessMove($move){
return preg_match("/([PNBRQK]?[a-h]?[1-8]?x?[a-h][1-8](?:\=[PNBRQK])?|O(-?O){1,2})[\+#]?(\s*[\!\?]+)?/s", $move);
}
public function addCommentBeforeFirstMove($comment){
$comment = trim($comment);
if(!strlen($comment)){