Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #SingleInstance Force
- while true
- {
- loopStart:
- sleep, 5000
- loopStart2:
- square1 = 0
- square2 = 0
- square3 = 0
- square4 = 0
- square5 = 0
- square6 = 0
- square7 = 0
- square8 = 0
- square9 = 0
- ;shut down end game windows
- IfWinExist Match ahk_class Shell_Dialog
- {
- WinActivate, Match ahk_class Shell_Dialog
- MouseMove, 621, 140
- MouseClick, left
- goto loopStart
- }
- IfWinExist You lost ahk_class Shell_Dialog
- {
- WinActivate, lost ahk_class Shell_Dialog
- MouseMove, 621, 140
- MouseClick, left
- goto loopStart
- }
- IfWinExist Tie ahk_class Shell_Dialog
- {
- WinActivate, Tie ahk_class Shell_Dialog
- MouseMove, 621, 140
- MouseClick, left
- goto loopStart
- }
- WinActivate, Tic Tac Toe ahk_class ApplicationFrameWindow
- ;check for turn
- PixelGetColor, OutputVar, 583, 861
- PixelSearch, OutputVarX, OutputVarY, 583, 861, 583, 861, OutputVar
- if ErrorLevel = 1
- {
- goto loopStart2
- }
- ;search for oh's
- ImageSearch, X, Y, 250, 200, 350, 380, testCards\tictactoe\oh.png
- if ErrorLevel = 0
- {
- square1 = 1
- }
- ImageSearch, X, Y, 450, 200, 550, 380, testCards\tictactoe\oh.png
- if ErrorLevel = 0
- {
- square2 = 1
- }
- ImageSearch, X, Y, 650, 200, 750, 380, testCards\tictactoe\oh.png
- if ErrorLevel = 0
- {
- square3 = 1
- }
- ImageSearch, X, Y, 250, 400, 350, 580, testCards\tictactoe\oh.png
- if ErrorLevel = 0
- {
- square4 = 1
- }
- ImageSearch, X, Y, 450, 400, 550, 580, testCards\tictactoe\oh.png
- if ErrorLevel = 0
- {
- square5 = 1
- }
- ImageSearch, X, Y, 650, 400, 750, 580, testCards\tictactoe\oh.png
- if ErrorLevel = 0
- {
- square6 = 1
- }
- ImageSearch, X, Y, 250, 600, 350, 780, testCards\tictactoe\oh.png
- if ErrorLevel = 0
- {
- square7 = 1
- }
- ImageSearch, X, Y, 450, 600, 550, 780, testCards\tictactoe\oh.png
- if ErrorLevel = 0
- {
- square8 = 1
- }
- ImageSearch, X, Y, 650, 600, 750, 780, testCards\tictactoe\oh.png
- if ErrorLevel = 0
- {
- square9 = 1
- }
- ;Search for x's
- ImageSearch, X, Y, 180, 240, 320, 350, testCards\tictactoe\xs.png
- if ErrorLevel = 0
- {
- square1 = 2
- }
- ImageSearch, X, Y, 380, 240, 520, 350, testCards\tictactoe\xs.png
- if ErrorLevel = 0
- {
- square2 = 2
- }
- ImageSearch, X, Y, 580, 240, 720, 350, testCards\tictactoe\xs.png
- if ErrorLevel = 0
- {
- square3 = 2
- }
- ImageSearch, X, Y, 180, 440, 320, 550, testCards\tictactoe\xs.png
- if ErrorLevel = 0
- {
- square4 = 2
- }
- ImageSearch, X, Y, 380, 440, 520, 550, testCards\tictactoe\xs.png
- if ErrorLevel = 0
- {
- square5 = 2
- }
- ImageSearch, X, Y, 580, 440, 720, 550, testCards\tictactoe\xs.png
- if ErrorLevel = 0
- {
- square6 = 2
- }
- ImageSearch, X, Y, 180, 640, 320, 750, testCards\tictactoe\xs.png
- if ErrorLevel = 0
- {
- square7 = 2
- }
- ImageSearch, X, Y, 380, 640, 520, 750, testCards\tictactoe\xs.png
- if ErrorLevel = 0
- {
- square8 = 2
- }
- ImageSearch, X, Y, 580, 640, 720, 750, testCards\tictactoe\xs.png
- if ErrorLevel = 0
- {
- square9 = 2
- }
- ;MsgBox, Square1 %square1% Square2 %square2% Square3 %square3% Square4 %square4% Square5 %square5% Square6 %square6% Square7 %square7% Square8 %square8% Square9 %square9%
- ;check for winning moves
- if (square1 == 2)
- {
- if ((square2 == 2) and (square3 == 0))
- {
- MouseMove, 653, 277
- MouseClick, Left
- goto loopStart
- }
- if ((square3 == 2) and (square2 == 0))
- {
- MouseMove, 453, 277
- MouseClick, Left
- goto loopStart
- }
- if ((square4 == 2) and (square7 == 0))
- {
- MouseMove, 253, 677
- MouseClick, Left
- goto loopStart
- }
- if ((square5 == 2) and (square9 == 0))
- {
- MouseMove, 653, 677
- MouseClick, Left
- goto loopStart
- }
- if ((square7 == 2) and (square4 == 0))
- {
- MouseMove, 253, 477
- MouseClick, Left
- goto loopStart
- }
- if ((square9 == 2) and (square5 == 0))
- {
- MouseMove, 453, 477
- MouseClick, Left
- goto loopStart
- }
- }
- if (square2 == 2)
- {
- if ((square3 == 2) and (square1 == 0))
- {
- MouseMove, 253, 277
- MouseClick, Left
- goto loopStart
- }
- if ((square5 == 2) and (square8 == 0))
- {
- MouseMove, 453, 677
- MouseClick, Left
- goto loopStart
- }
- if ((square8 == 2) and (square5 == 0))
- {
- MouseMove, 453, 477
- MouseClick, Left
- goto loopStart
- }
- }
- if (square3 == 2)
- {
- if ((square5 == 2) and (square7 == 0))
- {
- MouseMove, 253, 677
- MouseClick, Left
- goto loopStart
- }
- if ((square6 == 2) and (square9 == 0))
- {
- MouseMove, 653, 677
- MouseClick, Left
- goto loopStart
- }
- if ((square9 == 2) and (square6 == 0))
- {
- MouseMove, 453, 477
- MouseClick, Left
- goto loopStart
- }
- }
- if (square4 == 2)
- {
- if ((square5 == 2) and (square6 == 0))
- {
- MouseMove, 653, 477
- MouseClick, Left
- goto loopStart
- }
- if ((square6 == 2) and (square5 == 0))
- {
- MouseMove, 453, 477
- MouseClick, Left
- goto loopStart
- }
- if ((square7 == 2) and (square1 == 0))
- {
- MouseMove, 253, 277
- MouseClick, Left
- goto loopStart
- }
- }
- if (square5 == 2)
- {
- if ((square6 == 2) and (square4 == 0))
- {
- MouseMove, 253, 477
- MouseClick, Left
- goto loopStart
- }
- if ((square7 == 2) and (square3 == 0))
- {
- MouseMove, 653, 277
- MouseClick, Left
- goto loopStart
- }
- if ((square8 == 2) and (square2 == 0))
- {
- MouseMove, 453, 277
- MouseClick, Left
- goto loopStart
- }
- if ((square9 == 2) and (square2 == 0))
- {
- MouseMove, 453, 277
- MouseClick, Left
- goto loopStart
- }
- }
- if (square6 == 2)
- {
- if ((square9 == 2) and (square3 == 0))
- {
- MouseMove, 653, 277
- MouseClick, Left
- goto loopStart
- }
- }
- if (square7 == 2)
- {
- if ((square8 == 2) and (square9 == 0))
- {
- MouseMove, 653, 677
- MouseClick, Left
- goto loopStart
- }
- if ((square9 == 2) and (square8 == 0))
- {
- MouseMove, 453, 477
- MouseClick, Left
- goto loopStart
- }
- }
- if (square8 == 2)
- {
- if ((square9 == 2) and (square7 == 0))
- {
- MouseMove, 253, 677
- MouseClick, Left
- goto loopStart
- }
- }
- ;Check to block opponents win
- if (square1 == 1)
- {
- if ((square2 == 1) and (square3 == 0))
- {
- MouseMove, 653, 277
- MouseClick, Left
- goto loopStart
- }
- if ((square3 == 1) and (square2 == 0))
- {
- MouseMove, 453, 277
- MouseClick, Left
- goto loopStart
- }
- if ((square4 == 1) and (square7 == 0))
- {
- MouseMove, 253, 677
- MouseClick, Left
- goto loopStart
- }
- if ((square5 == 1) and (square9 == 0))
- {
- MouseMove, 653, 677
- MouseClick, Left
- goto loopStart
- }
- if ((square7 == 1) and (square4 == 0))
- {
- MouseMove, 253, 477
- MouseClick, Left
- goto loopStart
- }
- if ((square9 == 1) and (square5 == 0))
- {
- MouseMove, 453, 477
- MouseClick, Left
- goto loopStart
- }
- }
- if (square2 == 1)
- {
- if ((square3 == 1) and (square1 == 0))
- {
- MouseMove, 253, 277
- MouseClick, Left
- goto loopStart
- }
- if ((square5 == 1) and (square8 == 0))
- {
- MouseMove, 453, 677
- MouseClick,
- goto loopStart
- }
- if ((square8 == 1) and (square5 == 0))
- {
- MouseMove, 453, 477
- MouseClick, Left
- goto loopStart
- }
- }
- if (square3 == 1)
- {
- if ((square5 == 1) and (square7 == 0))
- {
- MouseMove, 253, 677
- MouseClick, Left
- goto loopStart
- }
- if ((square6 == 1) and (square9 == 0))
- {
- MouseMove, 653, 677
- MouseClick, Left
- goto loopStart
- }
- if ((square9 == 1) and (square6 == 0))
- {
- MouseMove, 653, 477
- MouseClick, Left
- goto loopStart
- }
- }
- if (square4 == 1)
- {
- if ((square5 == 1) and (square6 == 0))
- {
- MouseMove, 653, 477
- MouseClick, Left
- goto loopStart
- }
- if ((square6 == 1) and (square5 == 0))
- {
- MouseMove, 453, 477
- MouseClick, Left
- goto loopStart
- }
- if ((square7 == 1) and (square1 == 0))
- {
- MouseMove, 253, 277
- MouseClick, Left
- goto loopStart
- }
- }
- if (square5 == 1)
- {
- if ((square6 == 1) and (square4 == 0))
- {
- MouseMove, 253, 477
- MouseClick, Left
- goto loopStart
- }
- if ((square7 == 1) and (square3 == 0))
- {
- MouseMove, 653, 277
- MouseClick, Left
- goto loopStart
- }
- if ((square8 == 1) and (square2 == 0))
- {
- MouseMove, 453, 277
- MouseClick, Left
- goto loopStart
- }
- if ((square9 == 1) and (square2 == 0))
- {
- MouseMove, 453, 277
- MouseClick, Left
- goto loopStart
- }
- }
- if (square6 == 1)
- {
- if ((square9 == 1) and (square3 == 0))
- {
- MouseMove, 653, 277
- MouseClick, Left
- goto loopStart
- }
- }
- if (square7 == 1)
- {
- if ((square8 == 1) and (square9 == 0))
- {
- MouseMove, 653, 677
- MouseClick, Left
- goto loopStart
- }
- if ((square9 == 1) and (square8 == 0))
- {
- MouseMove, 453, 677
- MouseClick, Left
- goto loopStart
- }
- }
- if (square8 == 1)
- {
- if ((square9 == 1) and (square7 == 0))
- {
- MouseMove, 253, 677
- MouseClick, Left
- goto loopStart
- }
- }
- ;take center
- if (square5 == 0)
- {
- MouseMove, 453, 477
- MouseClick, Left
- goto loopStart
- }
- ;take corner
- if (square1 == 0)
- {
- MouseMove, 253, 277
- MouseClick, Left
- goto loopStart
- }
- if (square3 == 0)
- {
- MouseMove, 653, 277
- MouseClick, Left
- goto loopStart
- }
- if (square7 == 0)
- {
- MouseMove, 253, 677
- MouseClick, Left
- goto loopStart
- }
- if (square9 == 0)
- {
- MouseMove, 653, 677
- MouseClick, Left
- goto loopStart
- }
- ;else take middle side squares
- if (square2 == 0)
- {
- MouseMove, 453, 277
- MouseClick, Left
- goto loopStart
- }
- if (square4 == 0)
- {
- MouseMove, 253, 477
- MouseClick, Left
- goto loopStart
- }
- if (square6 == 0)
- {
- MouseMove, 653, 477
- MouseClick, Left
- goto loopStart
- }
- if (square8 == 0)
- {
- MouseMove, 453, 677
- MouseClick, Left
- goto loopStart
- }
- }
- x::ExitApp
Advertisement
Add Comment
Please, Sign In to add comment