コード例 #1
0
ファイル: Rematcher.php プロジェクト: hafeez3000/lichess
 protected function acceptRematch(Player $player)
 {
     $game = $player->getGame();
     $opponent = $player->getOpponent();
     // if the rematch is already accepted
     // can happen if the guy clicks frenetically
     // on the rematch accept button
     if ($nextGame = $game->getNext()) {
         $nextOpponent = $nextGame->getPlayer($player->getColor());
         $nextPlayer = $nextOpponent->getOpponent();
     } else {
         $nextOpponent = $this->gameGenerator->createReturnGame($opponent);
         $nextPlayer = $nextOpponent->getOpponent();
         $nextGame = $nextOpponent->getGame();
         $this->logger->notice($player, 'Player:rematch accept');
         $this->messenger->addSystemMessage($game, 'Rematch offer accepted');
         $nextGame->start();
         $this->memory->setAlive($nextPlayer);
         // the opponent still pings the old game,
         // so we set it as active on the new game
         if ($this->memory->getActivity($opponent)) {
             $this->memory->setAlive($nextOpponent);
         }
     }
     // tell spectators to reload the table
     $game->addEventToStacks(array('type' => 'reload_table'));
     // tell players to move to next game
     foreach (array(array($player, $nextPlayer), array($opponent, $nextOpponent)) as $pair) {
         $pair[0]->addEventToStack(array('type' => 'redirect', 'url' => $this->urlGenerator->generate('lichess_player', array('id' => $pair[1]->getFullId()))));
     }
     $this->objectManager->persist($nextGame);
 }
コード例 #2
0
ファイル: ClientUpdater.php プロジェクト: hafeez3000/lichess
 public function getEventsSinceClientVersion(Player $player, $clientVersion, $withPrivateEvents)
 {
     $game = $player->getGame();
     $version = $player->getStack()->getVersion();
     $opponentActivity = $this->memory->getActivity($player->getOpponent());
     $currentPlayerColor = $game->getTurnColor();
     try {
         $events = $version != $clientVersion ? $this->getDiffEvents($player, $clientVersion) : array();
     } catch (OutOfBoundsException $e) {
         return array('reload' => true);
     }
     // remove private events if user is spectator
     if (!$withPrivateEvents) {
         foreach ($events as $index => $event) {
             if ('message' === $event['type'] || 'redirect' === $event['type']) {
                 unset($events[$index]);
             }
         }
     } else {
         // render room messages
         foreach ($events as $index => $event) {
             if ('message' === $event['type']) {
                 $events[$index]['html'] = $this->roomMessageRenderer->renderRoomMessage($event['message']);
                 unset($events[$index]['message']);
             }
         }
     }
     $data = array('v' => $version, 'oa' => $opponentActivity, 'e' => $events, 'p' => $currentPlayerColor, 't' => $game->getTurns());
     if ($game->hasClock()) {
         $data['c'] = $game->getClock()->getRemainingTimes();
     }
     return $data;
 }
コード例 #3
0
ファイル: Joiner.php プロジェクト: hotfics/lichess-old
 public function join(Player $player)
 {
     $game = $player->getGame();
     if ($game->getIsStarted()) {
         return false;
     }
     $this->playerBlamer->blame($player);
     return $this->starter->start($game);
 }
コード例 #4
0
ファイル: Mover.php プロジェクト: hafeez3000/lichess
 /**
  * After the player has moved, run the AI to get the next move applied immediatly
  *
  * @param Player $player
  * @return void
  */
 protected function performAiAnswer(Player $player)
 {
     $game = $player->getGame();
     $opponent = $player->getOpponent();
     $stack = new Stack();
     $manipulator = $this->manipulatorFactory->create($game, $stack);
     $possibleMoves = $manipulator->play($this->ai->move($game, $opponent->getAiLevel()));
     $player->addEventToStack(array('type' => 'possible_moves', 'possible_moves' => $possibleMoves));
     $player->addEventsToStack($stack->getEvents());
 }
コード例 #5
0
ファイル: Joiner.php プロジェクト: hafeez3000/lichess
 public function join(Player $player)
 {
     $game = $player->getGame();
     if ($game->getIsStarted()) {
         $this->logger->warn($player, 'Game:join started');
         throw new InvalidArgumentException('Cannot join started game');
     }
     $this->playerBlamer->blame($player);
     $game->start();
     $player->getOpponent()->addEventToStack(array('type' => 'redirect', 'url' => $this->urlGenerator->generate('lichess_player', array('id' => $player->getOpponent()->getFullId()))));
     $this->logger->notice($player, 'Game:join');
 }
コード例 #6
0
ファイル: Generator.php プロジェクト: hotfics/lichess-old
 /**
  * Creates a return game for the given player,
  * reverting players colors
  *
  * @param  Player the player who creates the return game
  * @return Player the new player on the new game
  **/
 public function createReturnGame(Player $player)
 {
     $game = $player->getGame();
     $variant = $game->getVariant();
     $nextGame = $this->createGame($variant);
     if (Game::VARIANT_960 == $game->getVariant()) {
         Forsyth::import($nextGame, $game->getInitialFen());
         $nextGame->setInitialFen($game->getInitialFen());
     }
     $nextPlayer = $nextGame->getPlayer($player->getOpponent()->getColor());
     $nextGame->setCreator($nextPlayer);
     if ($game->hasClock()) {
         $nextGame->setClock(clone $game->getClock());
     }
     $nextGame->setIsRated($game->getIsRated());
     $nextGame->getPlayer('white')->setUser($game->getPlayer('black')->getUser());
     $nextGame->getPlayer('black')->setUser($game->getPlayer('white')->getUser());
     $game->setNext($nextGame);
     return $nextPlayer;
 }
