Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ::: REM Saturday lotto - Rolls in groups of 8 Games of 6 balls, out of 45 possible balls, No duplicant balls (except final 3 balls (45/6 =7.5 games)).
- ::: REM Will Roll any Number of Games without retaining duplicate Games. (Limited to 800 Games)
- ::: REM Stores rolled games to a txt file, then converts the .txt to a .doc so it can be Opened in MS Word
- ::: REM v 3.0 Modifications - Reduced number of subroutines down to One, Refinement of Sorting subroutine through the use of Nested For Loops.
- ::: REM (cont) Modified call to sort routine to use nested For /L Loops to build the strings containing games to be sorted.
- @Echo Off
- ::: REM Define escape sequence character for color output - hexadecimal: \x1B
- For /F %%a in ('echo prompt $E ^| cmd')do (Set "/E=%%a")
- :Re_roll_All
- Setlocal EnableExtensions EnableDelayedExpansion & TITLE Saturday Lotto game roller
- REM Stores the Folder location of the Program into a variable - Must be done before any functions are called.
- Set "ProgDir=%~dp0"
- REM Creates a folder to store lotto numbers in
- IF NOT EXIST "%ProgDir%LottoDraws" MD "%ProgDir%LottoDraws"
- Set "SaveLoc=%ProgDir%LottoDraws"
- REM Fullscreen mode
- Mode 1000
- REM - Game_Number variable used to track total number of Games rolled.
- Set G_N=0
- :Choose
- CLS
- ECHO %/E%[1;1H%/E%[K%/E%[36m Select the number of games to roll (%/E%[34mOnly multiples of 8 permitted%/E%[36m):%/E%[34m
- REM Displays Game Number Options in Multiples of 8, Highlights Games that match Multiples of 18 (Equal to Playslip Maximum Games)
- REM cont- Multiples of 8 beyond 320 are still Valid
- Set /a L_Pos=0
- FOR /L %%a IN (8,8,320) DO (
- Echo/%/E%[2;!L_pos!H%/E%[1m%/E%[35m%%a%/E%[0m%/E%[34m
- FOR /L %%b IN (18,18,320) DO (
- IF %%b==%%a (
- Echo/%/E%[2;!L_pos!H%/E%[33m%%a%/E%[34m
- ))
- Set /a L_Pos+=4
- )
- REM Tests to ensure input is Numerical, returns for new input if test fails
- Set "stop="
- Set /P "stop="
- SetLocal EnableDelayedExpansion
- (Echo/!stop!|"%__AppDir__%findstr.exe" /RX "[1-9][0-9]* 0">NUL||(Echo/ %/E%[31mOnly numerical input is accepted. Values with leading 0's will be rejected. & Timeout 2 >nul & ( EndLocal & Goto :Choose)) 2>NUL)
- REM Tests input and Limits number of Games to 800, returns for new input if test fails
- IF !stop! GTR 800 (
- Echo/%/E%[31m%/E%[K Maximum %/E%[33mNumber of Games Exceeded. [%/E%[32m800%/E%[33m]
- Timeout 3 >Nul
- (EndLocal & Goto :Choose)
- )
- REM Tests to ensure input is a multiple of 8, returns for new input if test fails
- FOR /L %%a IN (8,8,!stop!) DO (
- IF "%%a"=="!stop!" (
- EndLocal & Set "stop=!stop!" & GOTO :start
- ))
- Echo/ %/E%[33mNumber of games is %/E%[31mnot %/E%[33ma Multiple of %/E%[32m8 & TIMEOUT 2 >nul & ( EndLocal & GOTO :Choose )
- :start
- CLS
- REM Current_Ball Variable used in array for balls 1 to 48 in each set of 8 games.
- Set "C_B=1"
- REM Function to generate the first 45 balls without Duplication
- :gen_1to45
- REM Generate a Value for the Current_Ball and stores it to the current array Index.
- Set /a ball[%C_B%]=%random% %%45 +1
- REM Nested For Loop used to determine if Current Ball is a repeat of previous balls rolled - compares from 2nd ball onwards.
- REM Ball count is only incremented if there is no duplication, - enforcing a reroll upon duplication with use of Label loop
- If %C_B% GTR 1 (
- For /L %%a In (1,1,!C_B!) DO (
- For %%b In (!C_B!) Do (
- If NOT "%%a"=="%%b" (
- If "!ball[%%a]!"=="!ball[%%b]!" (
- ECHO %/E%[2;1H%/E%[K%/E%[31m../O%/E%[32m
- GOTO :gen_1to45
- )))))
- ECHO %/E%[2;1H%/E%[K%/E%[32m O\..%/E%[32m
- Set Games.Rolled=0
- For /L %%A in (6,6,%C_B%) Do (Set /A Games.Rolled+=1)
- Set /A Games.Rolled+=G_N
- Title %Games.Rolled% Games succesfully rolled.
- ECHO %/E%[1;1H%/E%[K%/E%[33mRolling Ball : [%/E%[37m!C_B!%/E%[33m]
- If "!C_B!"=="45" (GOTO :gen_46to48) Else (Set /A "C_B+=1" & GOTO :gen_1to45)
- REM Function to Generate the Last 3 Balls, Duplication of 3 balls from games one to 7 required to round out the 8th game.
- :gen_46to48
- ECHO %/E%[1;1H%/E%[K%/E%[33mRolling Ball : [%/E%[37m46-48%/E%[33m]
- For /L %%a In (46,1,48) Do (Set /A "ball[%%a]=!random! %%45 + 1" & Echo/ %/E%[1;1H%/E%[K%/E%[33mRolling Ball : [%/E%[37m%%a%/E%[33m])
- REM Progressively compares balls 42 - 48 against each other for duplicants
- FOR /L %%a In (42,1,48) DO (
- For /L %%b In (43,1,48) Do (
- If NOT "%%a"=="%%b" (
- IF "!ball[%%a]!"=="!ball[%%b]!" (
- Echo/ %/E%[2;1H%/E%[K%/E%[31m../O%/E%[32m
- GOTO :gen_46to48
- ) Else (
- Echo/ %/E%[1;1H%/E%[K%/E%[33mRolling Ball : [%/E%[37m%%a%/E%[33m]
- Echo/ %/E%[2;1H%/E%[K%/E%[32m O\..%/E%[32m
- ))))
- Set "Games.Rolled=1"
- For /L %%A in (6,6,%C_B%) Do (Set /A Games.Rolled+=1)
- Set /A Games.Rolled+=G_N
- Title %Games.Rolled% Games succesfully rolled.
- REM Build a string containing each set of 6 balls prefixed with a call to the sort routine.
- REM (Call contains each set of 6 ball indices as parameters, and is enacted each time the string is built.)
- REM Assignment of each game to the incremented index number occurs in the sort routine.
- ECHO %/E%[1;1H%/E%[K%/E%[36mSorting...
- Set "Call_Sort=Call :Sort"
- FOR /L %%A in (1,1,48) Do (
- Set "Call_Sort=!Call_Sort! ball[%%A]"
- For /L %%B in (6,6,48) Do (
- IF "%%B"=="%%A" (
- Set /A G_N+=1
- !Call_Sort!
- Set "Call_Sort=Call :Sort"
- )))
- REM Loops back to start until all games rolled
- IF !G_N! LSS !stop! Goto :Start
- REM Uses Nested for loop to compare the value of each game against the value of each other game.
- For /L %%a in (1,1,!G_N!) Do (
- For /L %%b in (2,1,!G_N!) Do (
- If Not "%%a"=="%%b" (
- ECHO %/E%[1;1H%/E%[31m%/E%[07m%/E%[K Comparing:%/E%[32m
- ECHO %/E%[2;1H%/E%[0m%/E%[K%/E%[37m Game[%/E%[33m%%a%/E%[37m] %/E%[36m!game[%%a]!%/E%[32m
- ECHO %/E%[3;1H%/E%[K%/E%[35mVs.%/E%[32m
- ECHO %/E%[4;1H%/E%[K%/E%[37m Game[%/E%[33m%%b%/E%[37m] %/E%[34m!game[%%b]!%/E%[32m
- IF "!game[%%a]!"=="!game[%%b]!" (
- cls
- Echo/game[%%a] = !game[%%a]! matches game[%%b] = !game[%%b]!
- Set "G_N=0"
- pause
- GOTO :start
- ))))
- :finish
- REM Move into the lotto draw subfolder to Save file, perform renames, deletions Etc
- PUSHD "%SaveLoc%"
- REM Places the program into a holding loop if the timestamped file already exists. Will break out of the loop when
- REM (cont) the Minute passes.
- :CheckSuffix
- REM Establish date and time suffix for filename
- Set "suffix=%DATE%"
- Set "suffix=%suffix: =%"
- Set "suffix=%suffix%%TIME%"
- Set "suffix=%suffix:/=%"
- Set "suffix=%suffix::=%"
- Set "suffix=%suffix:.=%"
- Set "suffix=%suffix: =0%"
- Set "suffix=%suffix:~3,12%"
- IF EXIST "LottoNumbers%suffix%.doc" (
- CLS
- Echo/%/E%[1;1H%/E%[K%/E%[31m"LottoNumbers%suffix%.doc" %/E%[37m Already Exists
- Echo/%/E%[2;1H%/E%[K%/E%[33mWaiting for File Timestamp to become Avialable...
- Timeout 1 >Nul
- GOTO :CheckSuffix
- ) else (
- cls
- Echo/%/E%[1;1H%/E%[K%/E%[33m Generation Results Stored in "%SaveLoc%\LottoNumbers%suffix%.doc"
- )
- REM Expands game Array and Displays to Screen, then Saves to file.
- FOR /L %%a IN (1,1,!G_N!) DO (
- Echo/%/E%[37mGame[%/E%[33m%%a%/E%[37m] %/E%[90m:%/E%[36m !game[%%a]!
- Echo/Game[%%a] : !game[%%a]!>>"%SaveLoc%\LottoNumbers%suffix%.txt"
- FOR /L %%b in (18,18,!G_N!) DO (
- REM Insert break after every 18th game - 18 Games per Playslip
- IF %%a==%%b (
- Echo/
- Echo/>>"%SaveLoc%\LottoNumbers%suffix%.txt"
- )
- )
- FOR /L %%c in (54,54,!G_N!) DO (
- REM Insert page break after every 54th game - Align Games with page break in Word
- IF %%a==%%c (
- Echo/
- Echo/>>"%SaveLoc%\LottoNumbers%suffix%.txt"
- )))
- REM Change File to microsoft word extension type
- REN LottoNumbers%suffix%.txt LottoNumbers%suffix%.doc
- Pause
- :_Options
- cls
- Echo/%/E%[37mMenu. %/E%[33mIf not Exiting, You are returned here.%/E%[36m
- CHOICE /N /C erovd /M "(E)xit (R)oll Agian (O)pen in Word (V)iew in Folder (D)elete Previous Generations"
- IF %errorlevel%==5 (
- Set "Del_C=0"
- For %%a IN (LottoNumbers*.doc) DO (
- IF NOT "%%~nxa"=="LottoNumbers%suffix%.doc" (
- cls
- Echo/%/E%[3;1H%/E%[K%/E%[33mConfirm:%/E%[31m
- DEL /P "%%~nxa"
- Set /a "Del_C+=1"
- )
- )
- Echo/%/E%[4;1H%/E%[K%/E%[32mFiles Removed = %/E%[33m!Del_C!%/E%[35m
- Timeout 3
- GOTO :_Options
- )
- IF %errorlevel%==4 (
- Echo/%/E%[1;1H%/E%[K%/E%[32mOpening %/E%[33m%SaveLoc% %/E%[32mCurrent Game is:%/E%[33m LottoNumbers%suffix%.doc%/E%[35m
- Echo/%/E%[2;1H%/E%[K
- REM Opens the Folder containing the lotto draw in windows Explorer
- explorer.exe "%SaveLoc%"
- pause
- GOTO :_Options
- )
- REM Unwanted folders are created in the process of renaming and opening the file with word using the start command.
- REM The program needs to wait for Word to be closed before it can remove those unwanted folders.
- IF %errorlevel%==3 (
- cls & Color 04 & Echo/Close Microsoft Word to continue.
- REM Start file in Default Program
- START /wait "" "%SaveLoc%\LottoNumbers%suffix%.doc"
- cls & Color 03 & ECHO Cleanup In Progress...
- FOR /L %%a in (1,1,50) DO (
- RMDIR /Q /S "%SaveLoc%\%%a" 2>nul
- )
- GOTO :_Options
- )
- IF %errorlevel%==2 (
- REM Return to the Previous Folder
- POPD
- ENDLOCAL & GOTO :Re_roll_All
- )
- REM *** End Script Main. Commence Functions. *** ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- REM command executes if choice errorlevel EQU 1
- EXIT /B 0
- :sort
- SetLocal EnableDelayedExpansion
- REM assign the current game index to a variable for return past the Endlocal barrier
- Set "game=game[!G_N!]"
- REM tkn[i] Temporary indexed variables used to Sort values passed by parameter.
- REM tkn[i] is the value of the Ball number of the Calling Round.
- Set "tkn[1]=!%1!"
- Set "tkn[2]=!%2!"
- Set "tkn[3]=!%3!"
- Set "tkn[4]=!%4!"
- Set "tkn[5]=!%5!"
- Set "tkn[6]=!%6!"
- REM Sorts from Last ball to First, Comparing against each previous Ball and exchanging places along the way.
- REM (cont) On IF Condition being true, the Value of tkn[i] is swapped for the ball being compared through use of a temporary Variable.
- For /L %%a In (1,1,5) Do (
- Set /A S_Offset=1 + %%a
- For /L %%b IN (1,1,%%a) DO (
- For %%c in (!S_Offset!) DO (
- IF !tkn[%%c]! LSS !tkn[%%b]! (
- Set tmp=!tkn[%%c]!
- Set tkn[%%c]=!tkn[%%b]!
- Set tkn[%%b]=!tmp!
- ECHO %/E%[2;1H%/E%[K%/E%[33m^<^<^<^<^<%/E%[32m
- ) else (
- ECHO %/E%[2;1H%/E%[K%/E%[32m==I==%/E%[32m
- ))))
- REM Assign sorted balls in current set of six to current game index.
- Set "tmpG=!tkn[1]!,!tkn[2]!,!tkn[3]!,!tkn[4]!,!tkn[5]!,!tkn[6]!"
- (
- EndLocal
- Set "%game%=%tmpG%"
- Exit /B
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement