Пример #1
0
 public function start(GameConfig $config)
 {
     $color = $config->resolveColor();
     $player = $this->generator->createGameForPlayer($color, $config->getVariant());
     $game = $player->getGame();
     if ($config->getClock()) {
         $clock = new Clock($config->getTime() * 60, $config->getIncrement());
         $game->setClock($clock);
     }
     $game->setIsRated($config->getMode());
     $this->objectManager->persist($game);
     $this->logger->notice($game, 'Game:api create');
     return $player;
 }
Пример #2
0
 public function start(GameConfig $config)
 {
     $this->configPersistence->saveConfigFor('ai', $config->toArray());
     $color = $config->resolveColor();
     $player = $this->generator->createGameForPlayer($color, $config->getVariant());
     $this->playerBlamer->blame($player);
     $game = $player->getGame();
     $opponent = $player->getOpponent();
     $opponent->setIsAi(true);
     $opponent->setAiLevel($config->getLevel());
     $this->starter->start($game);
     $this->objectManager->persist($game);
     return $player;
 }
Пример #3
0
 public function start(GameConfig $config)
 {
     $this->configPersistence->saveConfigFor('friend', $config->toArray());
     $color = $config->resolveColor();
     $player = $this->generator->createGameForPlayer($color, $config->getVariant());
     $this->playerBlamer->blame($player);
     $game = $player->getGame();
     if ($config->getClock()) {
         $clock = new Clock($config->getTime() * 60, $config->getIncrement());
         $game->setClock($clock);
     }
     $game->setIsRated($config->getMode());
     $this->objectManager->persist($game);
     $this->logger->notice($game, 'Game:inviteFriend create');
     return $player;
 }
Пример #4
0
 public function start(GameConfig $config)
 {
     $this->configPersistence->saveConfigFor('ai', $config->toArray());
     $color = $config->resolveColor();
     $player = $this->generator->createGameForPlayer($color, $config->getVariant());
     $this->playerBlamer->blame($player);
     $game = $player->getGame();
     $opponent = $player->getOpponent();
     $opponent->setIsAi(true);
     $opponent->setAiLevel($config->getLevel());
     $game->start();
     if ($player->isBlack()) {
         $this->manipulatorFactory->create($game)->play($this->ai->move($game, $opponent->getAiLevel()));
     }
     $this->objectManager->persist($game);
     $this->logger->notice($game, 'Game:inviteAi create');
     return $player;
 }
Пример #5
0
 public function joinAction($id)
 {
     $hook = $this->get('lichess_opening.hook_repository')->findOneById($id);
     $myHookId = $this->get('request')->query->get('cancel');
     // hook is not available anymore
     // hook elo range does not let me in
     if (!$hook || $hook->isMatch() || !$hook->userCanJoin($this->get('security.context')->getToken()->getUser())) {
         if ($myHookId) {
             return new RedirectResponse($this->generateUrl('lichess_hook', array('id' => $myHookId)));
         }
         return new RedirectResponse($this->generateUrl('lichess_homepage'));
     }
     // if I also have a hook, cancel it
     $myHook = null;
     if ($myHookId) {
         $myHook = $this->get('lichess_opening.hook_repository')->findOneByOwnerId($myHookId);
     }
     $config = new GameConfig();
     $config->fromArray($hook->toArray());
     $color = $config->resolveColor();
     $opponent = $this->get('lichess.generator')->createGameForPlayer($color, $config->getVariant());
     $opponent->setUser($hook->getUser());
     $player = $opponent->getOpponent();
     $this->get('lichess.blamer.player')->blame($player);
     $game = $player->getGame();
     if ($config->getClock()) {
         $clock = new Clock($config->getTime() * 60, $config->getIncrement());
         $game->setClock($clock);
     }
     $game->setIsRated($config->getMode());
     $messages = $this->get('lichess.starter.game')->start($game);
     $hook->setGame($game);
     $this->get('doctrine.odm.mongodb.document_manager')->persist($game);
     $this->get('doctrine.odm.mongodb.document_manager')->flush(array('safe' => true));
     $this->get('lila')->lobbyJoin($player, $messages, $hook, $myHook);
     return new RedirectResponse($this->generateUrl('lichess_player', array('id' => $player->getFullId())));
 }