Jump to content
Sign in to follow this  
Topher

Plastic Sliding Squares Puzzle v1.01

Recommended Posts

Remember when you were a kid (if you are as ancient as I) and there were these cheap plastic puzzles of sliding squares that you were suppose to get in the right order?

Well this is that ;)

Enjoy

Posted Image

Version 1.01

Cosmetic and Platform changes

Plastic Sliding Puzzle.au3

Edited by Topher

[left][hr]
$mood = "whimsy"
$mode = "confused"
$randomChaos = True
Do
Something()
Until $Tired
[/left][left]Reflex (Arcade game)[/left][left]IX (Board game)[/left][left]The Word Game (Word game)[/left][left]Plastic Sliding Squares Puzzle (Puzzle)[/left]

Share this post


Link to post
Share on other sites

Wow, great game! Reminds me when I was young too.

Great implementation! Took me 168 moves - I know I'm a bit rusty ;)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-30 - Version 1.6.2.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites

Thank you.

When my score passes 16 or so I've so badly messed it up that I never get it. So I am impressed.


[left][hr]
$mood = "whimsy"
$mode = "confused"
$randomChaos = True
Do
Something()
Until $Tired
[/left][left]Reflex (Arcade game)[/left][left]IX (Board game)[/left][left]The Word Game (Word game)[/left][left]Plastic Sliding Squares Puzzle (Puzzle)[/left]

Share this post


Link to post
Share on other sites

As I recall there were only <edit>15</edit> slats in the square puzzles I ever solved Posted Image

In my mind it was so clearly a 5x5 grid, but in looking for a picture to turn into an icon they were all as you said 4x4.


[left][hr]
$mood = "whimsy"
$mode = "confused"
$randomChaos = True
Do
Something()
Until $Tired
[/left][left]Reflex (Arcade game)[/left][left]IX (Board game)[/left][left]The Word Game (Word game)[/left][left]Plastic Sliding Squares Puzzle (Puzzle)[/left]

Share this post


Link to post
Share on other sites

I remember that I had two of these puzzles. One was 4x4 and the other was 4x6 or even 4x7.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-30 - Version 1.6.2.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites

Nice!

Eukalyptus made some similar with pictures.

You need a picture with 440x440 pixels.

#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <File.au3>
#include <GDIPlus.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
Global $iTile = 0, $iSize, $hLabel[5][5], $aField[5][5][3]
Global $aFiles = _FileListToArray(@ScriptDir, "*.jpg", 1)
_ArrayCombine($aFiles, _FileListToArray(@ScriptDir, "*.bmp", 1))
_ArrayCombine($aFiles, _FileListToArray(@ScriptDir, "*.tif", 1))
_ArrayCombine($aFiles, _FileListToArray(@ScriptDir, "*.gif", 1))
_ArrayCombine($aFiles, _FileListToArray(@ScriptDir, "*.png", 1))
If Not IsArray($aFiles) Or $aFiles[0] < 1 Then
    MsgBox(0, "Error", "No pics found")
    Exit
