Advertisement
Guest User

KeyBlox Sprint Bot

a guest
Mar 11th, 2013
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
  2. #Warn  ; Recommended for catching common errors.
  3. SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
  4. SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
  5. SetKeyDelay -1,-1
  6. ;SetBatchLines -1
  7. Process, Priority,, High
  8. #MaxThreadsPerHotkey 1
  9. qw := 25 ; wait sleep time for double taps 25
  10. qx := 472
  11. qy := 105 ; Win7 -> 105, WinXP -> 110
  12. qz := 41
  13. order := {}
  14. ;JLO := "" ; order of the current bag's J,L,O pieces
  15. ;TSZ := "" ; order of the current bag's J,L,O pieces
  16. init:
  17. hold := ""
  18. bag := 0 ; # of bags
  19. Tpos := 1 ; next T goes to S or Z stack?
  20. Todd := 0 ; odd number of T's dropped on stack?
  21. Ipos := 1 ; next I goes to left or right column?
  22. return
  23.  
  24.  
  25. ^::
  26. Suspend
  27. ;Pause
  28. return
  29.  
  30.  
  31. 1::
  32. gosub init
  33. send {Enter down}
  34. sleepy(50)
  35. send {Enter up}
  36. sleepy(2940)
  37. ;gosub getbag
  38. loop 14
  39. {
  40.     gosub movebag
  41. }
  42. gosub lastbag ; now begin to skim
  43. return
  44.  
  45.  
  46. movebag:
  47. bag += 1
  48. sleepy(qw)
  49. gosub getbag
  50. loop 7
  51. {
  52.     cur := order[ A_Index ]
  53.     gosub move%cur%
  54.     ; sleepy(qw) ; ################
  55. }
  56.  
  57. return
  58.  
  59.  
  60. moveT:
  61. if ( bag = 1 )
  62. {
  63.     if ( STZ = "TSZ" OR STZ = "TZS" )
  64.     {
  65.         send {s}
  66.     }
  67.     else if ( STZ = "ZST" OR STZ = "ZTS" )
  68.     {
  69.         ; left, sonic, left
  70.         send {d}
  71.     }
  72.     else if ( STZ = "STZ" OR STZ = "SZT" )
  73.     {
  74.         ; clockw, hold left, sonic, ccw
  75.         send {s}
  76.     }
  77. }
  78. else if ( hold = "T" OR Todd = 1 )
  79. {
  80.     if ( TPos = 0 AND Todd = 0 )
  81.     {
  82.         send {y}
  83.         ; drop on Z stack
  84.         Todd := 1
  85.     }
  86.     else if ( TPos = 0 AND Todd = 1 )
  87.     {
  88.         send {w}
  89.         ; drop flipped on Z stack
  90.         Tpos := 1
  91.         Todd := 0      
  92.     }
  93.     else if ( TPos = 1 AND Todd = 0 )
  94.     {
  95.         send {r}
  96.         ; drop on S stack
  97.         Todd := 1
  98.     }  
  99.     else if ( TPos = 1 AND Todd = 1 )
  100.     {
  101.         send {c}
  102.         ; drop flipped on S stack
  103.         Tpos := 0
  104.         Todd := 0      
  105.     }  
  106. }
  107. else
  108. {
  109.     send {space}
  110.     ;sleepy(qw) ; <-----------     
  111.     if ( hold = "S" )
  112.     {
  113.         send {c}       
  114.     }
  115.     else if ( hold = "Z" )
  116.     {
  117.         send {y}   
  118.     }
  119.     ; (hold T and drop held piece)
  120.     hold := "T"
  121. }
  122. return
  123.  
  124.  
  125. moveZ:
  126. if ( bag = 1 AND STZ = "SZT" )
  127. {
  128.     send {space}
  129.     ; (hold Z)
  130.     hold := "Z"
  131. }
  132. else if ( Tpos = 0 AND Todd = 1 )
  133. {
  134.     send {space}
  135.     ;sleepy(qw) ; <----------- 
  136.     send {w}
  137.     ; (hold Z, drop T on stack)
  138.     hold := "Z"
  139.     Tpos := 1
  140.     Todd := 0  
  141. }
  142. else
  143. {
  144.     send {y}
  145. }
  146. return
  147.  
  148.    
  149. moveS:
  150. if ( bag = 1 AND STZ = "ZST" )
  151. {
  152.     send {space}   
  153.     ; (hold S)
  154.     hold := "S"
  155. }
  156. else if ( Tpos = 1 AND Todd = 1 )
  157. {
  158.     send {space}
  159.     ;sleepy(qw) ; <-----------
  160.     send {c}
  161.     ; (hold S, drop T on stack)
  162.     hold := "S"
  163.     Tpos := 0
  164.     Todd := 0  
  165. }
  166. else
  167. {
  168.     send {c}
  169. }
  170. return
  171.  
  172.  
  173. moveI:
  174. if ( Ipos = 0 )
  175. {
  176.     send {b}
  177. }
  178. else if ( Ipos = 1 )
  179. {
  180.     send {n}
  181. }
  182. if ( bag > 1 AND bag != 9 )
  183.     Ipos := 1 - Ipos
  184. return
  185.  
  186.  
  187. moveO:
  188. if ( bag >= 13 )
  189. {
  190.     send {g}
  191. }
  192. else if ( JLO = "JLO" OR JLO = "LJO" OR JLO = "OJL" OR JLO = "OLJ" )
  193. {
  194.     send {k}       
  195. }
  196. else if ( JLO = "JOL" )
  197. {
  198.     ; hold right, softdrop, left
  199.     send {k}           
  200. }
  201. else if ( JLO = "LOJ" )
  202. {
  203.     ; right, right, softdrop, right
  204.     send {k}
  205. }
  206. return
  207.  
  208.  
  209. moveJ:
  210. if( bag = 13 )
  211. {
  212.     send {p}   
  213. }
  214. else if ( bag = 14 )
  215. {
  216.     send {.}
  217. }
  218. else if ( JLO = "JLO" OR JLO = "LJO" )
  219. {
  220.     send {p}
  221. }
  222. else if ( JLO = "JOL" OR JLO = "LOJ" OR JLO = "OJL" OR JLO = "OLJ" )
  223. {
  224.     send {m}
  225. }
  226. return
  227.  
  228.  
  229. moveL:
  230. if( bag = 13 )
  231. {
  232.     send {m}
  233. }
  234. else if ( bag = 14 )
  235. {
  236.     send {i}   
  237. }
  238. else if ( JLO = "JLO" OR JLO = "LJO" )
  239. {
  240.     send {m}
  241. }
  242. else if ( JLO = "JOL" OR JLO = "LOJ" OR JLO = "OJL" OR JLO = "OLJ" )
  243. {
  244.     send {p}   
  245. }
  246. return
  247.  
  248.  
  249. getbag:
  250. JLO := ""
  251. STZ := ""
  252. x := qx
  253. y := qy
  254. loop 7
  255. {
  256.     PixelGetColor, b, x, y
  257.     if (A_Index = 1)
  258.         x += 100
  259.     else
  260.         y += qz
  261.     r := Mod( b, 0x100 )
  262.     b -= r
  263.     b /= 0x100
  264.     g := Mod( b, 0x100 )
  265.     b -= g
  266.     b /= 0x100
  267.  
  268.     dist := ABS(r-225) + ABS(g-209) + ABS(b-34) ; 0=yellow
  269.     min := "O"
  270.     comp := ABS(r-34) + ABS(g-201) + ABS(b-225) ; I=cyan
  271.     if ( dist > comp )
  272.         dist := comp, min := "I"   
  273.     comp := ABS(r-225) + ABS(g-34) + ABS(b-58)  ; Z=red
  274.     if ( dist > comp )
  275.         dist := comp, min := "Z"
  276.     comp := ABS(r-34) + ABS(g-225) + ABS(b-34)  ; S=green
  277.     if ( dist > comp )
  278.         dist := comp, min := "S"   
  279.     comp := ABS(r-225) + ABS(g-129) + ABS(b-34) ; L=orange
  280.     if ( dist > comp )
  281.         dist := comp, min := "L"
  282.     comp := ABS(r-34) + ABS(g-58) + ABS(b-225)  ; J=blue
  283.     if ( dist > comp )
  284.         dist := comp, min := "J"   
  285.     comp := ABS(r-161) + ABS(g-34) + ABS(b-225) ; T=violet
  286.     if ( dist > comp )
  287.         dist := comp, min := "T"
  288.    
  289.     order[ A_Index ] := min
  290.    
  291.     if ( min = "J" OR min = "L" OR min = "O" )
  292.         JLO := JLO . min
  293.     else if ( min = "S" OR min = "T" OR min = "Z" )
  294.         STZ := STZ . min   
  295. }
  296. return
  297.  
  298. lastbag:
  299. sleepy(qw)
  300. gosub getbag
  301. num := 0
  302. oh := 0
  303. eye := 0
  304. loop 7
  305. {
  306.     cur := order[ A_Index ]
  307.     if ( cur = "I" )
  308.     {
  309.         if ( num >= 2 )
  310.         {
  311.             send {n}   
  312.             eye := 1
  313.             if ( oh )
  314.                 break
  315.         }  
  316.         else
  317.         {
  318.             send {space}
  319.             ;sleepy(qw) ; <-----------         
  320.             if ( hold = "T" )
  321.             {
  322.                 send {b}
  323.                 num += 1               
  324.             }
  325.             else
  326.             {
  327.                 send {l}               
  328.             }
  329.             hold := "I"
  330.         }
  331.     }
  332.     else if ( cur = "Z" )
  333.     {
  334.         send {y}       
  335.     }
  336.     else if ( cur = "S" )
  337.     {
  338.         send {c}           
  339.     }
  340.     else if ( cur = "T" OR cur = "J" OR cur = "L" )
  341.     {
  342.         if ( num < 2 )
  343.         {
  344.             send {b}
  345.             num += 1
  346.         }
  347.         else
  348.         {
  349.             send {l}           
  350.         }
  351.     }
  352.     else if ( cur = "O" )
  353.     {
  354.         send {g}           
  355.         oh := 1
  356.         if ( eye )
  357.             break
  358.     }
  359.     ;sleepy(qw) ; #############
  360.     if ( hold = "I" AND num >= 2 AND oh = 1 )
  361.     {          
  362.         send {space}
  363.         ;sleepy(qw) ; <-----------         
  364.         send {n}
  365.         break
  366.     }  
  367. }
  368. return
  369.  
  370.  
  371. sleepy(sleeptime)
  372. {
  373.     ; sleep sleeptime
  374.     DllCall("Winmm\timeBeginPeriod", UInt, 7) ; Try 7 or 3
  375.     DllCall("Sleep", UInt, sleepTime)  ; Must use DllCall instead of the Sleep command.
  376.     DllCall("Winmm\timeEndPeriod", UInt, 7)  ; Should be called to restore system to normal.
  377. }
  378.  
  379.  
  380.  
  381. ;3::click %qx%,%qy%,0  
  382.  
  383. ;4:: Msgbox % order[1] . order[2] . order[3] . order[4] . order[5] . order[6] . order[7]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement