4 Gewinnt, aber wie auswerten lassen?

  • Hab mich mal aus langeweile daran gesetzt ein 4-Gewinnt zu schreiben, es läuft auch super...

    Aber ich hätte halt gerne das das Script selbstständig auswertet ob jemand gewonnen hat, hab aber überhaupt keine idee wie ich das machen kann...

    Vielleicht hat ja einer von euch ne Idee, oder kann mir eventuell helfen mein momentan vorhandenes Script zu überarbeiten...

    Main.au3

    Spoiler anzeigen
    [autoit]

    #include <funcs.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <array.au3>
    Dim $player = 1, $pica[10], $picb[10], $picc[10], $picd[10], $pice[10], $picf[10], $picg[10], $pich[10], $pici[10]
    Opt("GUIOnEventMode", 1)
    Global $Form1 = GUICreate("4-Gewinnt", 196, 196)
    GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
    #Region ;Trenner
    Local $i
    For $i=20 To 174 Step 22
    GUICtrlCreatePic(@ScriptDir & "\res\trenn.bmp", $i, 0, 2, 196)
    GUICtrlCreatePic(@ScriptDir & "\res\trenn.bmp", 0, $i, 196, 2)
    Next
    #EndRegion ;Trenner
    #Region ;Spalten
    Local $i, $j=1
    For $i=0 To 176 Step 22
    $pica[$j] = GUICtrlCreatePic(@ScriptDir & "\res\feld.bmp", 0, $i, 20, 20, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))
    GUICtrlSetOnEvent(-1, "spalte_a")
    $Picb[$j] = GUICtrlCreatePic(@ScriptDir & "\res\feld.bmp", 22, $i, 20, 20, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))
    GUICtrlSetOnEvent(-1, "spalte_b")
    $Picc[$j] = GUICtrlCreatePic(@ScriptDir & "\res\feld.bmp", 44, $i, 20, 20, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))
    GUICtrlSetOnEvent(-1, "spalte_c")
    $picd[$j] = GUICtrlCreatePic(@ScriptDir & "\res\feld.bmp", 66, $i, 20, 20, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))
    GUICtrlSetOnEvent(-1, "spalte_d")
    $Pice[$j] = GUICtrlCreatePic(@ScriptDir & "\res\feld.bmp", 88, $i, 20, 20, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))
    GUICtrlSetOnEvent(-1, "spalte_e")
    $Picf[$j] = GUICtrlCreatePic(@ScriptDir & "\res\feld.bmp", 110, $i, 20, 20, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))
    GUICtrlSetOnEvent(-1, "spalte_f")
    $picg[$j] = GUICtrlCreatePic(@ScriptDir & "\res\feld.bmp", 132, $i, 20, 20, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))
    GUICtrlSetOnEvent(-1, "spalte_g")
    $pich[$j] = GUICtrlCreatePic(@ScriptDir & "\res\feld.bmp", 154, $i, 20, 20, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))
    GUICtrlSetOnEvent(-1, "spalte_h")
    $pici[$j] = GUICtrlCreatePic(@ScriptDir & "\res\feld.bmp", 176, $i, 20, 20, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))
    GUICtrlSetOnEvent(-1, "spalte_i")
    $j=$j+1
    Next
    #EndRegion
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While 1
    Sleep(1)
    WEnd

    [/autoit]

    Funcs.au3

    Spoiler anzeigen
    [autoit]

    #Region ;Vars
    Dim $player
    ;~ Vars Spalte A
    Dim $pica[10], $aa[10], $a = 9
    ;~ Vars Spalte B
    Dim $picb[10], $ba[10], $b = 9
    ;~ Vars Spalte C
    Dim $picc[10], $ca[10], $c = 9
    ;~ Vars Spalte D
    Dim $picd[10], $da[10], $d = 9
    ;~ Vars Spalte E
    Dim $pice[10], $ea[10], $e = 9
    ;~ Vars Spalte F
    Dim $picf[10], $fa[10], $f = 9
    ;~ Vars Spalte G
    Dim $picg[10], $ga[10], $g = 9
    ;~ Vars Spalte H
    Dim $pich[10], $ha[10], $h = 9
    ;~ Vars Spalte I
    Dim $pici[10], $ia[10], $ii = 9
    #EndRegion ;Vars
    #Region ;Spalten Funcs
    Func spalte_a()
    If $a >= 1 Then ;wenn nicht alle felder belegt dann ->
    If $player = 1 Then
    GUICtrlSetImage($pica[$a], @ScriptDir & "\res\feld-blau.bmp")
    $player = 2
    $aa[$a] = 1
    $a = $a - 1
    Else
    GUICtrlSetImage($pica[$a], @ScriptDir & "\res\feld-rot.bmp")
    $player = 1
    $aa[$a] = 2
    $a = $a - 1
    EndIf
    EndIf
    auswerten()
    EndFunc ;==>spalte_a
    Func spalte_b()
    If $b >= 1 Then
    If $player = 1 Then
    GUICtrlSetImage($picb[$b], @ScriptDir & "\res\feld-blau.bmp")
    $b = $b - 1
    $player = 2
    $ba[$b] = 1
    Else
    GUICtrlSetImage($picb[$b], @ScriptDir & "\res\feld-rot.bmp")
    $b = $b - 1
    $player = 1
    $ba[$b] = 2
    EndIf
    EndIf
    EndFunc ;==>spalte_b
    Func spalte_c()
    If $c >= 1 Then
    If $player = 1 Then
    GUICtrlSetImage($picc[$c], @ScriptDir & "\res\feld-blau.bmp")
    $c = $c - 1
    $player = 2
    $ca[$c] = 1
    Else
    GUICtrlSetImage($picc[$c], @ScriptDir & "\res\feld-rot.bmp")
    $c = $c - 1
    $player = 1
    $ca[$c] = 2
    EndIf
    EndIf
    EndFunc ;==>spalte_c
    Func spalte_d()
    If $d >= 1 Then
    If $player = 1 Then
    GUICtrlSetImage($picd[$d], @ScriptDir & "\res\feld-blau.bmp")
    $d = $d - 1
    $player = 2
    $da[$d] = 1
    Else
    GUICtrlSetImage($picd[$d], @ScriptDir & "\res\feld-rot.bmp")
    $d = $d - 1
    $player = 1
    $da[$d] = 2
    EndIf
    EndIf
    EndFunc ;==>spalte_d
    Func spalte_e()
    If $e >= 1 Then
    If $player = 1 Then
    GUICtrlSetImage($pice[$e], @ScriptDir & "\res\feld-blau.bmp")
    $e = $e - 1
    $player = 2
    $ea[$e] = 1
    Else
    GUICtrlSetImage($pice[$e], @ScriptDir & "\res\feld-rot.bmp")
    $e = $e - 1
    $player = 1
    $ea[$e] = 2
    EndIf
    EndIf
    EndFunc ;==>spalte_e
    Func spalte_f()
    If $f >= 1 Then
    If $player = 1 Then
    GUICtrlSetImage($picf[$f], @ScriptDir & "\res\feld-blau.bmp")
    $f = $f - 1
    $player = 2
    $fa[$f] = 1
    Else
    GUICtrlSetImage($picf[$f], @ScriptDir & "\res\feld-rot.bmp")
    $f = $f - 1
    $player = 1
    $fa[$f] = 2
    EndIf
    EndIf
    EndFunc ;==>spalte_f
    Func spalte_g()
    If $g >= 1 Then
    If $player = 1 Then
    GUICtrlSetImage($picg[$g], @ScriptDir & "\res\feld-blau.bmp")
    $g = $g - 1
    $player = 2
    $ga[$g] = 1
    Else
    GUICtrlSetImage($picg[$g], @ScriptDir & "\res\feld-rot.bmp")
    $g = $g - 1
    $player = 1
    $ga[$g] = 2
    EndIf
    EndIf
    EndFunc ;==>spalte_g
    Func spalte_h()
    If $h >= 1 Then
    If $player = 1 Then
    GUICtrlSetImage($pich[$h], @ScriptDir & "\res\feld-blau.bmp")
    $h = $h - 1
    $player = 2
    $ha[$h] = 1
    Else
    GUICtrlSetImage($pich[$h], @ScriptDir & "\res\feld-rot.bmp")
    $h = $h - 1
    $player = 1
    $ha[$h] = 2
    EndIf
    EndIf
    EndFunc ;==>spalte_h
    Func spalte_i()
    If $ii >= 1 Then
    If $player = 1 Then
    GUICtrlSetImage($pici[$ii], @ScriptDir & "\res\feld-blau.bmp")
    $ii = $ii - 1
    $player = 2
    $ia[$ii] = 1
    Else
    GUICtrlSetImage($pici[$ii], @ScriptDir & "\res\feld-rot.bmp")
    $ii = $ii - 1
    $player = 1
    $ia[$ii] = 2
    EndIf
    EndIf
    EndFunc ;==>spalte_i
    #EndRegion ;Spalten Funcs
    #Region ;standard functions
    Func Form1Close()
    ;Info()
    Exit
    EndFunc ;==>Form1Close
    #EndRegion
    Func Info()
    _ArrayDisplay($aa) ;~ just for testing
    _ArrayDisplay($ba) ;~ just for testing
    _ArrayDisplay($ca) ;~ just for testing
    _ArrayDisplay($da) ;~ just for testing
    _ArrayDisplay($ea) ;~ just for testing
    _ArrayDisplay($fa) ;~ just for testing
    _ArrayDisplay($ga) ;~ just for testing
    _ArrayDisplay($ha) ;~ just for testing
    _ArrayDisplay($ia) ;~ just for testing
    EndFunc ;==>Info
    Func auswerten()
    EndFunc ;==>auswerten

    [/autoit]

    Für hilfreiche Tipps wäre ich sehr Dankbar!

    Grüßle AlkoholiX

    p.s. im Anhang die Source + die Resourcen autoit.de/wcf/attachment/4786/

  • Ich hab das in meiner Version so gelöst:
    - Nehme die letzte gesetzte Position
    - Teste auf waagrechten Gewinn
    - Teste auf senkrechten Gewinn
    - Teste Diagonale 1 auf Gewinn
    - Teste Diagonale 2 auf Gewinn

    Sobald hier einmal 4 oder mehr Steine eine Reihe bilden, hat der Spieler, der den letzten Stein gesetzt hat, gewonnen.

  • Ich hab das in meiner Version so gelöst:
    - Nehme die letzte gesetzte Position
    - Teste auf waagrechten Gewinn
    - Teste auf senkrechten Gewinn
    - Teste Diagonale 1 auf Gewinn
    - Teste Diagonale 2 auf Gewinn

    Sobald hier einmal 4 oder mehr Steine eine Reihe bilden, hat der Spieler, der den letzten Stein gesetzt hat, gewonnen.

    Finde deine Lösung ziemlich gut.

    _________________________________________________________
    Irgendwann werde auch ich die 6 Richtigen haben!