EndIf
_GDIPlus_Startup()
Global $hImage, $iWidth, $iHeight
Global $hPenWhite = _GDIPlus_PenCreate(0x44FFFFFF, 2)
Global $hPenBlack = _GDIPlus_PenCreate(0x44000000, 2)
Global $hBrushBK = _GDIPlus_BrushCreateSolid(0xFF6C99B4)
Global $hGui = GUICreate("SchiebePuzzle", 452, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUISetOnEvent($GUI_EVENT_RESTORE, "_ReDraw")
GUISetBkColor(0x6C99B4)
GUICtrlCreateLabel("", 4, 4, 444, 444)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetBkColor(-1, 0x558097)
GUICtrlCreateLabel("", 6, 6, 442, 442)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetBkColor(-1, 0x88B8D8)
GUICtrlCreateLabel("", 6, 6, 440, 440)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetBkColor(-1, 0x6C99B4)
GUICtrlCreateLabel("Anzahl der Felder:", 10, 468, 90, 20)
Global $hInput = GUICtrlCreateInput(3, 100, 465, 30, 20, $ES_READONLY)
GUICtrlCreateUpdown(-1)
GUICtrlSetLimit(-1, 5, 2)
GUICtrlSetOnEvent(-1, "_SetTile")
GUICtrlCreateButton("Mischen", 160, 465, 80, 20)
GUICtrlSetOnEvent(-1, "_Randomize")
GUICtrlCreateButton("Neues Bild", 260, 465, 80, 20)
GUICtrlSetOnEvent(-1, "_LoadRandomImage1")
GUICtrlCreateButton("Beenden", 360, 465, 80, 20)
GUICtrlSetOnEvent(-1, "_Exit")
GUISetState()
Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
GUIRegisterMsg($WM_PAINT, '_Redraw')
_LoadRandomImage()
_SetTile()

While 1
    Sleep(100)
WEnd

Func _MoveField()
    Local $iX, $iY, $iNX, $iNY, $iDir
    For $i = 0 To $iTile - 1
        For $j = 0 To $iTile - 1
            If $hLabel[$i][$j] = @GUI_CtrlId Then
                $iX = $i
                $iY = $j
                ExitLoop 2
            EndIf
        Next
    Next
    If $aField[$iX][$iY][2] <> 2 Then Return
    $iNX = $iX
    $iNY = $iY
    Select
        Case $iX > 0 And $aField[$iX - 1][$iY][2] = 0
            $iNX = $iX - 1
            $iDir = 1
        Case $iX < $iTile - 1 And $aField[$iX + 1][$iY][2] = 0
            $iNX = $iX + 1
            $iDir = 2
        Case $iY > 0 And $aField[$iX][$iY - 1][2] = 0
            $iNY = $iY - 1
            $iDir = 3
        Case $iY < $iTile - 1 And $aField[$iX][$iY + 1][2] = 0
            $iNY = $iY + 1
            $iDir = 4
    EndSelect
    For $i = 0 To $iSize Step 5
        Switch $iDir
            Case 1
                _DrawField($iX, $iY, -$i, 0)
            Case 2
                _DrawField($iX, $iY, $i, 0)
            Case 3
                _DrawField($iX, $iY, 0, -$i)
            Case 4
                _DrawField($iX, $iY, 0, $i)
        EndSwitch
        Sleep(10)
    Next
    $aField[$iNX][$iNY][0] = $aField[$iX][$iY][0]
    $aField[$iNX][$iNY][1] = $aField[$iX][$iY][1]
    $aField[$iNX][$iNY][2] = $aField[$iX][$iY][2]
    $aField[$iX][$iY][2] = False
    GUICtrlSetBkColor($hLabel[$iX][$iY], 0x6C99B4)
    _DrawField($iNX, $iNY)
    _SetFreeField()
EndFunc   ;==>_MoveField
Func _LoadRandomImage1()
    _WinAPI_RedrawWindow($hGui)
    _LoadRandomImage()
    _ReDraw()
EndFunc   ;==>_LoadRandomImage1

Func _LoadRandomImage($Orig = False)
    Local $iRandom = Random(1, $aFiles[0], 1)
    If $iRandom = 0 Or $aFiles[0] = 1 Then $iRandom = 1
    If $Orig = False Then $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "" & $aFiles[$iRandom])
    $iWidth = _GDIPlus_ImageGetWidth($hImage)
    $iHeight = _GDIPlus_ImageGetHeight($hImage)
    For $i = 0 To $iTile - 1
        For $j = 0 To $iTile - 1
            GUICtrlSetCursor($hLabel[$i][$j], 2)
            $aField[$i][$j][0] = $i * $iSize
            $aField[$i][$j][1] = $j * $iSize
            $aField[$i][$j][2] = 1
        Next
    Next
    $aField[0][0][2] = 0
    $aField[1][0][2] = 2
    $aField[0][1][2] = 2
    GUICtrlSetCursor($hLabel[1][0], 0)
    GUICtrlSetCursor($hLabel[0][1], 0)
EndFunc   ;==>_LoadRandomImage
Func _Randomize()
    GUIRegisterMsg($WM_PAINT, '')
    Local $iX = 0, $iY = 0, $iNX, $iNY, $iDir
    For $i = 0 To $iTile - 1
        For $j = 0 To $iTile - 1
            If $aField[$i][$j][2] = 0 Then
                $iX = $i
                $iY = $j
                ExitLoop 2
            EndIf
        Next
    Next
    For $c = 1 To 500
        Do
            $iNX = $iX
            $iNY = $iY
            $iDir = Random(1, 4, 1)
            Select
                Case $iDir = 2 And $iX > 0
                    $iNX = $iX - 1
                Case $iDir = 1 And $iX < $iTile - 1
                    $iNX = $iX + 1
                Case $iDir = 4 And $iY > 0
                    $iNY = $iY - 1
                Case $iDir = 3 And $iY < $iTile - 1
                    $iNY = $iY + 1
            EndSelect
        Until $iX <> $iNX Or $iY <> $iNY
        $aField[$iX][$iY][0] = $aField[$iNX][$iNY][0]
        $aField[$iX][$iY][1] = $aField[$iNX][$iNY][1]
        $aField[$iX][$iY][2] = $aField[$iNX][$iNY][2]
        $aField[$iNX][$iNY][2] = False
        GUICtrlSetBkColor($hLabel[$iNX][$iNY], 0x6C99B4)
        _DrawField($iX, $iY)
        $iX = $iNX
        $iY = $iNY
    Next
    _ReDraw()
    _SetFreeField()
    GUIRegisterMsg($WM_PAINT, '_Redraw')
EndFunc   ;==>_Randomize
Func _SetFreeField()
    For $i = 0 To $iTile - 1
        For $j = 0 To $iTile - 1
            GUICtrlSetCursor($hLabel[$i][$j], 2)
            If $aField[$i][$j][2] <> 0 Then $aField[$i][$j][2] = 1
        Next
    Next
    For $i = 0 To $iTile - 1
        For $j = 0 To $iTile - 1
            If $aField[$i][$j][2] = False Then
                If $i > 0 Then
                    GUICtrlSetCursor($hLabel[$i - 1][$j], 0)
                    $aField[$i - 1][$j][2] = 2
                EndIf
                If $i < $iTile - 1 Then
                    GUICtrlSetCursor($hLabel[$i + 1][$j], 0)
                    $aField[$i + 1][$j][2] = 2
                EndIf
                If $j > 0 Then
                    GUICtrlSetCursor($hLabel[$i][$j - 1], 0)
                    $aField[$i][$j - 1][2] = 2
                EndIf
                If $j < $iTile - 1 Then
                    GUICtrlSetCursor($hLabel[$i][$j + 1], 0)
                    $aField[$i][$j + 1][2] = 2
                EndIf
            EndIf
        Next
    Next
EndFunc   ;==>_SetFreeField

Func _DrawField($x, $y, $iOX = 0, $iOY = 0)
    If $aField[$x][$y][2] = False Then Return
    Local $iX = $aField[$x][$y][0]
    Local $iY = $aField[$x][$y][1]
    Switch True
        Case $iOX > 0
            _GDIPlus_GraphicsFillRect($hGraphics, 6 + $x * $iSize, 6 + $y * $iSize, $iOX, $iSize, $hBrushBK)
        Case $iOX < 0
            _GDIPlus_GraphicsFillRect($hGraphics, 6 + $x * $iSize + $iSize + $iOX, 6 + $y * $iSize, -$iOX, $iSize, $hBrushBK)
        Case $iOY > 0
            _GDIPlus_GraphicsFillRect($hGraphics, 6 + $x * $iSize, 6 + $y * $iSize, $iSize, $iOY, $hBrushBK)
        Case $iOY < 0
            _GDIPlus_GraphicsFillRect($hGraphics, 6 + $x * $iSize, 6 + $y * $iSize + $iSize + $iOY, $iSize, -$iOY, $hBrushBK)
    EndSwitch
    _GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hImage, $iX, $iY, $iSize, $iSize, 6 + $x * $iSize + $iOX, 6 + $y * $iSize + $iOY, $iSize, $iSize)
    _GDIPlus_GraphicsDrawLine($hGraphics, 6 + $x * $iSize + $iOX, 7 + $y * $iSize + $iOY, $iSize + 6 + $x * $iSize + $iOX, 7 + $y * $iSize + $iOY, $hPenWhite)
    _GDIPlus_GraphicsDrawLine($hGraphics, 7 + $x * $iSize + $iOX, 6 + $y * $iSize + $iOY, 7 + $x * $iSize + $iOX, $iSize + 6 + $y * $iSize + $iOY, $hPenWhite)
    _GDIPlus_GraphicsDrawLine($hGraphics, 6 + $x * $iSize + $iOX, $iSize + 5 + $y * $iSize + $iOY, $iSize + 6 + $x * $iSize + $iOX, $iSize + 5 + $y * $iSize + $iOY, $hPenBlack)
    _GDIPlus_GraphicsDrawLine($hGraphics, $iSize + 5 + $x * $iSize + $iOX, 6 + $y * $iSize + $iOY, $iSize + 5 + $x * $iSize + $iOX, $iSize + 6 + $y * $iSize + $iOY, $hPenBlack)
EndFunc   ;==>_DrawField

Func _SetTile()
    If $iTile = GUICtrlRead($hInput) Then Return
    GUIRegisterMsg($WM_PAINT, '')
    For $i = 0 To 4
        For $j = 0 To 4
            GUICtrlDelete($hLabel[$i][$j])
        Next
    Next
    $iTile = GUICtrlRead($hInput)
    $iSize = Round(440 / $iTile)
    For $i = 0 To $iTile - 1
        For $j = 0 To $iTile - 1
            $hLabel[$i][$j] = GUICtrlCreateLabel("", 6 + $i * $iSize, 6 + $j * $iSize, $iSize, $iSize)
            GUICtrlSetCursor(-1, 2)
            GUICtrlSetOnEvent(-1, "_MoveField")
        Next
    Next
    _LoadRandomImage(True)
    _ReDraw()
    GUIRegisterMsg($WM_PAINT, '_Redraw')
EndFunc   ;==>_SetTile

Func _ReDraw()
    For $i = 0 To $iTile - 1
        For $j = 0 To $iTile - 1
            _DrawField($i, $j)
        Next
    Next
EndFunc   ;==>_ReDraw

Func _ArrayCombine(ByRef $aArray, $aNew)
    If Not IsArray($aNew) Then Return
    Local $iArray = UBound($aArray) - 1, $iNew = UBound($aNew) - 1
    Local $aReturn[$iArray + $iNew + 1]
    For $i = 1 To $iArray
        $aReturn[$i] = $aArray[$i]
    Next
    For $i = 1 To $iNew
        $aReturn[$i + $iArray] = $aNew[$i]
    Next
    $aReturn[0] = $iArray + $iNew
    $aArray = $aReturn
EndFunc   ;==>_ArrayCombine
Func _Exit()
    _GDIPlus_Shutdown()
    Exit
EndFunc   ;==>_Exit

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites

On my XP, I believe the $BS_BITMAP in the GUICtrlCreateButton function was hiding all the numbers on the buttons.

I continued to play with your script and swap these to commands around, Scramble() and GUISetState(): and,

added colour.

Topher, good job.

#NoTrayIcon
#cs ----------------------------------------------------------------------------
    AutoIt Version: 3.3.6.1
    Author:   Garth Bigelow
    email:     garthbigelow@gmail.com
    Script Function: Sliding Squiare Puzzle
