Random track selection for custom cups

Post suggestions regarding RVGL here in this subforum.
Jakal
Posts: 3

Random track selection for custom cups

Unread post by Jakal » Mon Dec 04, 2023 8:26 pm

First of all: Thank you for all your work on RVGL, it is simply fantastic. Especially the custom cups feature has breathed new life into the game for me.

One thing i would love to see would be randomized track selection for custom cups though. So for example that i could create a "Random Cup" cup txt file that contained 10 stages with 10 laps in the following format:

STAGE 0 random 10 false false
STAGE 1 random 10 false false
[and so on]

Where "random" would be a placeholder for any installed track and the cup would contain different tracks each time. Maybe even the mirrored and reversed parameters could be randomized in the same way.

I tried to use ChatGPT to create a batch file that generates new random cups on each game launch and got pretty far, but the batch file got super complicated and still contains a couple of formatting errors that i can't seem to fix.

Would adding something like that to the rvgl code be a possibility?
User avatar
607
Posts: 388

Re: Random track selection for custom cups

Unread post by 607 » Fri Dec 08, 2023 10:40 am

Very interesting that you tried using ChatGPT. :P I guess you had no prior coding experience?
I like the idea, although I'm not sure if it should go into the custom cup functionality. In any case, sharing these does not make much sense, as different people will have a different collection. At the same time, it might be the easiest way to implement it, because most of the functionality is already there.
I would like to hear what others think.
User avatar
agg1401
Posts: 119
From: Kayseri

Re: Random track selection for custom cups

Unread post by agg1401 » Sat Dec 09, 2023 4:43 am

I think it could be very interesting. It's worth a try.
Turkish Re-Volter.

:re-volt: :re-volt: :re-volt: :re-volt:
Jakal
Posts: 3

Re: Random track selection for custom cups

Unread post by Jakal » Sun Dec 10, 2023 10:21 pm

607 wrote: Fri Dec 08, 2023 10:40 am Very interesting that you tried using ChatGPT. :P I guess you had no prior coding experience?
I like the idea, although I'm not sure if it should go into the custom cup functionality. In any case, sharing these does not make much sense, as different people will have a different collection. At the same time, it might be the easiest way to implement it, because most of the functionality is already there.
I would like to hear what others think.
I have very little actual coding experience, but basic understanding of how code works, if that makes sense. Over the years i helped myself with several (mostly game-related) tedious tasks by copying together stuff using google, but ChatGPT has been a godsend for me in that regard. I actually have a working batch file now that creates 5 different random cups per difficulty level, based on whatever tracks i have in the levels subfolder and then launches the game. The code is super super dirty and not very flexible, as a lot of variables like number of laps, number of cars etc. are fixed, but hey, it works :D

An official implementation would still be much appreciated if doable. I agree that it would probably be best put in its own submenu, like maybe adding another selection after selecting "Championship" that has 3 options for the official cups, the custom cups and creating a new randomized cup... But that's just an idea, not sure if that's the best way to go.
Jakal
Posts: 3

Re: Random track selection for custom cups

Unread post by Jakal » Mon Dec 11, 2023 1:23 pm

Right, i might as well share this random cup generator, now that it works pretty well, maybe it can be of use for some people. Disclaimer: I am not responsible if your Computer spontanously explodes or any other damages happen when you run the script, yada, yada ;)

Instructions: Just copy the code below to a new .bat file in the Re-Volt root directory. On launch you can define the number of stages you like per cup and the number of laps per stage, as well as if you like reverse and mirrored mode randomization. Other variables like the total number of cars, the points system and the number of total cups generated are fixed, as i have no need for that to be flexible.

The script will then generate a total number of 30 random cups, 5 per difficulty level, and save them in the cups folder. Whenever you run the script again, previously generated random cups will be overwritten.

Code: Select all

@echo off
setlocal enabledelayedexpansion

:: Prompt user for number of stages, laps, and modes
set /p numStages=Enter the number of stages per cup (default is 10): 
set /p numLaps=Enter the number of laps per stage (default is 5): 
echo.
echo Choose mirrored and reversed modes for each stage:
echo 1 - Always False (Default)
echo 2 - Always True
echo 3 - Randomize
set /p modeChoice=Enter your choice (1, 2, or 3): 

:: Use default values if input is not provided
if "!numStages!"=="" set /a numStages=10
if "!numLaps!"=="" set /a numLaps=5
if "!modeChoice!"=="" set modeChoice=1

:: Define class names
set "classes[0]=rookie"
set "classes[1]=amateur"
set "classes[2]=advanced"
set "classes[3]=semi-pro"
set "classes[4]=pro"
set "classes[5]=superpro"

:: Create an array of levels
set /a levelCount=0
for /f "delims=" %%a in ('dir /b "levels"') do (
    set /a levelCount+=1
    set "levels[!levelCount!]=%%a"
)

:: Generate cups for each class
for /L %%c in (0,1,5) do (
    for /L %%i in (1,1,5) do (
        call :createCup %%c %%i
    )
)

