Ejemplo n.º 1
0
 protected function createGenericForm($persistedName, $rangeable = false)
 {
     $isAuthenticated = $this->security->isGranted('IS_AUTHENTICATED_REMEMBERED');
     $config = new GameConfig();
     $config->fromArray($this->configPersistence->loadConfigFor($persistedName));
     return $this->formFactory->create(new GameConfigFormType($isAuthenticated, true, $rangeable), $config);
 }
Ejemplo n.º 2
0
 public function waitFriendAction($id)
 {
     $player = $this->get('lichess.provider')->findPlayer($id);
     if ($player->getGame()->getIsStarted()) {
         return new RedirectResponse($this->generateUrl('lichess_player', array('id' => $id)));
     }
     $config = new GameConfig();
     $config->fromArray($this->get('session')->get('lichess.game_config.friend', array()));
     return $this->render('LichessBundle:Player:waitFriend.html.twig', array('player' => $player, 'config' => $config->createView()));
 }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
0
 public function fromArray(array $data)
 {
     parent::fromArray($data);
     if (isset($data['level'])) {
         $this->level = $data['level'];
     }
 }
Ejemplo n.º 5
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;
 }
Ejemplo n.º 6
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;
 }
Ejemplo n.º 7
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;
 }
Ejemplo n.º 8
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())));
 }
Ejemplo n.º 9
0
 protected function loadFriendGame($color, $username1, $username2, array $configArray = array())
 {
     $config = new GameConfig();
     $config->fromArray($configArray);
     $config->setColor($color);
     $player = $this->friendStarter->start($config);
     $game = $player->getGame();
     if ($username1) {
         $this->blamePlayerWithUsername($player, $username1);
     }
     if ($username2) {
         $this->blamePlayerWithUsername($player->getOpponent(), $username2);
     }
     $game->start();
     return $game;
 }