Advertisement
IcarusLives

Random Walker

Mar 7th, 2017
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.54 KB | None | 0 0
  1. @echo off & setlocal enableDelayedExpansion
  2.  
  3. call :canvas 50 40
  4.  
  5. set /a "dx=25", "dy=20", "di=!random! %% 3 - 1", "dj=!random! %% 3 - 1"
  6. :loop
  7.     for /l %%a in (1,1,900) do (
  8.    
  9.         set /a "dx+=di", "dy+=dj", "di=!random! %% 3 - 1", "dj=!random! %% 3 - 1"
  10.        
  11.         call :plot !dx! !dy!
  12.         call :showCanvas
  13.     )
  14.    
  15.     call :updateCanvas
  16. if !l! neq 900 ( set /a "l+=1" & goto :loop) else exit /b
  17. rem ---------------------------------------------------------------------------------------
  18.  
  19.  
  20.  
  21.  
  22. rem All functions below this line.
  23. rem ---------------------------------------------------------------------------------------
  24. :canvas
  25.         set /a "width=%~1 - 1", "height=%~2 - 1", "_=-1", "conWidth=width + 4", "conHeight=height + 5"
  26.         if exist cursorpos.exe ( set "cls=cursorpos 0 0" ) else ( set "cls=cls" )
  27.         for /l %%a in (-2,1,%width%) do set "outerBuffer=!outerBuffer!#"
  28.         for /l %%a in (0,1,%width%)  do set "widthBuffer=!widthBuffer! "
  29.         call :updateCanvas
  30.         mode con: cols=%conWidth% lines=%conHeight%
  31.     goto :eof
  32.    
  33.     :updateCanvas
  34.         for /l %%a in (0,1,%height%) do set /a "_+=1" & set "_[!_!]=%widthBuffer%"
  35.         set "_="
  36.     goto :eof
  37.    
  38.     :showCanvas
  39.         %cls%
  40.         echo=%outerBuffer%
  41.         for /l %%a in (0,1,%height%) do echo=#!_[%%a]!#
  42.         echo=%outerBuffer%
  43.     goto :eof
  44. goto :eof
  45.  
  46. :plot x y
  47.     setlocal
  48.         set /a "_x2=%~1 + 1"
  49.         (endlocal
  50.             set "_[%~2]=!_[%~2]:~0,%~1!.!_[%~2]:~%_x2%!"
  51.         )
  52. goto :eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement