Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
- #Warn ; Recommended for catching common errors.
- SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
- SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
- SetKeyDelay -1,-1
- ;SetBatchLines -1
- Process, Priority,, High
- #MaxThreadsPerHotkey 1
- qw := 25 ; wait sleep time for double taps 25
- qx := 472
- qy := 105 ; Win7 -> 105, WinXP -> 110
- qz := 41
- order := {}
- ;JLO := "" ; order of the current bag's J,L,O pieces
- ;TSZ := "" ; order of the current bag's J,L,O pieces
- init:
- hold := ""
- bag := 0 ; # of bags
- Tpos := 1 ; next T goes to S or Z stack?
- Todd := 0 ; odd number of T's dropped on stack?
- Ipos := 1 ; next I goes to left or right column?
- return
- ^::
- Suspend
- ;Pause
- return
- 1::
- gosub init
- send {Enter down}
- sleepy(50)
- send {Enter up}
- sleepy(2940)
- ;gosub getbag
- loop 14
- {
- gosub movebag
- }
- gosub lastbag ; now begin to skim
- return
- movebag:
- bag += 1
- sleepy(qw)
- gosub getbag
- loop 7
- {
- cur := order[ A_Index ]
- gosub move%cur%
- ; sleepy(qw) ; ################
- }
- return
- moveT:
- if ( bag = 1 )
- {
- if ( STZ = "TSZ" OR STZ = "TZS" )
- {
- send {s}
- }
- else if ( STZ = "ZST" OR STZ = "ZTS" )
- {
- ; left, sonic, left
- send {d}
- }
- else if ( STZ = "STZ" OR STZ = "SZT" )
- {
- ; clockw, hold left, sonic, ccw
- send {s}
- }
- }
- else if ( hold = "T" OR Todd = 1 )
- {
- if ( TPos = 0 AND Todd = 0 )
- {
- send {y}
- ; drop on Z stack
- Todd := 1
- }
- else if ( TPos = 0 AND Todd = 1 )
- {
- send {w}
- ; drop flipped on Z stack
- Tpos := 1
- Todd := 0
- }
- else if ( TPos = 1 AND Todd = 0 )
- {
- send {r}
- ; drop on S stack
- Todd := 1
- }
- else if ( TPos = 1 AND Todd = 1 )
- {
- send {c}
- ; drop flipped on S stack
- Tpos := 0
- Todd := 0
- }
- }
- else
- {
- send {space}
- ;sleepy(qw) ; <-----------
- if ( hold = "S" )
- {
- send {c}
- }
- else if ( hold = "Z" )
- {
- send {y}
- }
- ; (hold T and drop held piece)
- hold := "T"
- }
- return
- moveZ:
- if ( bag = 1 AND STZ = "SZT" )
- {
- send {space}
- ; (hold Z)
- hold := "Z"
- }
- else if ( Tpos = 0 AND Todd = 1 )
- {
- send {space}
- ;sleepy(qw) ; <-----------
- send {w}
- ; (hold Z, drop T on stack)
- hold := "Z"
- Tpos := 1
- Todd := 0
- }
- else
- {
- send {y}
- }
- return
- moveS:
- if ( bag = 1 AND STZ = "ZST" )
- {
- send {space}
- ; (hold S)
- hold := "S"
- }
- else if ( Tpos = 1 AND Todd = 1 )
- {
- send {space}
- ;sleepy(qw) ; <-----------
- send {c}
- ; (hold S, drop T on stack)
- hold := "S"
- Tpos := 0
- Todd := 0
- }
- else
- {
- send {c}
- }
- return
- moveI:
- if ( Ipos = 0 )
- {
- send {b}
- }
- else if ( Ipos = 1 )
- {
- send {n}
- }
- if ( bag > 1 AND bag != 9 )
- Ipos := 1 - Ipos
- return
- moveO:
- if ( bag >= 13 )
- {
- send {g}
- }
- else if ( JLO = "JLO" OR JLO = "LJO" OR JLO = "OJL" OR JLO = "OLJ" )
- {
- send {k}
- }
- else if ( JLO = "JOL" )
- {
- ; hold right, softdrop, left
- send {k}
- }
- else if ( JLO = "LOJ" )
- {
- ; right, right, softdrop, right
- send {k}
- }
- return
- moveJ:
- if( bag = 13 )
- {
- send {p}
- }
- else if ( bag = 14 )
- {
- send {.}
- }
- else if ( JLO = "JLO" OR JLO = "LJO" )
- {
- send {p}
- }
- else if ( JLO = "JOL" OR JLO = "LOJ" OR JLO = "OJL" OR JLO = "OLJ" )
- {
- send {m}
- }
- return
- moveL:
- if( bag = 13 )
- {
- send {m}
- }
- else if ( bag = 14 )
- {
- send {i}
- }
- else if ( JLO = "JLO" OR JLO = "LJO" )
- {
- send {m}
- }
- else if ( JLO = "JOL" OR JLO = "LOJ" OR JLO = "OJL" OR JLO = "OLJ" )
- {
- send {p}
- }
- return
- getbag:
- JLO := ""
- STZ := ""
- x := qx
- y := qy
- loop 7
- {
- PixelGetColor, b, x, y
- if (A_Index = 1)
- x += 100
- else
- y += qz
- r := Mod( b, 0x100 )
- b -= r
- b /= 0x100
- g := Mod( b, 0x100 )
- b -= g
- b /= 0x100
- dist := ABS(r-225) + ABS(g-209) + ABS(b-34) ; 0=yellow
- min := "O"
- comp := ABS(r-34) + ABS(g-201) + ABS(b-225) ; I=cyan
- if ( dist > comp )
- dist := comp, min := "I"
- comp := ABS(r-225) + ABS(g-34) + ABS(b-58) ; Z=red
- if ( dist > comp )
- dist := comp, min := "Z"
- comp := ABS(r-34) + ABS(g-225) + ABS(b-34) ; S=green
- if ( dist > comp )
- dist := comp, min := "S"
- comp := ABS(r-225) + ABS(g-129) + ABS(b-34) ; L=orange
- if ( dist > comp )
- dist := comp, min := "L"
- comp := ABS(r-34) + ABS(g-58) + ABS(b-225) ; J=blue
- if ( dist > comp )
- dist := comp, min := "J"
- comp := ABS(r-161) + ABS(g-34) + ABS(b-225) ; T=violet
- if ( dist > comp )
- dist := comp, min := "T"
- order[ A_Index ] := min
- if ( min = "J" OR min = "L" OR min = "O" )
- JLO := JLO . min
- else if ( min = "S" OR min = "T" OR min = "Z" )
- STZ := STZ . min
- }
- return
- lastbag:
- sleepy(qw)
- gosub getbag
- num := 0
- oh := 0
- eye := 0
- loop 7
- {
- cur := order[ A_Index ]
- if ( cur = "I" )
- {
- if ( num >= 2 )
- {
- send {n}
- eye := 1
- if ( oh )
- break
- }
- else
- {
- send {space}
- ;sleepy(qw) ; <-----------
- if ( hold = "T" )
- {
- send {b}
- num += 1
- }
- else
- {
- send {l}
- }
- hold := "I"
- }
- }
- else if ( cur = "Z" )
- {
- send {y}
- }
- else if ( cur = "S" )
- {
- send {c}
- }
- else if ( cur = "T" OR cur = "J" OR cur = "L" )
- {
- if ( num < 2 )
- {
- send {b}
- num += 1
- }
- else
- {
- send {l}
- }
- }
- else if ( cur = "O" )
- {
- send {g}
- oh := 1
- if ( eye )
- break
- }
- ;sleepy(qw) ; #############
- if ( hold = "I" AND num >= 2 AND oh = 1 )
- {
- send {space}
- ;sleepy(qw) ; <-----------
- send {n}
- break
- }
- }
- return
- sleepy(sleeptime)
- {
- ; sleep sleeptime
- DllCall("Winmm\timeBeginPeriod", UInt, 7) ; Try 7 or 3
- DllCall("Sleep", UInt, sleepTime) ; Must use DllCall instead of the Sleep command.
- DllCall("Winmm\timeEndPeriod", UInt, 7) ; Should be called to restore system to normal.
- }
- ;3::click %qx%,%qy%,0
- ;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