Move validation inside Movebuilder using regex
This commit is contained in:
@@ -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)){
|
||||
|
Reference in New Issue
Block a user