goto :eof

:createCup
set classIndex=%1
set cupNumber=%2
set cupName=!classes[%classIndex%]!randomcup%cupNumber%
set cupFile=cups\%cupName%.txt

:: Create the cup file
(
    echo Name        "!classes[%classIndex%]! Random Cup %cupNumber%"
    echo Difficulty  4
    echo Obtain      0
    echo.
    echo NumCars     16
    echo NumTries    5
    echo QualifyPos  16
    echo UnlockPos   16
    echo.

    :: Create Classes line
    set "classesLine="
    for /L %%j in (0,1,5) do (
        if %%j==%classIndex% (
            set "classesLine=!classesLine!15,"
        ) else (
            set "classesLine=!classesLine!0,"
        )
    )
    set "classesLine=!classesLine:~0,-1!"  :: Remove the trailing comma
    echo Classes     !classesLine!
    echo Points      10,8,6,5,4,3,2,1,0,0,0,0,0,0,0,0
    echo.

:: Decrease the number of stages by 1 for correct looping
set /a adjustedNumStages=%numStages%-1

:: Randomly select and add stages
for /L %%j in (0,1,%adjustedNumStages%) do (
    set /a rnd=!random! %% levelCount + 1
    call :setMode %modeChoice%
    for /f "tokens=2 delims==" %%s in ('set levels[!rnd!]') do (
        echo STAGE %%j     %%s %numLaps% !mirrored! !reversed!
    )
)
) > "%cupFile%"

goto :eof

:setMode
set mode=%1
if "%mode%"=="1" (
    set mirrored=false
    set reversed=false
) else if "%mode%"=="2" (
    set mirrored=true
    set reversed=true
) else if "%mode%"=="3" (
    set /a randMirrored=!random! %% 2
    set /a randReversed=!random! %% 2
    if "!randMirrored!"=="0" (set mirrored=false) else (set mirrored=true)
    if "!randReversed!"=="0" (set reversed=false) else (set reversed=true)
)
goto :eof
7ynk3r
Posts: 1

Re: Random track selection for custom cups

Unread post by 7ynk3r » Sun Jan 28, 2024 6:51 am

Wrote a python script that is really easy to update. Just run the script under your "cups" folder.
Enjoy!

Code: Select all

from random import choice, sample

difficulty = 4 # 1:Easy, 2:Normal, 3:Hard, 4:Extreme
stages = 5 # [0 - 15]
cars = 8

# levelConfig = { level name : { difficulty : number of lamps } }
levelConfig = {
    'garden1':      {1: 4, 2: 4, 3: 4, 4: 4},
    'market1':      {1: 3, 2: 3, 3: 3, 4: 3},
    'market2':      {1: 4, 2: 4, 3: 4, 4: 4},
    'muse1':        {1: 3, 2: 3, 3: 3, 4: 3},
    'muse2':        {1: 3, 2: 3, 3: 3, 4: 3},
    'nhood1':       {1: 3, 2: 3, 3: 3, 4: 3},
    'nhood2':       {1: 3, 2: 3, 3: 3, 4: 3},
    'roof':         {1: 3, 2: 3, 3: 3, 4: 3},
    'ship1':        {1: 2, 2: 2, 3: 2, 4: 2},
    'ship2':        {1: 2, 2: 2, 3: 2, 4: 2},
    'toy2':         {1: 3, 2: 3, 3: 3, 4: 3},
    'toylite':      {1: 4, 2: 4, 3: 4, 4: 4},
    'wild_west1':   {1: 3, 2: 3, 3: 3, 4: 3},
    'wild_west2':   {1: 3, 2: 3, 3: 3, 4: 3},
}
levels = sample(list(levelConfig.keys()), stages)

# classesConfig = { difficulty : classes }
classesConfig = {
    1: '7,0,0,0,0,0', 
    2: '0,4,3,0,0,0', 
    3: '0,0,4,3,0,0', 
    4: '0,0,0,4,3,0', 
    5: '0,0,0,0,4,3', 
}
classes = classesConfig[difficulty]

b = ['true', 'false']

stages = '\n'.join(list(map(
    lambda pair: f"STAGE {pair[0]}     {pair[1]} {levelConfig[pair[1]].get(difficulty,3)} {choice(b)} {choice(b)}", enumerate(levels))))

file_content = f"""\
;===============================================================================
;                                RVGL Random File
;===============================================================================

Name        "Random"
Difficulty  {difficulty}
Obtain      0

NumCars     {cars}   ; Number of cars [4 - 16]
NumTries    3   ; Number of retry attempts

Classes     {classes}       ; Number of CPU cars picked from each rating
Points      10,6,4,3,2,1,0,0  ; Points obtained for each position


; Stages [0 - 15]: level laps mirrored reversed

{stages}

random
"""

with open("random.txt", "w") as file:
    file.write(file_content)

with open("dc/random.txt", "w") as file:
    file.write(file_content)
Last edited by 7ynk3r on Sun Jan 28, 2024 7:14 am, edited 1 time in total.
Post Reply