<commit_before><?php
/**
 *
 * @package
 */
class OneUpGame extends MGMultiPlayer
{
    function __construct()
    {
        $playedGameId = -1;
        if (isset($_POST['playedGameId'])) {
            $playedGameId = $_POST['playedGameId'];
        }
        parent::__construct("OneUp", true, $playedGameId);
    }


    /**
     * @param GameTagDTO[] $tags
     * @throws CHttpException
     */
    public function submit(&$tags)
    {
        /**
         * @var GameSubmission[] $submits
         */
        $submits = GameSubmission::model()->findAll('played_game_id=:playedGameId', array(':playedGameId' => $this->playedGame->id));
        /**
         * @var string[] $submits
         */
        $playerTags = array();
        $playerTagDTOs = array();
        $opponentTagDTOs = array();
        foreach ($submits as $submit) {
            $tagsArr = json_decode($submit->submission, true);
            $tmpTags = GameTagDTO::createFromArray($tagsArr);
            if ($submit->session->user_id == $this->userId) {
                if (!isset($playerTagDTOs[$submit->turn])) {
                    $playerTagDTOs[$submit->turn] = array();
                }
                $playerTagDTOs[$submit->turn] = array_merge($playerTagDTOs[$submit->turn], $tmpTags);
                foreach ($tmpTags as $tt) {
                    array_push($playerTags, $tt->tag);
                }
            } else {
                if (!isset($opponentTagDTOs[$submit->turn])) {
                    $opponentTagDTOs[$submit->turn] = array();
                }
                $opponentTagDTOs[$submit->turn] = array_merge($opponentTagDTOs[$submit->turn], $tmpTags);
            }
        }

        if ($this->playedGame->session_id_1 == $this->sessionId) {
            $opponentId = $this->playedGame->sessionId2->user_id;
        } else {
            $opponentId = $this->playedGame->sessionId1->user_id;
        }
        $opponentOnline = UserOnline::model()->find('user_id =:userId', array(':userId' => $opponentId));
        if (isset($playerTagDTOs[$this->gameTurn->turn])) {
            $submissions = count($playerTagDTOs[$this->gameTurn->turn]);
        } else {
            $submissions = 0;
        }
        if ($submissions < $this->game->submissions) {
            foreach ($tags as &$tag) {
                $tag->type = "new";
                $tag->weight = 1;
                foreach ($opponentTagDTOs as $turn => $oTags) {
                    $found = false;
                    foreach ($oTags as $oTag) {
                        if ($oTag->tag == $tag->tag) {
                            if ($turn == $this->gameTurn->turn)
                                $tag->weight += 1;
                            else
                                $tag->weight += 2;
                            $found = true;
                            break;
                        }
                    }
                    if ($found) {
                        break;
                    }
                }
                if (in_array($tag->tag, $playerTags)) {
                    throw new CHttpException(400, Yii::t('app', 'You already submitted this word!'));
                }
                $prvTurn = $this->gameTurn->turn - 1;
                $penalty = false;
                if ($prvTurn > 0) {
                    for ($i = 1; $i <= $prvTurn; $i++) {
                        foreach ($opponentTagDTOs[$prvTurn] as $row) {
                            if ($row->tag == $tag->tag) {
                                $tag->score = -1;
                                $payload = array();
                                $payload['tag'] = $tag;
                                $payload['playedGameId'] = $this->playedGame->id;

                                $this->pushMessage($this->userOnline->user_id, MGMultiPlayer::PUSH_PENALTY, json_encode($payload));
                                $this->updateSubmitToBonus($submits, $row);
                                if ($opponentOnline) {
                                    $payload = array();
                                    $payload['tag'] = $tag;
                                    $payload['tag']->score = 1;
                                    $payload['playedGameId'] = $this->playedGame->id;
                                    $payload['opponentName'] = $this->userOnline->session->username;
                                    $this->pushMessage($opponentId, MGMultiPlayer::PUSH_BONUS, json_encode($payload));
                                }
                                $tag->score = -1;

                                //Player notified of penalty
                                //Opponent receives OneUp bonus and notification
                                if ($this->playedGame->session_id_1 == $this->sessionId) {
                                    $this->playedGame->score_2 += 1;
                                } else {
                                    $this->playedGame->score_1 += 1;
                                }
                                if (!$this->playedGame->update()) {
                                    $message = "";
                                    $errors = $this->playedGame->getErrors();<commit_msg>* score still displaying incorrectly in certain cases: it appears to have something to do with submitting a word in Round 3 that has already been submitted in Round 1. FIXED<commit_after><?php
/**
 *
 * @package
 */
class OneUpGame extends MGMultiPlayer
{
    function __construct()
    {
        $playedGameId = -1;
        if (isset($_POST['playedGameId'])) {
            $playedGameId = $_POST['playedGameId'];
        }
        parent::__construct("OneUp", true, $playedGameId);
    }


    /**
     * @param GameTagDTO[] $tags
     * @throws CHttpException
     */
    public function submit(&$tags)
    {
        /**
         * @var GameSubmission[] $submits
         */
        $submits = GameSubmission::model()->findAll('played_game_id=:playedGameId', array(':playedGameId' => $this->playedGame->id));
        /**
         * @var string[] $submits
         */
        $playerTags = array();
        $playerTagDTOs = array();
        $opponentTagDTOs = array();
        foreach ($submits as $submit) {
            $tagsArr = json_decode($submit->submission, true);
            $tmpTags = GameTagDTO::createFromArray($tagsArr);
            if ($submit->session->user_id == $this->userId) {
                if (!isset($playerTagDTOs[$submit->turn])) {
                    $playerTagDTOs[$submit->turn] = array();
                }
                $playerTagDTOs[$submit->turn] = array_merge($playerTagDTOs[$submit->turn], $tmpTags);
                foreach ($tmpTags as $tt) {
                    array_push($playerTags, $tt->tag);
                }
            } else {
                if (!isset($opponentTagDTOs[$submit->turn])) {
                    $opponentTagDTOs[$submit->turn] = array();
                }
                $opponentTagDTOs[$submit->turn] = array_merge($opponentTagDTOs[$submit->turn], $tmpTags);
            }
        }

        if ($this->playedGame->session_id_1 == $this->sessionId) {
            $opponentId = $this->playedGame->sessionId2->user_id;
        } else {
            $opponentId = $this->playedGame->sessionId1->user_id;
        }
        $opponentOnline = UserOnline::model()->find('user_id =:userId', array(':userId' => $opponentId));
        if (isset($playerTagDTOs[$this->gameTurn->turn])) {
            $submissions = count($playerTagDTOs[$this->gameTurn->turn]);
        } else {
            $submissions = 0;
        }
        if ($submissions < $this->game->submissions) {
            foreach ($tags as &$tag) {
                $tag->type = "new";
                $tag->weight = 1;
                foreach ($opponentTagDTOs as $turn => $oTags) {
                    $found = false;
                    foreach ($oTags as $oTag) {
                        if ($oTag->tag == $tag->tag) {
                            if ($turn == $this->gameTurn->turn)
                                $tag->weight += 1;
                            else
                                $tag->weight += 2;
                            $found = true;
                            break;
                        }
                    }
                    if ($found) {
                        break;
                    }
                }
                if (in_array($tag->tag, $playerTags)) {
                    throw new CHttpException(400, Yii::t('app', 'You already submitted this word!'));
                }
                $prvTurn = $this->gameTurn->turn - 1;
                $penalty = false;
                if ($prvTurn > 0) {
                    for ($i = 1; $i <= $prvTurn; $i++) {
                        foreach ($opponentTagDTOs[$i] as $row) {
                            if ($row->tag == $tag->tag) {
                                $tag->score = -1;
                                $payload = array();
                                $payload['tag'] = $tag;
                                $payload['playedGameId'] = $this->playedGame->id;

                                $this->pushMessage($this->userOnline->user_id, MGMultiPlayer::PUSH_PENALTY, json_encode($payload));
                                $this->updateSubmitToBonus($submits, $row);
                                if ($opponentOnline) {
                                    $payload = array();
                                    $payload['tag'] = $tag;
                                    $payload['tag']->score = 1;
                                    $payload['playedGameId'] = $this->playedGame->id;
                                    $payload['opponentName'] = $this->userOnline->session->username;
                                    $this->pushMessage($opponentId, MGMultiPlayer::PUSH_BONUS, json_encode($payload));
                                }
                                $tag->score = -1;

                                //Player notified of penalty
                                //Opponent receives OneUp bonus and notification
                                if ($this->playedGame->session_id_1 == $this->sessionId) {
                                    $this->playedGame->score_2 += 1;
                                } else {
                                    $this->playedGame->score_1 += 1;
                                }
                                if (!$this->playedGame->update()) {
                                    $message = "";
                                    $errors = $this->playedGame->getErrors();
{'fraction_non_alphanumeric': 0.1356076356076356, 'fraction_numerical': 0.004347004347004347, 'mean_word_length': 1.182061855670103, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 153, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '931084', 'n_tokens_mistral': 2855, 'n_tokens_neox': 2655, 'n_words': 467}