<commit_before>#include <functional>
#include <utility>
#include <tuple>
#include <vector>
#include <array>
#include <iostream>
#include <random>
#include <algorithm>
#include "Common.h"
#include <array>
#include <string>
#include <iostream>
#include <vector>
#include <memory>
#include <map>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_mixer.h>
#include <SDL/SDL_ttf.h>
#include "Vipper/Vipper.h"
#include "Modules/Gameplay/Entities/CLevel.h"

namespace RunTheWorld {

    void CLevel::reset() {
        timeEllapsed = 0;
    }

    CLevel::CLevel() {
        gameState = EGameState::kGame;
        reset();

        std::random_device rd;
        std::mt19937 gen(rd());

        std::uniform_real_distribution<> speedRandom(1.0f, 50.0f);
        std::uniform_real_distribution<> laneRandom(-1.0f, 1.0f);
        std::uniform_real_distribution<> positionRandom( 10, track.size() * kSegmentLengthInMeters * kZones);

        for( int c = 0; c < 200; ++c ) {
            mCars.push_back( std::make_tuple( positionRandom( gen ), laneRandom( gen ), speedRandom( gen ) ) );
        }
    }

    void CLevel::tick(long ms) {
        timeEllapsed += ms;

        //20 km/h
        //1h = 60 minutes * 60 seconds * 1000 ms
        float secondsSinceLastTick = ms / 1000.0f;
        float distanceSinceLastTick = carSpeed * secondsSinceLastTick;
        timeLeft -= ms;
        distanceRan += distanceSinceLastTick;
        distanceToNextElement -= distanceSinceLastTick;

        smoking = ( carSpeed > 0 && carSpeed < 20 );

        auto playerLane = x / 640.0f;



        for ( auto& car : mCars ) {
            auto oldPosition = std::get<0>(car);
            auto speed = std::get<2>(car);
            auto newPosition = oldPosition + ( speed * secondsSinceLastTick );
            std::get<0>(car) = newPosition;
            auto lane = std::get<1>(car);

            auto pz0 = distanceRan;
            auto pz1 = distanceRan + 1;
            auto cz0 = newPosition;
            auto cz1 = newPosition + 1;

            if ((cz0 <= pz0 && pz0 <= cz1) ||
                ( pz0 <= cz0 && cz0 <= pz1 )||
                        (cz0 <= pz1 && pz1 <= cz1) ||
                        ( pz0 <= cz1 && cz1 <= pz1) ) {

                if (((playerLane - 0.2f) <= (lane - 0.2f) && (lane - 0.2f) <= (playerLane + 0.2f)) ||
                    ((playerLane - 0.2f) <= (lane + 0.2f) && (lane + 0.2f) <= (playerLane + 0.2f))) {
                    carSpeed = 0.0;
                    std::cout << "COLLISION!" << std::endl;
                    std::get<0>(car) = distanceRan + std::get<2>(car) / 2 + 10 + carSpeed / 2;
                    std::get<2>(car) += carSpeed / 2;
                    hit = true;
                }
            }
        }

        if ( timeLeft <= 0 ) {
            std::cout << "TIME UP!" << std::endl;
            mIsOver = true;
        }

        if (distanceToNextElement <= 0 ) {
            distanceToNextElement = kSegmentLengthInMeters;
            elementIndex++;
        }

        if ( elementIndex >= track.size() ) {
            elementIndex = 0;
            ++zone;
            timeLeft += track.size() * 20 * 1000;
            std::cout << "time:" << (timeLeft / 1000 ) << std::endl;
        }

        if ( carSpeed > 0 ) {
            x += xSpeed * (carSpeed + 2) * 0.2f;
        }

        if ( distanceToNextElement < ( kSegmentLengthInMeters / 2) ) {

            char shape = track[elementIndex];
            int shapeDelta = 0;

            if (shape == ')') {
                shapeDelta = -1;
                x+= 0.15f * carSpeed;
            }

            if (shape == '(') {
                shapeDelta = 1;<commit_msg>Fix bug on level progression<commit_after>#include <functional>
#include <utility>
#include <tuple>
#include <vector>
#include <array>
#include <iostream>
#include <random>
#include <algorithm>
#include "Common.h"
#include <array>
#include <string>
#include <iostream>
#include <vector>
#include <memory>
#include <map>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_mixer.h>
#include <SDL/SDL_ttf.h>
#include "Vipper/Vipper.h"
#include "Modules/Gameplay/Entities/CLevel.h"

namespace RunTheWorld {

    void CLevel::reset() {
        timeEllapsed = 0;
    }

    CLevel::CLevel() {
        gameState = EGameState::kGame;
        reset();

        std::random_device rd;
        std::mt19937 gen(rd());

        std::uniform_real_distribution<> speedRandom(1.0f, 50.0f);
        std::uniform_real_distribution<> laneRandom(-1.0f, 1.0f);
        std::uniform_real_distribution<> positionRandom( 10, track.size() * kSegmentLengthInMeters * kZones);

        for( int c = 0; c < 200; ++c ) {
            mCars.push_back( std::make_tuple( positionRandom( gen ), laneRandom( gen ), speedRandom( gen ) ) );
        }
    }

    void CLevel::tick(long ms) {
        timeEllapsed += ms;

        //20 km/h
        //1h = 60 minutes * 60 seconds * 1000 ms
        float secondsSinceLastTick = ms / 1000.0f;
        float distanceSinceLastTick = carSpeed * secondsSinceLastTick;
        timeLeft -= ms;
        distanceRan += distanceSinceLastTick;
        distanceToNextElement -= distanceSinceLastTick;

        smoking = ( carSpeed > 0 && carSpeed < 20 );

        auto playerLane = x / 640.0f;



        for ( auto& car : mCars ) {
            auto oldPosition = std::get<0>(car);
            auto speed = std::get<2>(car);
            auto newPosition = oldPosition + ( speed * secondsSinceLastTick );
            std::get<0>(car) = newPosition;
            auto lane = std::get<1>(car);

            auto pz0 = distanceRan;
            auto pz1 = distanceRan + 1;
            auto cz0 = newPosition;
            auto cz1 = newPosition + 1;

            if ((cz0 <= pz0 && pz0 <= cz1) ||
                ( pz0 <= cz0 && cz0 <= pz1 )||
                        (cz0 <= pz1 && pz1 <= cz1) ||
                        ( pz0 <= cz1 && cz1 <= pz1) ) {

                if (((playerLane - 0.2f) <= (lane - 0.2f) && (lane - 0.2f) <= (playerLane + 0.2f)) ||
                    ((playerLane - 0.2f) <= (lane + 0.2f) && (lane + 0.2f) <= (playerLane + 0.2f))) {
                    carSpeed = 0.0;
                    std::cout << "COLLISION!" << std::endl;
                    std::get<0>(car) = distanceRan + std::get<2>(car) / 2 + 10 + carSpeed / 2;
                    std::get<2>(car) += carSpeed / 2;
                    hit = true;
                }
            }
        }

        if ( timeLeft <= 0 ) {
            std::cout << "TIME UP!" << std::endl;
            mIsOver = true;
        }

        if (distanceToNextElement <= 0 ) {
            distanceToNextElement = kSegmentLengthInMeters;
            elementIndex++;
        }

        if ( elementIndex >= track.size() ) {
            elementIndex = 0;
            timeLeft += track.size() * 20 * 1000;
            zone = (zone + 1) % kZones;
            std::cout << "time:" << (timeLeft / 1000 ) << std::endl;
        }

        if ( carSpeed > 0 ) {
            x += xSpeed * (carSpeed + 2) * 0.2f;
        }

        if ( distanceToNextElement < ( kSegmentLengthInMeters / 2) ) {

            char shape = track[elementIndex];
            int shapeDelta = 0;

            if (shape == ')') {
                shapeDelta = -1;
                x+= 0.15f * carSpeed;
            }

            if (shape == '(') {
                shapeDelta = 1;
{'fraction_non_alphanumeric': 0.14563894523326573, 'fraction_numerical': 0.032589587559161595, 'mean_word_length': 1.7301587301587302, 'pattern_counts': {'":': 0, '<': 121, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '238472', 'n_tokens_mistral': 2544, 'n_tokens_neox': 2310, 'n_words': 534}