Jump to content

Recommended Posts

Posted

This part of an AutoHotKey script.

Can it be converted to AutoIt?

Thank in advance for any help.

CODE
Loop

{

; Loop Y then X: move across every square, down only once per line.

sg_line := ("")

Loop, %SG_SQUARES_Y%

{

sg_y := A_Index

sg_py := yCoordToPixel(A_Index)

;MsgBox,%yCoordToPixel%

sg_line = %sg_line% `n# %A_Index% :

;MsgBox,%sg_line% `n# %A_Index%

Loop, %SG_SQUARES_X%

{

sg_x := A_Index

sg_px := xCoordToPixel(A_Index)

PixelGetColor, sg_color, %sg_px%, %sg_py%, RGB

sg_c := sg_color

SG_ARR_%sg_x%_%sg_y% := sg_c

col := SG_ARR_%sg_x%_%sg_y%

;MsgBox, SG_ARR_%sg_x%_%sg_y% = %col%

sg_line = %sg_line% %sg_c% ( %sg_x% , %sg_y% = %sg_px% , %sg_py% )

}

}

getmove()

}

isSameAt(col, x, y)

{

; Generic global to include array.

global

if (x < 1 || x > SG_SQUARES_X || y < 1 || y > SG_SQUARES_Y )

{

;MsgBox, returning false as OOB ( %x% < 1 || %x% > %SG_SQUARES_X% || %y% < 1 || %y% > %SG_SQUARES_Y% )

return false

}

ax := SG_ARR_%x%_%y%

if ( SG_ARR_%x%_%y% == col )

{

;MsgBox, returning true as %ax% == %col% and none of ( %x% < 1 || %x% > %SG_SQUARES_X% || %y% < 1 || %y% > %SG_SQUARES_Y% )

return true

}

;MsgBox, returning false as %ax% != %col% though none of ( %x% < 1 || %x% > %SG_SQUARES_X% || %y% < 1 || %y% > %SG_SQUARES_Y% )

return false

}

getMove()

