Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Echo off
- Mode 200,30
- Rem Scripting Goal: Natural Dice roll animation
- REM THIS IS NOT INTENDED AS A GAME. It is merely a proof of concept for a naturalised dice roll animation.
- REM best viewed using Lucida Console font size 14 [May differ depending on screen resolution]
- REM *** For a Yahtzee game developed from this proof of concept, See: https://pastebin.com/3JhHgvac
- Rem Specific animation goals:
- Rem - Randomized Roll length.
- Rem - Each flip of the die must be 'natural' - Flips of roll must be restricted to side adjacent the current face
- Rem - Enact roll momentum - Random Flip Count; Each flip of Die should occur with greater time interval
- Rem - Distance travelled between flips must reduce.
- Rem - Enact random[ish] 'bounce' between flips
- REM %= This is a comment =% It cannot contain : ~ ^& or %. ; will cause the comment to be displayed incorrectly on some websites.
- REM The above commenting style is parsed faster than REM
- For /f %%e in ('Echo(prompt $E^|Cmd')Do Set "\E=%%e"
- CHCP 65001 > nul
- REM delay Timing - May only work correctly on NON english based systems [untested].
- For /F "tokens=1,2 delims==" %%G in ('wmic cpu get maxclockspeed /format:value^|%SystemRoot%\System32\Findstr.exe /Li "MaxClockSpeed"')Do Set /A "%%G=%%H" 2> nul
- If not Defined MaxClockSpeed Set "MaxClockSpeed=2000"
- Set /A "DelayBase=MaxClockSpeed * (Number_Of_Processors*Number_Of_Processors)","EORdelay=(DelayBase/2)*5"
- Rem Die FG / BG properties
- REM White BG = \E[38;2;256m black BG = \E[38;2;3m
- Set "DB=%\E%[0m%\E%[48;5;1m%\E%[38;2;3m%\E%[7m"
- REM Die animation macros.
- REM Restore cursor;Cusor Down;Cursor left;Save Cursor
- Set "\c=%\E%8%\E%[B%\E%7!DB!"
- REM Face Strings, Split via substring every 3rd character to create the 3 lines comprising the die face interior for a given side.
- Set "F1= ☻ "
- Set "F2=☻ ☻"
- Set "F3=☻ ☻ ☻"
- Set "F4=☻ ☻ ☻ ☻"
- Set "F5=☻ ☻ ☻ ☻ ☻"
- Set "F6=☻ ☻☻ ☻☻ ☻"
- REM when expanded with delayedexpansion, displays roll track and die using the value of the current face to reference the appropriate substring above,
- REM with the dice positioned at the current Y;X coordinates.
- Set "ShowCurrentFace=For %%v in ("!F#!")Do Echo(%\E%[?1049h%\E%[?25l%\E%[1;1H%\E%[48;2;;;120m%\E%[K%\E%[1E%\E%[48;2;40;80;0m%\E%[0J%\E%[!y!;!x!H%\E%7!DB!╔═════╗%\c%║ !F%%~v:~0,3! ║%\c%║ !F%%~v:~3,3! ║%\c%║ !F%%~v:~6,3! ║%\c%╚═════╝%\c%%\E%[13;1H%\E%[48;2;10;10;10m%\E%[K%\E%[48;2;;;120m%\E%[K%\E%[1E%\E%[0m%\E%[0J"
- REM macros used to enforce natural flips of the dice during rolling sequence by excluding opposing side from RNG.
- Set Side[1]="1/(6-F#)"
- Set Side[2]="1/(5-F#)"
- Set Side[3]="1/(4-F#)"
- Set Side[4]="1/(3-F#)"
- Set Side[5]="1/(2-F#)"
- Set Side[6]="1/(1-F#)"
- Set "ConstrainFlip=Set /A "F#=!Random! %% 6 + 1","1/(Old-F#)",!Side[%%~v]! ||"
- Setlocal EnableDelayedExpansion
- Echo(Roll the die How many times [1 - 9]?
- For /F "delims=" %%i in ('%SystemRoot%\System32\Choice.exe /C:123456789 /N')Do Call:#Rolls %%i
- Set Roll[
- Endlocal & Goto:Eof
- :#Rolls
- (For /F "tokens=1,2 Delims==" %%G in ('Set "Roll["')Do Set "%%G=") 2> nul
- Cls
- If not "%~1"=="" (%= Enact for /l loop only if arg 1 a positive integer =%
- Set /A "1/(%~1>>31)" 2> nul || Set /a "1/%~1" 2> nul && For /L %%R in (1 1 %~1)Do (
- %= Below Mod value determines variance in Maximum X Endpoint per roll - impact extends to apparent momentum =%
- %= A higher + value to inital Mod definition results in a longer, faster average roll. =%
- %= Screen width limit restricts maximum initial vombined Mod value to total of 10 =%
- %= Die 6 characters wide * max20 flips EQU 120 characters =%
- Set /A "Y=2,X=1","Old=!Random! %%6 +1","Mod=!Random! %%2 + 8","Flips=!Random! %%Mod + Mod"
- For /l %%i in (!Flips! -1 1)Do (%= Naturally flip die a random number of times - increasing delay. =%
- Set /A "Delay=(DelayBase / (%%i+1/2))*4"
- 2> nul (
- For %%v in ("!Old!")Do (
- %= enforce natural flips of the dice during the roll - Each side should not flip to itself or its opposing side. =%
- Set /A "F#=!Random! %% 6 + 1","1/(Old-F#)",!Side[%%~v]! || (
- %ConstrainFlip% (
- %ConstrainFlip% (
- %ConstrainFlip% (
- %ConstrainFlip% (
- %ConstrainFlip% (
- %ConstrainFlip% (
- %ConstrainFlip% (
- %ConstrainFlip% (
- %ConstrainFlip% (
- %ConstrainFlip% (
- %ConstrainFlip% (
- %= Probability of failure to constrain Flip to adjacent side is approx 0 - NOT non-zero. =%
- %= No failures in 600000 test flips. In case of Failure - lesser evil - 'slide' on current face. =%
- Set "F#=!Old!"
- ))))))))))))))
- Set /A "Old=!F#!"
- %ShowCurrentFace%
- For /l %%i in (1 1 !Delay!)Do Rem delay
- Set /A "X+=%%i+(!Random! %%7 - 2)","LY=Y"
- %= Restrict Y value to random range range 2-8. Modulo of X value by Flip number used to implement approximation of bouncing =%
- %= Generate + test Y ?Negative ?zero ?Eight ?one !&! If tests Failed Assign Y EQU minimum{{LastY+1},8} =%
- Set /A "Y=(X %% %%i-2)","1/(-1-(Y>>31))","1/Y","1/(8/Y)","1/(Y-1)" 2> nul || Set /A "Y=LY+1","1/(8/Y)" 2> nul || Set /A "Y=LY"
- )
- Set "Roll[%%R]=!F#!"
- For /l %%i in (1 1 !EORdelay!)Do Rem end of roll delay
- <nul Set /P "=%\E%[?1049l%\E%[1;1H%\E%7"
- )
- )
- Goto:Eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement