Get the opponent of a player
@param int $player The player
@return int|bool The integer representing the opponent if found
542646
private function getOpponentPlayer($player)
    {
        if (!in_array($player, $this->players)) {
            return false;
        }

        $opponentArray = array_diff($this->players, [$player]);

        return array_shift($opponentArray);
    }
47700
private function calculateExperience($playerA, $playerB)
    {
        $difference = $playerB->getElo() - $playerA->getElo();
        $exp = $difference / $this->configuration->getFloor();

        return 1/(1 + pow(10, $exp));
    }
851581
public function play($game, $user, &$error = null)
    {
        //some entries can stay open during days.
        // The player can take back the entry to go on playing
        // like in a postvote or for quizzes
        // We create also an entry before the game when an optin is needed
        $entry = $this->checkExistingEntry($game, $user, true);

        // If the game needs an optin and the player has not opted in
        if ($entry && $game->getTermsOptin() && !$entry->getTermsOptin()) {
            $error = -2;
            return false;
        }

        // If the game has a cost and the player has not paid yet
        // (this case occurs when the entry has been created by the termsOptin
        // and the game has a price to play)
        if ($entry && !$entry->getPaid() && $game->getCostToPlay() > 0) {
            if (!$this->payToPlay($game, $user, $entry)) {
                $error = -3;
                return false;
            } else {
                $entry->setPaid(1);
                $entry->setPaidAmount($game->getCostToPlay());
                $entry = $this->getEntryMapper()->update($entry);
            }
        }

        if (! $entry) {
            // Play limit reached
            if ($this->hasReachedPlayLimit($game, $user)) {
                $error = -1;
                return false;
            }
            // Can't pay for the game
            if (!$this->canPayToPlay($game, $user)) {
                $error = -3;
                return false;
            }
            // Terms optin not checked
            if ($game->getTermsOptin()) {
                $error = -2;
                return false;
            }

            $ip = $this->getIp();
            $geoloc = $this->getGeoloc($ip);
            $entry = new Entry();
            $entry->setGame($game);
            $entry->setUser($user);
            $entry->setPoints(0);
            $entry->setIp($ip);
            $entry->setGeoloc($geoloc);
            $entry->setAnonymousId($this->getAnonymousId());
            
            if ($this->getAnonymousIdentifier()) {
                $entry->setAnonymousIdentifier($this->getAnonymousIdentifier());
            }
            if ($game->getCostToPlay() === 0) {
                $entry->setPaid(true);
                $entry = $this->getEntryMapper()->insert($entry);
                $this->getEventManager()->trigger(
                    __FUNCTION__ . '.post',
                    $this,
                    [
                        'user' => $user,
                        'game' => $game,
                        'entry' => $entry,
                    ]
                );
            } else {
                $entry = $this->getEntryMapper()->insert($entry);
                $entryPaid = $this->payToPlay($game, $user, $entry);
                if ($entryPaid) {
                    $entry = $this->getEntryMapper()->update($entryPaid);
                    $this->getEventManager()->trigger(
                        __FUNCTION__ . '.post',
                        $this,
                        [
                            'user' => $user,
                            'game' => $game,
                            'entry' => $entry,
                        ]
                    );
                } else {
                    $entry->setActive(false);
                    $entry = $this->getEntryMapper()->update($entry);
                    $error = -3;
                    return false;
                }
            }
        }

        return $entry;
    }
1240332
public function start(Player $player, $params)
    {
        $this->currentVote = new Vote($player, $this->getCode(), $params);
        return $this->currentVote;
    }
1088613
public function playerPushesAllIn(PlayerContract $player)
    {
        $this->checkPlayerTryingToAct($player);

        // got the players chipStack
        $chips = $player->chipStack();

        // gotta create a new chip obj here cause of PHPs /awesome/ objRef ability :D
        $this->actions()->push(new Action($player, Action::ALLIN, ['chips' => Chips::fromAmount($chips->amount())]));

        $this->placeChipBet($player, $chips);
        $this->leftToAct = $this->leftToAct()->playerHasActioned($player, LeftToAct::ALLIN);
    }
1005765
public function getItemId(Item $item)
    {
        /* @var $source \AnimeDb\Bundle\CatalogBundle\Entity\Source */
        foreach ($item->getSources() as $source) {
            if (strpos($source->getUrl(), $this->browser->getHost()) === 0 &&
                preg_match(self::REG_ITEM_ID, $source->getUrl(), $match)
            ) {
                return (int)$match['id'];
            }
        }
        return 0;
    }
660621
public function getWinner()
    {
        if (!$this->isGameOver()) {
            return null;
        }

        if ($this->getScore(self::PLAYER_0) === $this->getScore(self::PLAYER_1)) {
            return self::DRAW;
        } elseif ($this->getScore(self::PLAYER_0) > $this->getScore(self::PLAYER_1)) {
            return self::PLAYER_0;
        } else {
            return self::PLAYER_1;
        }
    }