{

global

Loop, %SG_SQUARES_Y%

{

y = %A_Index%

py := xCoordToPixel(y)

y1 := ( y + 1 )

y2 := ( y + 2 )

y3 := ( y + 3 )

y_1 := ( y - 1 )

y_2 := ( y - 2 )

y_3 := ( y - 3 )

Loop, %SG_SQUARES_X%

{

x = %A_Index%

if ( SG_LAST_X == x && SG_LAST_Y == y )

{

; Zero them so we can get this square next time if it's the only one.

SG_LAST_X = 0

SG_LAST_Y = 0

Continue

}

px := xCoordToPixel(px)

x1 := ( x + 1 )

x2 := ( x + 2 )

x3 := ( x + 3 )

x_1 := ( x - 1 )

x_2 := ( x - 2 )

x_3 := ( x - 3 )

col := SG_ARR_%x%_%y%

if (isSameAt(col, x_1, y2) && isSameAt(col, x_1, y1) && isSameAt(col, x_1, y_2) && isSameAt(col, x_1, y_1))

{

movePiece( x, y, x_1, y)

return

}

Posted (edited)

Can you give me a better description of what this script does? I began converting it but I may be able to write it from scratch if I know what your goal is.

Also I don't know if theres something wrong with this script but a lot of the braces don't balance. Did this work at all?

Edited by weaponx
Posted (edited)

Here's a little of what I can say based on your code:

To create a function, use

Func name (arg1, arg2)

...

EndFunc

Block If/Then/Endif.

If thisistrue Then

...

ElseIf thatistrue Then

...

Else

...

Endif

Variable Declaration:

All variables start with a dollar sign, so you can pretty much name them anything.

Assignment of variables:

$y = 1

$x= $x+1

Msgbox:

Msgbox(0,"Title","Text") ; generates simple Ok box.

AutoIt doesn't use brackets, nor will you ever see Goto statements (yes, they were banned).

Edited by RobertKipling
Posted

Can you give me a better description of what this script does? I began converting it but I may be able to write it from scratch if I know what your goal is.

Also I don't know if theres something wrong with this script but a lot of the braces don't balance. Did this work at all?

Thanks for your help...

Here is what I have for as the entire script...

Its for a game with 64 squares (8x8) similar to bejeweled

I would like to make it "smart" instead of brute force method...I've looked at game tree theory but I don't see how to use with this, not to mention the computing power needed.

CODE
^!r::Reload ; pause/reload the script.

^!z:: ;start script

; Globals.

; Offset to measure within the square.

SG_OFFSET_X=1

SG_OFFSET_Y=1

; Coords within the window for the top left of the board.

SG_ORIGIN_X=168

SG_ORIGIN_Y=15

; Size of a single square.

SG_SIZE_X=52

SG_SIZE_Y=52

; Number of squares on board.

SG_SQUARES_X=8

SG_SQUARES_Y=8

; Remember last move so we're less likely to get stuck trying the same wrong move forever.

SG_LAST_X=0

SG_LAST_Y=0

1 = 1

Loop

{

getWindow()

; Loop Y then X: move across every square, down only once per line.

sg_line := ("")

Loop, %SG_SQUARES_Y%

{

sg_y := A_Index

sg_py := yCoordToPixel(A_Index)

;MsgBox,%yCoordToPixel%

sg_line = %sg_line% `n# %A_Index% :

;MsgBox,%sg_line% `n# %A_Index%

Loop, %SG_SQUARES_X%

{

sg_x := A_Index

sg_px := xCoordToPixel(A_Index)

PixelGetColor, sg_color, %sg_px%, %sg_py%, RGB

sg_c := sg_color

SG_ARR_%sg_x%_%sg_y% := sg_c

col := SG_ARR_%sg_x%_%sg_y%

;MsgBox, SG_ARR_%sg_x%_%sg_y% = %col%

sg_line = %sg_line% %sg_c% ( %sg_x% , %sg_y% = %sg_px% , %sg_py% )

}

}

getmove()

}

getWindow()

{

;window info

}

; Convert a board y square coord to a screen y coord.

; This means our y coords are, internally, all "backwards" - but who cares?

yCoordToPixel(y)

{

global SG_SIZE_Y

global SG_ORIGIN_Y

global SG_OFFSET_Y

global SG_SQUARES_Y

; SG_SQUARES_Y - y as we're working from the bottom for highest scores.

return ( ( SG_SQUARES_Y - y + 1 ) * SG_SIZE_Y ) + SG_ORIGIN_Y + SG_OFFSET_Y

}

; Convert a board square x coord to a screen x coord.

xCoordToPixel(x)

{

global SG_SIZE_X

global SG_ORIGIN_X

global SG_OFFSET_X

return ( x * SG_SIZE_X ) + SG_ORIGIN_X + SG_OFFSET_X

}

;Make the mouse move a piece

movePiece(x1, y1, x2, y2)

{

global SG_DRAG_OK

global SG_ORIGIN_X

global SG_ORIGIN_Y

global SG_LAST_X

global SG_LAST_Y

SG_LAST_X := x1

SG_LAST_Y := y1

getWindow()

if 1 = 1

{

MouseClick, L, xCoordToPixel(x1), yCoordToPixel(y1),1,0

MouseClick, L, xCoordToPixel(x2), yCoordToPixel(y2),1,0

MouseClick, L, xCoordToPixel(x1), yCoordToPixel(y1),1,0

}

}

; Check that the piece in an array coord is not out of bounds,

; and is the same color.

isSameAt(col, x, y)

{

; Generic global to include array.

global

if (x < 1 || x > SG_SQUARES_X || y < 1 || y > SG_SQUARES_Y )

{

;MsgBox, returning false as OOB ( %x% < 1 || %x% > %SG_SQUARES_X% || %y% < 1 || %y% > %SG_SQUARES_Y% )

return false

}

ax := SG_ARR_%x%_%y%

if ( SG_ARR_%x%_%y% == col )

{

;MsgBox, returning true as %ax% == %col% and none of ( %x% < 1 || %x% > %SG_SQUARES_X% || %y% < 1 || %y% > %SG_SQUARES_Y% )

return true

}

;MsgBox, returning false as %ax% != %col% though none of ( %x% < 1 || %x% > %SG_SQUARES_X% || %y% < 1 || %y% > %SG_SQUARES_Y% )

return false

}

getmove()

{

global

Loop, %SG_SQUARES_Y%

{

y = %A_Index%

py := xCoordToPixel(y)

y1 := ( y + 1 )

y2 := ( y + 2 )

y3 := ( y + 3 )

y_1 := ( y - 1 )

y_2 := ( y - 2 )

y_3 := ( y - 3 )

Loop, %SG_SQUARES_X%

{

x = %A_Index%

; Anti-stick: don't play the same piece twice in a row

; If it's the only playable square, we'll get it next time round.

if ( SG_LAST_X == x && SG_LAST_Y == y )

{

; Zero them so we can get this square next time if it's the only one.

SG_LAST_X = 0

SG_LAST_Y = 0

Continue

}

px := xCoordToPixel(px)

x1 := ( x + 1 )

x2 := ( x + 2 )

x3 := ( x + 3 )

x_1 := ( x - 1 )

x_2 := ( x - 2 )

x_3 := ( x - 3 )

col := SG_ARR_%x%_%y%

if ( isSameAt(col, x2, y) && isSameAt(col, x3, y))

{

movePiece( x, y, x1, y)

return

}

if ( isSameAt(col, x_2, y) && isSameAt(col, x_3, y))

{

movePiece( x, y, x_1, y)

return

}

if ( isSameAt(col, x, y2) && isSameAt(col, x, y3))

{

movePiece( x, y, x, y1)

return

}

if ( isSameAt(col, x, y_2) && isSameAt(col, x, y_3))

{

movePiece( x, y, x, y_1)

return

}

if ( isSameAt(col, x_1, y_1) && isSameAt(col, x_1, y_2))

{

movePiece( x, y, x_1, y)

return

}

if ( isSameAt(col, x1, y_1) && isSameAt(col, x1, y_2))

{

movePiece( x, y, x1, y)

return

}

if ( isSameAt(col, x_1, y1) && isSameAt(col, x_1, y2))

{

movePiece( x, y, x_1, y)

return

}

if ( isSameAt(col, x1, y1) && isSameAt(col, x1, y2))

{

movePiece( x, y, x1, y)

return

}

if ( isSameAt(col, x1, y1) && isSameAt(col, x2, y1))

{

movePiece( x, y, x, y1)

return

}

if ( isSameAt(col, x1, y_1) && isSameAt(col, x2, y_1))

{

movePiece( x, y, x, y_1)

return

}

if ( isSameAt(col, x_1, y1) && isSameAt(col, x_2, y1))

{

movePiece( x, y, x, y1)

return

}

if ( isSameAt(col, x_1, y_1) && isSameAt(col, x_2, y_1))

{

movePiece( x, y, x, y_1)

return

}

if ( isSameAt(col, x_1, y_1) && isSameAt(col, x_1, y1))

{

movePiece( x, y, x_1, y)

return

}

if ( isSameAt(col, x1, y_1) && isSameAt(col, x1, y1))

{

movePiece( x, y, x1, y)

return

}

if ( isSameAt(col, x_1, y1) && isSameAt(col, x1, y1))

{

movePiece( x, y, x, y1)

return

}

if ( isSameAt(col, x_1, y_1) && isSameAt(col, x1, y_1))

{

movePiece( x, y, x, y_1)

return

}

}

}

}

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...