#ce ----------------------------------------------------------------------------

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <WindowsConstants.au3>

Const $version = "Plastic Sliding Squares Puzzle v1.00"

; Size of the Grid - 1
; 2 to 11
$Size = 4
;
; Speed of Sliding Movement
; 0 to ridiculously slow
$Speed = 0
;
; Number of potential moves
; needs to be rather larger as movement back and forth happens more often than you would think
; the smaller the grid the larger complexity needs to be
; the greater complexity the more challenging the puzzle
$Complexity = 30
;
; Whether empty square is the last number or not
; 0 for not
$Advanced = 0
;
; Disregard the Ini file and use the values above or not
$Ignore = False

If FileExists("PSSP.ini") = 0 Then
    IniWrite("PSSP.ini", "Config", "Grid Size", 5)
    IniWrite("PSSP.ini", "Config", "Speed", 10)
    IniWrite("PSSP.ini", "Config", "Complexity", 30)
    IniWrite("PSSP.ini", "Config", "Adanced", 0)
EndIf
If Not $Ignore Then
    $Size = IniRead("PSSP.ini", "Config", "Grid Size", 5) - 1
    $Speed = IniRead("PSSP.ini", "Config", "Speed", 10)
    $Complexity = IniRead("PSSP.ini", "Config", "Complexity", 30)
    $Advanced = IniRead("PSSP.ini", "Config", "Adanced", 0)
EndIf

Dim $hBoard[($Size + 1)][($Size + 1)]

Global $GoX, $GoY, $MoveCount = 0, $MenuSpace = 0

$hGUI = GUICreate($version, 68 * ($Size + 1) + 3, 68 * ($Size + 1) + $MenuSpace, -1, -1, -1, $WS_EX_COMPOSITED)
GUISetBkColor(0xAA4444)
If $Advanced = 0 Then
    $EmptySquare = ($Size + 1) * ($Size + 1)
Else
    $EmptySquare = Rand(($Size + 1) * ($Size + 1))
EndIf
For $x = 0 To $Size
    For $y = 0 To $Size
        $label = ($y) * ($Size + 1) + ($x + 1)

        $hBoard[$x][$y] = GUICtrlCreateButton($label, $x * 68 + 3, $y * 68 + 3 + $MenuSpace, 62, 62, $BS_FLAT)
        ;$hBoard[$x][$y] = GUICtrlCreateButton(String($label), $x * 68 + 3, $y * 68 + 3 + $MenuSpace, 62, 62, BitOR($BS_BITMAP, $BS_FLAT))
        GUICtrlSetBkColor(-1, Number("0x" & Hex(Random(0x80, 0xff, 1), 2) & Hex(Random(0x80, 0xff, 1), 2) & Hex(Random(0x80, 0xff, 1), 2)))

        If $EmptySquare = $label Then GUICtrlSetState($hBoard[$x][$y], $GUI_HIDE)
    Next
Next

Scramble()
GUISetState()

$MoveCount = 0

While True
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then
        GUIDelete()
        Exit
    EndIf
    ProcessClick()
    If Over() Then
        NumToCoord($EmptySquare)
        GUICtrlSetState($hBoard[$GoX][$GoY], $GUI_SHOW)
        MsgBox(48, "Puzzle Completed", "You completed the puzzle in " & $MoveCount & " moves.")
        Exit
    EndIf
WEnd

Func ProcessClick()

    For $px = 0 To $Size
        For $py = 0 To $Size
            If $msg = $hBoard[$px][$py] Then
                If IsValidClick($px, $py) Then
                    Slide($px, $py)
                    Return
                EndIf
                Return
            EndIf
        Next
    Next
    Sleep(10)

EndFunc   ;==>ProcessClick

Func Scramble()

    $holdSpeed = $Speed
    $Speed = 0
    $a = $Complexity
    While $a > 0
        $x = Rand($Size)
        $y = Rand($Size)
        If IsValidClick($x, $y) Then
            Slide($x, $y)
            $a -= 1
        EndIf
    WEnd
    $Speed = $holdSpeed

EndFunc   ;==>Scramble

Func Slide($x, $y)

    NumToCoord($EmptySquare)
    If $x > $GoX Then SlideLeft($x, $y)
    If $x < $GoX Then SlideRight($x, $y)
    If $y > $GoY Then SlideUp($x, $y)
    If $y < $GoY Then SlideDown($x, $y)
    $MoveCount += 1

EndFunc   ;==>Slide

Func SlideDown($x, $y)

    NumToCoord($EmptySquare)
    For $line = 1 To 68
        For $b = $y To $GoY
            GUICtrlSetPos($hBoard[$x][$b], $x * 68 + 3, ($b * 68 + 3 + $MenuSpace) + $line)
        Next
        Sleep($Speed)
    Next
    $holdHandle = $hBoard[$GoX][$GoY]
    For $b = $GoY - 1 To $y Step -1
        $hBoard[$x][$b + 1] = $hBoard[$x][$b]
    Next
    $hBoard[$x][$y] = $holdHandle

EndFunc   ;==>SlideDown

