Advertisement
T3RRYT3RR0R

Roller.bat

Jan 7th, 2022 (edited)
1,762
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 5.48 KB | None | 0 0
  1. @Echo off
  2. Mode 200,30
  3. Rem Scripting Goal: Natural Dice roll animation
  4.  
  5. REM THIS IS NOT INTENDED AS A GAME. It is merely a proof of concept for a naturalised dice roll animation.
  6. REM best viewed using Lucida Console font size 14 [May differ depending on screen resolution]
  7.  
  8. REM *** For a Yahtzee game developed from this proof of concept, See: https://pastebin.com/3JhHgvac
  9.  
  10. Rem Specific animation goals:
  11. Rem  -  Randomized Roll length.
  12. Rem  -  Each flip of the die must be 'natural' - Flips of roll must be restricted to side adjacent the current face
  13. Rem  -  Enact roll momentum                    - Random Flip Count; Each flip of Die should occur with greater time interval
  14. Rem                                            - Distance travelled between flips must reduce.
  15. Rem  - Enact random[ish] 'bounce' between flips
  16.  
  17. REM %= This is a comment =% It cannot contain : ~ ^& or %. ; will cause the comment to be displayed incorrectly on some websites.
  18. REM The above commenting style is parsed faster than REM
  19.  
  20.  For /f %%e in ('Echo(prompt $E^|Cmd')Do Set "\E=%%e"
  21.  CHCP 65001 > nul
  22.  
  23. REM delay Timing - May only work correctly on NON english based systems [untested].
  24.  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
  25.  If not Defined MaxClockSpeed Set "MaxClockSpeed=2000"
  26.  Set /A "DelayBase=MaxClockSpeed * (Number_Of_Processors*Number_Of_Processors)","EORdelay=(DelayBase/2)*5"
  27.  
  28. Rem Die FG / BG properties
  29. REM White BG = \E[38;2;256m black BG = \E[38;2;3m
  30.  Set "DB=%\E%[0m%\E%[48;5;1m%\E%[38;2;3m%\E%[7m"
  31.  
  32. REM Die animation macros.
  33.  
  34. REM Restore cursor;Cusor Down;Cursor left;Save Cursor
  35.  Set "\c=%\E%8%\E%[B%\E%7!DB!"
  36. REM Face Strings, Split via substring every 3rd character to create the 3 lines comprising the die face interior for a given side.
  37.  Set "F1=    ☻    "
  38.  Set "F2=☻       ☻"
  39.  Set "F3=☻   ☻   ☻"
  40.  Set "F4=☻ ☻   ☻ ☻"
  41.  Set "F5=☻ ☻ ☻ ☻ ☻"
  42.  Set "F6=☻ ☻☻ ☻☻ ☻"
  43. REM when expanded with delayedexpansion, displays roll track and die using the value of the current face to reference the appropriate substring above,
  44. REM with the dice positioned at the current Y;X coordinates.
  45.  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"
  46.  
  47. REM macros used to enforce natural flips of the dice during rolling sequence by excluding opposing side from RNG.
  48.  Set Side[1]="1/(6-F#)"
  49.  Set Side[2]="1/(5-F#)"
  50.  Set Side[3]="1/(4-F#)"
  51.  Set Side[4]="1/(3-F#)"
  52.  Set Side[5]="1/(2-F#)"
  53.  Set Side[6]="1/(1-F#)"
  54.  Set "ConstrainFlip=Set /A "F#=!Random! %% 6 + 1","1/(Old-F#)",!Side[%%~v]! ||"
  55.  
  56. Setlocal EnableDelayedExpansion
  57.  
  58.  Echo(Roll the die How many times [1 - 9]?
  59.  For /F "delims=" %%i in ('%SystemRoot%\System32\Choice.exe /C:123456789 /N')Do Call:#Rolls %%i
  60.  Set Roll[
  61. Endlocal & Goto:Eof
  62.  
  63. :#Rolls
  64.  
  65. (For /F "tokens=1,2 Delims==" %%G in ('Set "Roll["')Do Set "%%G=") 2> nul
  66.  Cls
  67.  If not "%~1"=="" (%= Enact for /l loop only if arg 1 a positive integer =%
  68.   Set /A "1/(%~1>>31)" 2> nul || Set /a "1/%~1" 2> nul && For /L %%R in (1 1 %~1)Do (
  69.  
  70.    %= Below Mod value determines variance in Maximum X Endpoint per roll - impact extends to apparent momentum =%
  71.    %= A higher + value to inital Mod definition results in a longer, faster average roll. =%
  72.    %= Screen width limit restricts maximum initial vombined Mod value to total of 10 =%
  73.    %= Die 6 characters wide * max20 flips EQU 120 characters =%
  74.    Set /A "Y=2,X=1","Old=!Random! %%6 +1","Mod=!Random! %%2 + 8","Flips=!Random! %%Mod + Mod"
  75.  
  76.    For /l %%i in (!Flips! -1 1)Do (%= Naturally flip die a random number of times - increasing delay. =%
  77.     Set /A "Delay=(DelayBase / (%%i+1/2))*4"
  78.     2> nul (
  79.      For %%v in ("!Old!")Do (
  80.       %= enforce natural flips of the dice during the roll - Each side should not flip to itself or its opposing side. =%
  81.       Set /A "F#=!Random! %% 6 + 1","1/(Old-F#)",!Side[%%~v]! || (
  82.        %ConstrainFlip% (
  83.         %ConstrainFlip% (
  84.          %ConstrainFlip% (
  85.           %ConstrainFlip% (
  86.            %ConstrainFlip% (
  87.             %ConstrainFlip% (
  88.              %ConstrainFlip% (
  89.               %ConstrainFlip% (
  90.                %ConstrainFlip% (
  91.                 %ConstrainFlip% (
  92.                  %ConstrainFlip% (
  93.                   %= Probability of failure to constrain Flip to adjacent side is approx 0 - NOT non-zero. =%
  94.                   %= No failures in 600000 test flips. In case of Failure - lesser evil - 'slide' on current face. =%
  95.                   Set "F#=!Old!"
  96.     ))))))))))))))
  97.     Set /A "Old=!F#!"
  98.     %ShowCurrentFace%
  99.     For /l %%i in (1 1 !Delay!)Do Rem delay
  100.     Set /A "X+=%%i+(!Random! %%7 - 2)","LY=Y"
  101.     %= Restrict Y value to random range range 2-8. Modulo of X value by Flip number used to implement approximation of bouncing =%
  102.     %= Generate + test Y   ?Negative        ?zero ?Eight    ?one      !&! If tests Failed Assign Y EQU minimum{{LastY+1},8} =%
  103.     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"
  104.    )
  105.    Set "Roll[%%R]=!F#!"
  106.    For /l %%i in (1 1 !EORdelay!)Do Rem end of roll delay
  107.    <nul Set /P "=%\E%[?1049l%\E%[1;1H%\E%7"
  108.   )
  109.  )
  110. Goto:Eof
  111.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement