public function createPieces(Game $game) { $pieces = array(); $player = $game->getPlayer('white'); // Bishop on black square $file = 2 * mt_rand(1, 4) - 1; $pieces[$file] = $this->createPiece('Bishop', $file, 1); // Bishop on white square $file = 2 * mt_rand(1, 4); $pieces[$file] = $this->createPiece('Bishop', $file, 1); // Queen and Knights foreach (array(6 => 'Queen', 5 => 'Knight', 4 => 'Knight') as $rand => $class) { $file = $this->getEmptyFile($pieces, mt_rand(1, $rand)); $pieces[$file] = $this->createPiece($class, $file, 1); } // Rooks and King foreach (array('Rook', 'King', 'Rook') as $class) { $file = $this->getEmptyFile($pieces, 1); $pieces[$file] = $this->createPiece($class, $file, 1); } // Pawns for ($it = 1; $it <= 8; $it++) { $pieces[] = $this->createPiece('Pawn', $it, 2); } $pieces = array_values($pieces); $player->setPieces($pieces); $player->getOpponent()->setPieces($this->mirrorPieces($pieces)); $game->ensureDependencies(); $game->setInitialFen(Forsyth::export($game)); }
/** * @dataProvider fenProvider */ public function testImportExport($fen) { $game = $this->createGame(); Forsyth::import($game, $fen); $simplifyFen = function ($fen) { return substr($fen, 0, strpos($fen, ' ')); }; $this->assertEquals($simplifyFen($fen), $simplifyFen(Forsyth::export($game))); }
public function move(Game $game, $level) { $oldForsyth = Forsyth::export($game); // hack to have chess960 working with Crafty if (!$game->isStandardVariant()) { $oldForsyth = $this->removeCastlingInfos($oldForsyth); } $newForsyth = $this->getNewForsyth($oldForsyth, $level); $move = Forsyth::diffToMove($game, $newForsyth); return $move; }
public function renderGameFen(Game $game, User $user = null) { $fenString = Forsyth::export($game, true); $player = $game->getPlayerByUserOrCreator($user); $authUser = $this->container->get('security.context')->getToken()->getUser(); if ($authUser instanceof User && ($authPlayer = $game->getPlayerByUser($authUser))) { $gameUrl = $this->getRouterGenerator()->generate('lichess_player', array('id' => $authPlayer->getFullId())); } else { $gameUrl = $this->getRouterGenerator()->generate('lichess_game', array('id' => $game->getId(), 'color' => $player->getColor())); } return sprintf('<a href="%s" title="%s" class="mini_board parse_fen" data-color="%s" data-fen="%s"></a>', $gameUrl, $this->getTranslator()->trans('View in full size'), $player->getColor(), $fenString); }