Exemplo n.º 1
0
 /**
  * @param string $line "Qe7 22. Nhg4 Nxg4 23. Nxg4 Na5 24. b3 Nc6"
  */
 private function addMoves($line)
 {
     $line = $this->removeAnnotations($line);
     // Remove the move numbers, so "1. e4 e5 2. f4" becomes "e4 e5 f4"
     $line = preg_replace('/\\d+\\./', '', $line);
     // Remove the result (1-0, 1/2-1/2, 0-1) from the end of the line, if there is one.
     $line = preg_replace('/(1-0|0-1|1\\/2-1\\/2|\\*)$/', '', $line);
     // If black's move is after an annotation, it is formatted as: "annotation } 17...h5".
     // Remove those dots (one is already gonee after removing "17." earlier.
     $line = str_replace('..', '', $line);
     $line = preg_replace('/\\$[0-9]/', '', $line);
     $line = preg_replace('/\\([^\\(\\)]+\\)/', '', $line);
     // And finally remove excess white-space.
     $line = trim(preg_replace('/\\s{2,}/', ' ', $line));
     $this->currentGame->setMoves($this->currentGame->getMoves() ? $this->currentGame->getMoves() . " " . $line : $line);
 }