944881
public function onPlayerConnect(Player $playerData)
    {
        $login = $playerData->getLogin();

        $this->online[$login] = $playerData;

        if ($playerData->isSpectator()) {
            $this->spectators[$login] = $playerData;
        } else {
            $this->players[$login] = $playerData;
        }
    }
901464
public function playerRaises(PlayerContract $player, Chips $chips)
    {
        $this->checkPlayerTryingToAct($player);

        $highestChipBet = $this->highestBet();
        if ($chips->amount() < $highestChipBet->amount()) {
            throw RoundException::raiseNotHighEnough($chips, $highestChipBet);
        }

        $chipStackLeft = Chips::fromAmount($player->chipStack()->amount() - $chips->amount());
        if ($chipStackLeft->amount() === 0) {
            return $this->playerPushesAllIn($player, $chips);
        }

        $betAmount = Chips::fromAmount($highestChipBet->amount() + $chips->amount());

        $this->actions->push(new Action($player, Action::RAISE, ['chips' => $betAmount]));
        $this->placeChipBet($player, $betAmount);

        $action = $chipStackLeft->amount() === 0 ? LeftToAct::ALLIN : LeftToAct::AGGRESSIVELY_ACTIONED;
        $this->leftToAct = $this->leftToAct()->playerHasActioned($player, $action);
    }
446119
function unBan($player, $multicall = false)
    {
        $login = $this->getLogin($player);
        if ($login === false) {
            throw new InvalidArgumentException('player = ' . print_r($player, true));
        }

        return $this->execute(ucfirst(__FUNCTION__), array($login), $multicall);
    }
1099907
public function payToPlay($game, $user, $entry)
    {
        // Is there a limitation on the game ?
        $cost = $game->getCostToPlay();
        if ($cost && $cost > 0) {
            if ($this->canPayToPlay($game, $user)) {
                $entry->setPaid(true);
                $entry->setPaidAmount(-$cost);
                $leaderboard = $this->getEventManager()->trigger(
                    'leaderboardUserUpdate',
                    $this,
                    [
                        'user' => $user,
                        'game' => $game,
                        'points' => -$cost,
                        'entry' => $entry,
                    ]
                )->last();

                return $entry;
            }
        } else {
            $entry->setPaid(true);
            return $entry;
        }

        return false;
    }
207329
public function checkPlayer($player)
    {
        if (!in_array($player, array(self::PLAYER_0, self::PLAYER_1))) {
            throw new AwaleException('Invalid player value.');
        }

        return $this;
    }
101626
public function isMoveFeedsOpponent($player, $move)
    {
        if (self::PLAYER_0 === $player) {
            return $this->grid[$player]['seeds'][$move] > $move;
        } else {
            return $this->grid[$player]['seeds'][$move] > (5 - $move);
        }
    }
943279
def getPlayer(name):
    """"""
    if isinstance(name, PlayerRecord): return name
    try:    return getKnownPlayers()[name.lower()]
    except KeyError:
        raise ValueError("given player name '%s' is not a known player definition"%(name))
299844
public function onPlayerChat(Player $player, $text)
    {
        if ($player->getPlayerId() === 0) {
            return;
        }
        if (substr($text, 0, 1) == "/") {
            return;
        }

        if ($text == "++") {
            $this->setVote($player->getLogin(), 100);
        }

        if ($text == "--") {
            $this->setVote($player->getLogin(), 0);
        }

    }
975698
private function estimateRange(EloPlayerInterface $player)
    {
        $baseRange = new ArrayCollection($this->configuration->getBaseRange());
        $keys = array_keys($this->configuration->getBaseRange());
        $estimatedRange = $baseRange->first();

        $i = 0;
        foreach ($baseRange as $eloMin => $range) {
            if (!isset($keys[$i +1]) && $player->getElo() > $baseRange->last()) {
                $estimatedRange = $baseRange->last();
                break;
            }

            if ($player->getElo() >= $eloMin && isset($keys[$i +1]) && $player->getElo() <= $keys[$i +1]) {
                $estimatedRange = $range;
                break;
            }

            $i++;
        }

        return $estimatedRange;
    }
745177
public function playerCalls(PlayerContract $player)
    {
        $this->checkPlayerTryingToAct($player);

        $highestChipBet = $this->highestBet();

        // current highest bet - currentPlayersChipStack
        $amountLeftToBet = Chips::fromAmount($highestChipBet->amount() - $this->playerBetStack($player)->amount());

        $chipStackLeft = Chips::fromAmount($player->chipStack()->amount() - $amountLeftToBet->amount());

        if ($chipStackLeft->amount() <= 0) {
            $amountLeftToBet = Chips::fromAmount($player->chipStack()->amount());
            $chipStackLeft = Chips::zero();
        }

        $action = $chipStackLeft->amount() === 0 ? Action::ALLIN : Action::CALL;
        $this->actions->push(new Action($player, $action, ['chips' => $amountLeftToBet]));

        $this->placeChipBet($player, $amountLeftToBet);

        $action = $chipStackLeft->amount() === 0 ? LeftToAct::ALLIN : LeftToAct::ACTIONED;
        $this->leftToAct = $this->leftToAct()->playerHasActioned($player, $action);
    }