Func SlideLeft($x, $y)

    NumToCoord($EmptySquare)
    For $line = 1 To 68
        For $b = $GoX To $x
            GUICtrlSetPos($hBoard[$b][$y], ($b * 68 + 3) - $line, ($y * 68 + 3 + $MenuSpace))
        Next
        Sleep($Speed)
    Next
    $holdHandle = $hBoard[$GoX][$GoY]
    For $b = $GoX + 1 To $x
        $hBoard[$b - 1][$y] = $hBoard[$b][$y]
    Next
    $hBoard[$x][$y] = $holdHandle

EndFunc   ;==>SlideLeft

Func SlideRight($x, $y)

    NumToCoord($EmptySquare)
    For $line = 1 To 68
        For $b = $x To $GoX - 1
            GUICtrlSetPos($hBoard[$b][$y], ($b * 68 + 3) + $line, ($y * 68 + 3 + $MenuSpace))
        Next
        Sleep($Speed)
    Next
    $holdHandle = $hBoard[$GoX][$GoY]
    For $b = $GoX - 1 To $x Step -1
        $hBoard[$b + 1][$y] = $hBoard[$b][$y]
    Next
    $hBoard[$x][$y] = $holdHandle

EndFunc   ;==>SlideRight

Func SlideUp($x, $y) ; checked

    NumToCoord($EmptySquare)
    For $line = 1 To 68
        For $b = $GoY To $y
            GUICtrlSetPos($hBoard[$x][$b], $x * 68 + 3, ($b * 68 + 3 + $MenuSpace) - $line)
        Next
        Sleep($Speed)
    Next
    $holdHandle = $hBoard[$GoX][$GoY]
    For $b = $GoY + 1 To $y
        $hBoard[$x][$b - 1] = $hBoard[$x][$b]
    Next
    $hBoard[$x][$y] = $holdHandle

EndFunc   ;==>SlideUp

Func IsValidClick($x, $y)

    NumToCoord($EmptySquare)
    $EmptyX = $GoX
    $EmptyY = $GoY
    NumToCoord(GUICtrlRead($hBoard[$x][$y]))
    If $EmptyX = $GoX Or $EmptyY = $GoY Then Return 1
    Return 0

EndFunc   ;==>IsValidClick

Func NumToCoord($Num)

    For $x = 0 To $Size
        For $y = 0 To $Size
            $lnum = GUICtrlRead($hBoard[$x][$y])
            If $Num = $lnum Then
                $GoX = $x
                $GoY = $y
                ExitLoop 2
            EndIf
        Next
    Next

EndFunc   ;==>NumToCoord

Func Over()

    For $x = 0 To $Size
        For $y = 0 To $Size
            If ($y) * ($Size + 1) + ($x + 1) <> GUICtrlRead($hBoard[$x][$y]) Then Return 0
        Next
    Next
    Return 1

EndFunc   ;==>Over


;
; bend random() function to my needs
;
Func Rand($pMax)

    Return Random(0, $pMax, 1)

EndFunc   ;==>Rand

Share this post


Link to post
Share on other sites

On my XP, I believe the $BS_BITMAP in the GUICtrlCreateButton function was hiding all the numbers on the buttons.

I continued to play with your script and swap these to commands around, Scramble() and GUISetState(): and,

added colour.

Thanks.

I played with it a bit, opting for the black and red digits of the most common versions of the physical puzzle.

Thanks for the knowledge on $BS_BITMAP


[left][hr]
$mood = "whimsy"
$mode = "confused"
$randomChaos = True
Do
Something()
Until $Tired
[/left][left]Reflex (Arcade game)[/left][left]IX (Board game)[/left][left]The Word Game (Word game)[/left][left]Plastic Sliding Squares Puzzle (Puzzle)[/left]

Share this post


Link to post
Share on other sites

Great! Looks even better - more like the one I had when I was young (so long ago ;)).

The new version seems to be even faster: I only needed 47 moves.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-30 - Version 1.6.2.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites

Removed slide animation. Took too long.

If you have time, see if you could add frame rate independent animations.

Func SlideDown($x, $y)

    NumToCoord($EmptySquare)

    For $b = $y To $GoY
        GUICtrlSetPos($hBoard[$x][$b], $x * 68 + 3, ($b * 68 + 3 + $MenuSpace) + 68)
    Next
    $holdHandle = $hBoard[$GoX][$GoY]
    For $b = $GoY - 1 To $y Step - 1
        $hBoard[$x][$b+1] = $hBoard[$x][$b]
    Next
    $hBoard[$x][$y] = $holdHandle

EndFunc

Func SlideLeft($x, $y)

    NumToCoord($EmptySquare)

    For $b = $GoX To $x
        GUICtrlSetPos($hBoard[$b][$y], ($b * 68 + 3) - 68, ($y * 68 + 3 + $MenuSpace))
    Next
    $holdHandle = $hBoard[$GoX][$GoY]
    For $b = $GoX + 1 To $x
        $hBoard[$b-1][$y] = $hBoard[$b][$y]
    Next
    $hBoard[$x][$y] = $holdHandle

EndFunc

