Esempio n. 1
0
 /**
  * @param string $asciiBoard
  *
  * @return Board
  */
 public static function fromAscii($asciiBoard)
 {
     $asciiBoard = trim($asciiBoard);
     $squares = [];
     $rows = array_map('trim', explode("\n", trim($asciiBoard)));
     unset($rows[8]);
     unset($rows[9]);
     foreach ($rows as $x => $row) {
         $rowNumber = 8 - $x;
         $columns = array_map('trim', explode(' ', substr($row, 5)));
         foreach ($columns as $y => $pieceAscii) {
             $columnNumber = $y + 1;
             if ($pieceAscii === '…') {
                 $piece = null;
             } else {
                 $piece = PieceDecorator::fromAscii($pieceAscii);
             }
             $position = intval($columnNumber . $rowNumber);
             $squares[] = new Square($position, $piece);
         }
     }
     $board = BoardFactory::create($squares);
     return $board;
 }