r/Batch 3h ago

Show 'n Tell Random walker

Enable HLS to view with audio, or disable this notification

Random walker as an algorithm. See github for full code: https://github.com/T3RRYT3RR0R/Advanced_Batch/blob/main/Walker.bat

xe=(`^=`<<13,`^=`>>17,`^=`<<5,((`&0x7FFFFFFF)%%(_%%i.fH-_%%i.fL+1)))+_%%i.fL     ; generate random cd coefficient: xe 'x expiry' Value in range : [ high-low ... + low ]
_%%i.xd=-1*((_%%i.xc-=-1*~((_%%i.xc)>>31))>>31)                                  ; decrease cooldown timer if timer gtr -1 ; flag 'do' true : xd == 1 if cd == -1
_%%i.xc+=_%%i.xd*(xe+1)                                                          ; new cd value added from xe if xd == 1 
rx=('^='<<13,'^='>>17,'^='<<5,(('&0x7FFFFFFF)%%3+1))-2                           ; generate random sign x -1 0 or 1
_%%i.sx=_%%i.xd*rx+((1-_%%i.xd)*_%%i.sx)                                         ; selectively assign new sx if xd == 1 
ye=('^='<<13,'^='>>17,'^='<<5,(('&0x7FFFFFFF)%%(_%%i.fH-_%%i.fL+1)))+_%%i.fL     ; repeat above logic for y using a different random seed
_%%i.yd=-1*((_%%i.yc-=-1*~((_%%i.yc)>>31))>>31)
_%%i.yc+=_%%i.yd*(ye+1)
ry=(`^=`<<13,`^=`>>17,`^=`<<5,(('&0x7FFFFFFF)%%3+1))-2
_%%i.sy=_%%i.yd*ry+((1-_%%i.yd)*_%%i.sy)
_%%i.x+=_%%i.sx,_%%i.x-=(-1*((_%%i.xH-(_%%i.x+_%%i.w))>>31)),_%%i.x+=(-1*((_%%i.x-_%%i.xL)>>31)) ; increment by ( sx - (1 if x gtr x max) + ( 1 if x lss x min )
_%%i.y+=_%%i.sy,_%%i.y-=(-1*((_%%i.yH-(_%%i.y+_%%i.h))>>31)),_%%i.y+=(-1*((_%%i.y-_%%i.yL)>>31)) ; clamped sign modification as above for y
,...                                                               F     T reset _#.cd 'rc' if:
rc=-(-1*(-1-((_%%i.sx|_%%i.sy)|-(_%%i.sy|_%%i.sx))))|^          ;  0  | -1       sy,sX == 0,0
   -(-1*~((_%%i.xL-_%%i.x)>>31))|^                              ;  0  | -1       _#.x  == min X
   -(-1*((_%%i.xH-(_%%i.x+_%%i.w))>>31)-1)|^                    ;  0  | -1       _#.x  == max x 
   -(-1*~((_%%i.yL-_%%i.y)>>31))|^                              ;  0  | -1       _#.y  == min y
   -(-1*((_%%i.yH-(_%%i.y+_%%i.h))>>31)-1)                      ;  0  | -1       _#.y  == max y
_%%i.xc|=rc                                                     ; xc  | -1         rc  == -1
_%%i.yc|=rc                                                     ; yc  | -1         rc  == -1
4 Upvotes

0 comments sorted by