public function getPgnMoves(Game $game, $withTime = false) { $withTime = $withTime && $game->hasMoveTimes(); if ($withTime) { $times = $game->getMoveTimes(); } $pgnMoves = $game->getPgnMoves(); if (empty($pgnMoves)) { return ''; } $moves = $game->getPgnMoves(); $nbMoves = count($moves); $nbTurns = ceil($nbMoves / 2); $string = ''; for ($turns = 1; $turns <= $nbTurns; $turns++) { $index = ($turns - 1) * 2; $string .= $turns . '. '; $string .= $moves[$index] . ' '; if ($withTime) { $string .= '{' . $times[$index] . '} '; } if (isset($moves[$index + 1])) { $string .= $moves[$index + 1] . ' '; if ($withTime) { $string .= '{' . $times[$index + 1] . '} '; } } } return trim($string); }