コード例 #7
0
ファイル: Rematcher.php プロジェクト: hotfics/lichess-old
 protected function acceptRematch(Player $player)
 {
     $game = $player->getGame();
     $opponent = $player->getOpponent();
     // if the rematch is already accepted
     // can happen if the guy clicks frenetically
     // on the rematch accept button
     if ($nextGame = $game->getNext()) {
         $nextOpponent = $nextGame->getPlayer($player->getColor());
         $nextPlayer = $nextOpponent->getOpponent();
         $messages = array();
     } else {
         $nextOpponent = $this->gameGenerator->createReturnGame($opponent);
         $nextPlayer = $nextOpponent->getOpponent();
         $nextGame = $nextOpponent->getGame();
         $messages = $this->starter->start($nextGame);
         $this->objectManager->persist($nextGame);
     }
     return array($nextGame, $messages);
 }
コード例 #8
0
ファイル: Piece.php プロジェクト: hafeez3000/lichess
 public function getGame()
 {
     return $this->player->getGame();
 }
コード例 #9
0
ファイル: Synchronizer.php プロジェクト: hafeez3000/lichess
 public function synchronize(Player $player, $version, $isSigned)
 {
     $player->getGame()->cachePlayerVersions();
     $this->httpPush->poll($player, $version);
     return $this->clientUpdater->getEventsSinceClientVersion($player, $version, $isSigned);
 }
コード例 #10
0
 public function renderGameBoard(Player $player, $checkSquareKey)
 {
     $board = $player->getGame()->getBoard();
     $squares = $board->getSquares();
     $isGameStarted = $player->getGame()->getIsStarted();
     if ($player->isBlack()) {
         $squares = array_reverse($squares, true);
     }
     $x = $y = 1;
     $html = '<div class="lichess_board">';
     foreach ($squares as $squareKey => $square) {
         $html .= sprintf('<div class="lcs %s%s" id="%s" style="top:%dpx;left:%dpx;">', $square->getColor(), $checkSquareKey === $squareKey ? ' check' : '', $squareKey, 64 * (8 - $x), 64 * ($y - 1));
         $html .= '<div class="lcsi"></div>';
         if ($piece = $board->getPieceByKey($squareKey)) {
             if ($isGameStarted || $piece->getPlayer() === $player) {
                 $html .= sprintf('<div class="lichess_piece %s %s"></div>', strtolower($piece->getClass()), $piece->getColor());
             }
         }
         $html .= '</div>';
         if (++$x === 9) {
             $x = 1;
             ++$y;
         }
     }
     $html .= '</div>';
     return $html;
 }
コード例 #11
0
ファイル: Judge.php プロジェクト: hafeez3000/lichess
 protected function calculateBlurFactor(Player $player)
 {
     $blurs = $player->getGame()->getBlurs();
     return round(100 * max(0, min(1, $blurs[$player->getColor()] / $player->getGame()->getFullmoveNumber())));
 }
コード例 #12
0
ファイル: Memory.php プロジェクト: hafeez3000/lichess
 public function getPlayerKey(Player $player)
 {
     return $player->getGame()->getId() . '.' . $player->getColor() . '.alive';
 }
コード例 #13
0
ファイル: Messenger.php プロジェクト: hafeez3000/lichess
 public function addPlayerMessage(Player $player, $message)
 {
     return $this->addMessage($player->getGame(), $player->getColor(), $message);
 }
コード例 #14
0
ファイル: Lila.php プロジェクト: hotfics/lichess-old
 private function gameColorUrl(Player $player)
 {
     return $player->getGame()->getId() . '/' . $player->getColor();
 }
コード例 #15
0
ファイル: Drawer.php プロジェクト: hafeez3000/lichess
 /**
  * The player cancels his previous draw offer
  *
  * @param Player $player
  * @return void
  */
 public function cancel(Player $player)
 {
     $game = $player->getGame();
     if ($player->getIsOfferingDraw()) {
         $this->messenger->addSystemMessage($game, 'Draw offer canceled');
         $player->setIsOfferingDraw(false);
         $player->getOpponent()->addEventToStack(array('type' => 'reload_table'));
         $this->logger->notice($player, 'Player:cancelDrawOffer');
     } else {
         $this->logger->warn($player, 'Player:cancelDrawOffer no offered draw');
     }
 }
コード例 #16
0
ファイル: Logger.php プロジェクト: hotfics/lichess-old
 public function expandPlayer(Player $player)
 {
     return sprintf('player(%s,%s,%s,%s) %s', $player->getColor(), $player->getIsAi() ? 'AI' : $player->getUsernameWithElo(), $player->getGame()->hasClock() ? $player->getGame()->getClock()->getRemainingTime($player->getColor()) . 's.' : '-', $this->generator->generate('lichess_player', array('id' => $player->getFullId()), true), $this->expandGame($player->getGame()));
 }
コード例 #17
0
ファイル: Finisher.php プロジェクト: hafeez3000/lichess
 /**
  * The player resigns and loses the game
  *
  * @param Player $player
  * @return void
  */
 public function resign(Player $player)
 {
     $game = $player->getGame();
     if (!$game->isResignable()) {
         $this->logger->warn($player, 'Player:resign non-resignable');
         throw new FinisherException();
     }
     $opponent = $player->getOpponent();
     $game->setStatus(Game::RESIGN);
     $game->setWinner($opponent);
     $this->finish($game);
     $game->addEventToStacks(array('type' => 'end'));
     $this->logger->notice($player, 'Player:resign');
 }