Func SlideRight($x, $y)

    NumToCoord($EmptySquare)

    For $b = $x To $GoX - 1
        GUICtrlSetPos($hBoard[$b][$y], ($b * 68 + 3) + 68, ($y * 68 + 3 + $MenuSpace))
    Next
    $holdHandle = $hBoard[$GoX][$GoY]
    For $b = $GoX - 1 To $x Step - 1
        $hBoard[$b+1][$y] = $hBoard[$b][$y]
    Next
    $hBoard[$x][$y] = $holdHandle

EndFunc

Func SlideUp($x, $y) ; checked

    NumToCoord($EmptySquare)

    For $b = $GoY To $y
        GUICtrlSetPos($hBoard[$x][$b], $x * 68 + 3, ($b * 68 + 3 + $MenuSpace) - 68)
    Next
    $holdHandle = $hBoard[$GoX][$GoY]
    For $b = $GoY + 1 To $y
        $hBoard[$x][$b-1] = $hBoard[$x][$b]
    Next
    $hBoard[$x][$y] = $holdHandle

EndFunc
Edited by Manadar

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Barney
      Hi guys, I just finished a Connect 4 game by using MiniMax with Alpha Beta Pruning. I haven't written a program for a long time, but writing an
      AI program is always funny! I have to learn how the algorithm works and try to optimize the code to run faster. Let's play and have fun!
       

       

      Oops, I lost the game ...
      Thanks guys!
      Download: Connect 4.zip
    • By Chimp
      After watching this movie (https://www.youtube.com/watch?v=cPiDHXtM0VA) I wanted to try the test to see how much i could compete with that chimpanzee so i created this script.
      well, actually passing that test is a lot harder than it sounds. With the difficulty set to seven numbers and a display time of one second, I can only remember 2 or 3 numbers ... (what a disappointment)
      I can only do better if I reduce the slider to 5 numbers and increase the storage time to 2 seconds (the easyest level), a very poor performance. That chimpanzee is great.
      The script offers you a sequence of 10 random quizzes. At the end it gives you the percentage of your "level". The chimpanzee resolves on average 8 out of 10 (80%), so you can compare your performance to that of the chimpanzee.
      How to play:
      Run the script. At the beginning there are 2 sliders at the bottom of the screen where you can set the difficulty level by varying the memorization time and the amount of numbers to memorize as you like. After setting the difficulty, click the circle on the bottom left to get started. after the first move the sliders are no longer displayed until the next game, (the game lasts 10 attempts, there is a progress bar at the bottom of the screen to see where you are) between one test and the other of the ten, click on the circle to move on to the next test have fun.
      #include <GUIConstants.au3> #include <MsgBoxConstants.au3> #include <Array.au3> #include <WinAPIMisc.au3> ; HotKeySet("{ESC}", "_EndOfGame") Global $iNumbersToGuess = 7, $iExpositionTime = 1000, $iMatches = 10, $iMatchesWon Global $aNumbers[10] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Global $aButtons[10], $aControls[5] Global $iWinWidth = @DesktopWidth / 2, $iWinHeight = @DesktopHeight / 2, $iButtonXSide = Int($iWinWidth / UBound($aNumbers)), $iButtonYSide = Int($iWinHeight / UBound($aNumbers)), $sWinTitle = "Beat the Chimp" Global $aX[Int($iWinWidth / $iButtonXSide)], $aY[Int($iWinHeight / $iButtonYSide)], $iNdx = 0, $aPoints[3], $score, $GUIGetMsg, $iDockHeight = 50, $iProgrssHeight = 5 For $i = 0 To (Int($iWinWidth / $iButtonXSide) - 1) * $iButtonXSide Step $iButtonXSide $aX[$iNdx] = $i $iNdx += 1 Next $iNdx = 0 For $i = 0 To (Int($iWinHeight / $iButtonYSide) - 1) * $iButtonYSide Step $iButtonYSide $aY[$iNdx] = $i $iNdx += 1 Next Global Const $iDockLeftBorder = 200, $iForeColor = 0xFFFFFF, $iBackColor = 0x000000 Global $hGUI = GUICreate($sWinTitle, $iWinWidth, $iWinHeight + $iDockHeight + $iProgrssHeight, @DesktopWidth / 4, @DesktopHeight / 5) GUISetBkColor($iBackColor, $hGUI) ; the circle to continue playing $aControls[0] = GUICtrlCreateLabel(ChrW(0x25EF), 0, $iWinHeight + 1, 100, $iDockHeight, 0x01) ; GUICtrlSetTip(-1, "Click the circle," & @CRLF & "then click the squares" & @CRLF & "in numeric order.") GUICtrlSetFont(-1, 24, 900) GUICtrlSetColor(-1, $iForeColor) GUICtrlSetBkColor(-1, $iBackColor) ; slider for the amount of numbers to guess $aControls[2] = GUICtrlCreateSlider($iDockLeftBorder, $iWinHeight, $iWinWidth - $iDockLeftBorder, Int($iDockHeight / 2)) GUICtrlSetLimit(-1, 10, 5) ; 5 steps 5 (easy) to 10 (hard) GUICtrlSetData(-1, $iNumbersToGuess) ; label for the amount of quizzes $aControls[1] = GUICtrlCreateLabel("Numbers : " & GUICtrlRead($aControls[2]), 100, $iWinHeight + 1, 100) GUICtrlSetColor(-1, $iForeColor) ; slider for the exposition time $aControls[4] = GUICtrlCreateSlider($iDockLeftBorder, $iWinHeight + (Int($iDockHeight / 2)), $iWinWidth - $iDockLeftBorder, $iDockHeight / 2) GUICtrlSetLimit(-1, 8, 1) ; 8 steps (0f 250ms each) GUICtrlSetData(-1, $iExpositionTime / 250) ; label for the exposition time $aControls[3] = GUICtrlCreateLabel("ms to show : " & GUICtrlRead($aControls[4]) * 250, 100, $iWinHeight + 1 + (Int($iDockHeight / 2)), 100) GUICtrlSetColor(-1, $iForeColor) ; progress bar of the match Global $idProgressbar = GUICtrlCreateProgress(0, $iWinHeight + $iDockHeight, $iWinWidth, $iProgrssHeight) ; Create buttons For $i = 0 To 9 $aButtons[$i] = GUICtrlCreateLabel($i + 1, $iWinWidth + 5, $iWinHeight + $iDockHeight + $iProgrssHeight + 5, $iButtonXSide, $iButtonYSide, 0x01) GUICtrlSetFont($aButtons[$i], 24) GUICtrlSetColor($aButtons[$i], $iForeColor) GUICtrlSetBkColor($aButtons[$i], $iBackColor) Next GUISetState(@SW_SHOW) ; --- Main loop --- Do ; New game $iMatchesWon = 0 GUICtrlSetData($idProgressbar, 0) For $iRound = 1 To $iMatches ; the game lasts $iMatches rounds $iNdx = 0 ; reset pointer (index to the next correct answer) _HideControls(__get_IDs_by_indexes($aButtons, $aNumbers)) ; remove the numbers from the screen ; show the dock and wait (only in the first round are also shown the sliders) _ShowControls($iRound = 1 ? $aControls : $aControls[0]) ; display the dock's control(s) While 1 Switch GUIGetMsg() Case $aControls[0] ; The circle (play a new quiz) ExitLoop Case $aControls[2] ; slider to choose how many numbers to guess $iNumbersToGuess = GUICtrlRead($aControls[2]) GUICtrlSetData($aControls[1], "Numbers : " & $iNumbersToGuess) Case $aControls[4] ; slider to choose how long (milliseconds) to show the numbers $iExpositionTime = GUICtrlRead($aControls[4]) * 250 ; 8 steps of 250 milliseconds each GUICtrlSetData($aControls[3], "ms to show : " & $iExpositionTime) Case $GUI_EVENT_CLOSE _EndOfGame() EndSwitch WEnd _HideControls($aControls) ; hide the dock Sleep(750) ; wait a bit $aQuiz = _GenerateQuiz($iNumbersToGuess) ; generate random elements to guess _SpreadControls(__get_IDs_by_indexes($aButtons, $aQuiz)) ; scatter the numbers on the GUI _ShowControls(__get_IDs_by_indexes($aButtons, $aQuiz)) ; display the numbers Sleep($iExpositionTime) ; leave numbers visible for a short time _MaskControls(__get_IDs_by_indexes($aButtons, $aQuiz)) ; mask the numbers GUICtrlSetData($idProgressbar, Round($iRound / $iMatches * 100)) ; _ShowControls(__get_IDs_by_indexes($aButtons, $aQuiz)) ; <------------- keep numbers visible FOR DEBUG PURPOSE ONLY! While 1 ; wait for a move $GUIGetMsg = GUIGetMsg() If $GUIGetMsg = $GUI_EVENT_CLOSE Then _EndOfGame() ; scan all quiz buttons to check if one was pressed For $i = 0 To UBound($aQuiz) - 1 ; $aButtons) - 1 If $GUIGetMsg = $aButtons[$aQuiz[$i] - 1] Then If $i = $iNdx Then ; -------------------------- ; actions for a right move ; -------------------------- ; hide the guessed number _HideControls($aButtons[$aQuiz[$i] - 1]) ; --------------------------------- ; check if this round is complete ; --------------------------------- If $iNdx = (UBound($aQuiz) - 1) Then _WinAPI_PlaySound("SystemExclamation", Null, BitOR($SND_ALIAS, $SND_ASYNC)) $iMatchesWon += 1 ExitLoop 2 EndIf ; play a short ok sound ; _WinAPI_PlaySound("FaxBeep", Null, BitOR($SND_ALIAS, $SND_ASYNC)) ; "SystemAsterisk" $iNdx += 1 ; set index to next correct answer Else ; -------------------------- ; actions for a wrong move ; -------------------------- ; show all the right sequence _ShowControls(__get_IDs_by_indexes($aButtons, $aQuiz)) _WinAPI_PlaySound("DeviceFail", Null, BitOR($SND_ALIAS, $SND_ASYNC)) ; give a little time to the user to control it Sleep(1500) ; go to next step ExitLoop 2 EndIf EndIf Next WEnd ; loop till end of match $score = Round($iMatchesWon / $iMatches * 100, 2) ; percentage Select Case $score < 80 $sResult = "The chimp beat you!" Case $score > 80 $sResult = "You beat the chimp!" Case $score = 80 $sResult = "You tied the chimp." EndSelect Next ; next round ; game over? Until MsgBox($MB_YESNO + $MB_ICONINFORMATION + $MB_TASKMODAL + $MB_SETFOREGROUND, _ "Game over", _ "You got " & $score & "% correct." & @CRLF & _ "Ayumu averages 80% correct." & @CRLF & $sResult & @CRLF & @CRLF & _ "do you want to try again?") <> 6 Func _SpreadControls($aTemp) ; place the required numbers scattered on the GUI SRandom(@YEAR + @MON + @MDAY + @HOUR + @MIN + @SEC) _ArrayShuffle($aX) _ArrayShuffle($aY) ; first, place all buttons out of GUI For $i = 0 To UBound($aButtons) - 1 GUICtrlSetPos($aButtons[$i], $iWinWidth + 5, $iWinHeight + $iDockHeight + $iProgrssHeight + 5) GUICtrlSetState($aButtons[$i], $GUI_DISABLE) Next ; Then place only the numbers of this quiz in visible area For $i = 0 To UBound($aTemp) - 1 GUICtrlSetPos($aTemp[$i], $aX[$i], $aY[$i]) GUICtrlSetState($aTemp[$i], $GUI_ENABLE) Next EndFunc ;==>_SpreadControls Func _GenerateQuiz($iNumElements) ; generate an array of required random numbers SRandom(@YEAR + @MON + @MDAY + @HOUR + @MIN + @SEC) Local $aTemp[$iNumElements] _ArrayShuffle($aNumbers) For $i = 0 To $iNumElements - 1 $aTemp[$i] = $aNumbers[$i] Next _ArraySort($aTemp) Return $aTemp EndFunc ;==>_GenerateQuiz Func _ShowControls($aTemp) ; render controls visible (and enabled) $aTemp = _EnforceArray($aTemp) For $i = 0 To UBound($aTemp) - 1 GUICtrlSetState($aTemp[$i], $GUI_SHOW) GUICtrlSetColor($aTemp[$i], $iForeColor) GUICtrlSetBkColor($aTemp[$i], $iBackColor) Next EndFunc ;==>_ShowControls Func _MaskControls($aTemp) ; mask the controls $aTemp = _EnforceArray($aTemp) For $i = 0 To UBound($aTemp) - 1 GUICtrlSetColor($aTemp[$i], $iForeColor) GUICtrlSetBkColor($aTemp[$i], $iForeColor) Next EndFunc ;==>_MaskControls Func _HideControls($aTemp) ; hide the controls (implies disable) $aTemp = _EnforceArray($aTemp) For $i = 0 To UBound($aTemp) - 1 GUICtrlSetState($aTemp[$i], $GUI_HIDE) ; $GUI_DISABLE) ; GUICtrlSetColor($aButtons[$aTemp[$i] - 1], $iBackColor) ; GUICtrlSetBkColor($aButtons[$aTemp[$i] - 1], $iBackColor) Next EndFunc ;==>_HideControls Func _EnforceArray($vParam) ; if only one value is passed, turn it into an array of only 1 element If Not IsArray($vParam) Then Local $aTemp[1] = [$vParam] Return $aTemp EndIf Return $vParam EndFunc ;==>_EnforceArray Func __get_IDs_by_indexes(ByRef $aCtrls, ByRef $aNdxs) ; returns the handles of the controls pointed to by the indexes Local $aTemp[UBound($aNdxs)] For $i = 0 To UBound($aNdxs) - 1 $aTemp[$i] = $aCtrls[$aNdxs[$i] - 1] Next Return $aTemp EndFunc ;==>__get_IDs_by_indexes Func _EndOfGame() ; _WinAPI_PlaySound ("SystemExit" , Null, $SND_ALIAS) GUIDelete() Exit EndFunc ;==>_EndOfGame P.S. At this link (https://web.archive.org/web/20131006161544/http://games.lumosity.com/chimp.html) there is a Flash version of this game.
    • By gwinter
      Just something I made to auto-collect Gil from FFCC and to test out a new templating system for AutoIt. The templating system is a work in progress, but it is meant to be a companion to AutoIT, which automates creation of GUI, buttons, scripts, templates, etc. It also has built-in chat and group-collaboration, an asset management system and online library for resources.
      -snip-
    • By n0ktar
      is it possible to make a wall chams in rainbow six siege using autoit scripts? tell me please and how . 
    • By spikespaz
      The rule against game automation is misguided and unhelpful for the following reasons.
       
      I am a developer, using AutoIt to automate testing for a game that I am developing. Singleplayer games can be mundane and sometimes cheating can be overlooked. Multiplayer games usually have anticheat against repetitive robotic actions anyways. People want to override the control schemes of games with bad customization. Eg. Axiom Verge, Fortnite (Crouching). Game automation is not always bad. If the user feels the need to automate a singleplayer game for boring or mundane tasks, that is their choice. Similarly, if I wish to use scripts to automate testing, that is my choice.
      Game automation can be a problem for online multiplayer games, giving players a competitive advantage. This could be countered by common sense; ask OP what game they are automating, and is it an online game? What is this script for, and what does it seem to do?

      Please revise the rule as it seems very unnecessary and harmful to people seeking help with innocent attempts at game automation.
×
×
  • Create New...