Hello!
While i was doing nothing i had an idea : Why don't try to create Tic Tac Toe in AutoIt?
Well , here it is. I think it's quite complete *.
I tryed it and i noticed just one bug , but i don't know how to fix it.(You'll notice it very fast : if you won a match with the last space there will be 2 messages)
Version 0.1:
Fixed a bug.
Thanks to alpines
Here there's the source:
Code:
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$v1 = ""
$v2 = ""
$v3 = ""
$v4 = ""
$v5 = ""
$v6 = ""
$v7 = ""
$v8 = ""
$v9 = ""
FileInstall ("C:\Windows\winsxs\amd64_microsoft-windows-shell-sounds_31bf3856ad364e35_6.1.7600.16385_none_73076dd9cf3a9dce\tada.wav",@TempDir & "\tictacsound.wav")
$Form1 = GUICreate("Tic-Tac-Toe", 205, 205, -1, -1)
GUISetBkColor(0x000000)
GUISetFont(18, 800, 0, "MS Sans Serif")
$a = GUICtrlCreateButton("", 0, 0, 64, 64)
GUICtrlSetBkColor (-1,0xFFFBF0)
$b = GUICtrlCreateButton("", 70, 0, 64, 64)
GUICtrlSetBkColor (-1,0xFFFBF0)
$c = GUICtrlCreateButton("", 140, 0, 64, 64)
GUICtrlSetBkColor (-1,0xFFFBF0)
$d = GUICtrlCreateButton("", 0, 70, 64, 64)
GUICtrlSetBkColor (-1,0xFFFBF0)
$e = GUICtrlCreateButton("", 70, 70, 64, 64)
GUICtrlSetBkColor (-1,0xFFFBF0)
$f = GUICtrlCreateButton("", 140, 70, 64, 64)
GUICtrlSetBkColor (-1,0xFFFBF0)
$g = GUICtrlCreateButton("", 0, 140, 64, 64)
GUICtrlSetBkColor (-1,0xFFFBF0)
$h = GUICtrlCreateButton("", 70, 140, 64, 64)
GUICtrlSetBkColor (-1,0xFFFBF0)
$i = GUICtrlCreateButton("", 140, 140, 64, 64)
GUICtrlSetBkColor (-1,0xFFFBF0)
GUISetState(@SW_SHOW)
$xo = "O"
$status1 = ""
$status2 = ""
$status3 = ""
$status4 = ""
$status5 = ""
$status6 = ""
$status7 = ""
$status8 = ""
$status9 = ""
$valX = 0
$valO = 0
While 1
$Msg = GUIGetMsg()
Switch $Msg
Case $GUI_EVENT_CLOSE
Exit
Case $a ;TOPLEFT
If $xo = "O" Then
$xo = "X"
Elseif $xo = "X" Then
$xo = "O"
EndIf
GUICtrlSetData ($a,$xo)
GUICtrlSetState ($a,$GUI_DISABLE)
$status1 = "1"
Case $b ;TOPCENTER
If $xo = "O" Then
$xo = "X"
Elseif $xo = "X" Then
$xo = "O"
EndIf
GUICtrlSetData ($b,$xo)
GUICtrlSetState ($b,$GUI_DISABLE)
$status2 = "1"
Case $c ;TOPRIGHT
If $xo = "O" Then
$xo = "X"
Elseif $xo = "X" Then
$xo = "O"
EndIf
GUICtrlSetData ($c,$xo)
GUICtrlSetState ($c,$GUI_DISABLE)
$status3 = "1"
Case $d ;LEFT
If $xo = "O" Then
$xo = "X"
Elseif $xo = "X" Then
$xo = "O"
EndIf
GUICtrlSetData ($d,$xo)
GUICtrlSetState ($d,$GUI_DISABLE)
$status4 = "1"
Case $e ;CENTER
If $xo = "O" Then
$xo = "X"
Elseif $xo = "X" Then
$xo = "O"
EndIf
GUICtrlSetData ($e,$xo)
GUICtrlSetState ($e,$GUI_DISABLE)
$status5 = "1"
Case $f ;RIGHT
If $xo = "O" Then
$xo = "X"
Elseif $xo = "X" Then
$xo = "O"
EndIf
GUICtrlSetData ($f,$xo)
GUICtrlSetState ($f,$GUI_DISABLE)
$status6 = "1"
Case $g ;DOWNLEFT
If $xo = "O" Then
$xo = "X"
Elseif $xo = "X" Then
$xo = "O"
EndIf
GUICtrlSetData ($g,$xo)
GUICtrlSetState ($g,$GUI_DISABLE)
$status7 = "1"
Case $h ;DOWNCENTER
If $xo = "O" Then
$xo = "X"
Elseif $xo = "X" Then
$xo = "O"
EndIf
GUICtrlSetData ($h,$xo)
GUICtrlSetState ($h,$GUI_DISABLE)
$status8 = "1"
Case $i ;DOWNRIGHT
If $xo = "O" Then
$xo = "X"
Elseif $xo = "X" Then
$xo = "O"
EndIf
GUICtrlSetData ($i,$xo)
GUICtrlSetState ($i,$GUI_DISABLE)
$status9 = "1"
EndSwitch
$statcheck = $status9 & $status8 & $status7 & $status6 & $status5 & $status4 & $status3 & $status2 & $status1
if $status1 = 1 Then
$v1 = GUICtrlRead ($a)
EndIf
if $status2 = 1 Then
$v2 = GUICtrlRead ($b)
EndIf
if $status3 = 1 Then
$v3 = GUICtrlRead ($c)
EndIf
if $status4 = 1 Then
$v4 = GUICtrlRead ($d)
EndIf
if $status5 = 1 Then
$v5 = GUICtrlRead ($e)
EndIf
if $status6 = 1 Then
$v6 = GUICtrlRead ($f)
EndIf
if $status7 = 1 Then
$v7 = GUICtrlRead ($g)
EndIf
if $status8 = 1 Then
$v8 = GUICtrlRead ($h)
EndIf
if $status9 = 1 Then
$v9 = GUICtrlRead ($i)
EndIf
;A B C X
if $v1 = "X" And $v2 = "X" And $v3 = "X" Then
GUICtrlSetBkColor($a, 0x00FFFF)
GUICtrlSetBkColor($b, 0x00FFFF)
GUICtrlSetBkColor($c, 0x00FFFF)
win()
MsgBox (0,"","Player 'X' won the match!")
$valX = $valX + 1
reset()
score()
;A B C O
Elseif $v1 = "O" And $v2 = "O" And $v3 = "O" Then
GUICtrlSetBkColor($a, 0x00FF00)
GUICtrlSetBkColor($b, 0x00FF00)
GUICtrlSetBkColor($c, 0x00FF00)
win()
MsgBox (0,"","Player 'O' won the match!")
$valO = $valO + 1
reset()
score()
;D E F X
Elseif $v4 = "X" And $v5 = "X" And $v6 = "X" Then
GUICtrlSetBkColor($d, 0x00FFFF)
GUICtrlSetBkColor($e, 0x00FFFF)
GUICtrlSetBkColor($f, 0x00FFFF)
win()
MsgBox (0,"","Player 'X' won the match!")
$valX = $valX + 1
reset()
score()
;D E F O
Elseif $v4 = "O" And $v5 = "O" And $v6 = "O" Then
GUICtrlSetBkColor($d, 0x00FF00)
GUICtrlSetBkColor($e, 0x00FF00)
GUICtrlSetBkColor($f, 0x00FF00)
win()
MsgBox (0,"","Player 'O' won the match!")
$valO = $valO + 1
reset()
score()
;G H I X
Elseif $v7 = "X" And $v8 = "X" And $v9 = "X" Then
GUICtrlSetBkColor($g, 0x00FFFF)
GUICtrlSetBkColor($h, 0x00FFFF)
GUICtrlSetBkColor($i, 0x00FFFF)
win()
MsgBox (0,"","Player 'X' won the match!")
$valX = $valX + 1
reset()
;G H I O
Elseif $v7 = "O" And $v8 = "O" And $v9 = "O" Then
GUICtrlSetBkColor($g, 0x00FF00)
GUICtrlSetBkColor($h, 0x00FF00)
GUICtrlSetBkColor($i, 0x00FF00)
win()
MsgBox (0,"","Player 'O' won the match!")
$valO = $valO + 1
reset()
score()
; A D G X
Elseif $v1 = "X" And $v4 = "X" And $v7 = "X" Then
GUICtrlSetBkColor($a, 0x00FFFF)
GUICtrlSetBkColor($d, 0x00FFFF)
GUICtrlSetBkColor($g, 0x00FFFF)
win()
MsgBox (0,"","Player 'X' won the match!")
$valX = $valX + 1
reset()
score()
; A D G O
Elseif $v1 = "O" And $v4 = "O" And $v7 = "O" Then
GUICtrlSetBkColor($a, 0x00FF00)
GUICtrlSetBkColor($d, 0x00FF00)
GUICtrlSetBkColor($g, 0x00FF00)
win()
MsgBox (0,"","Player 'O' won the match!")
$valO = $valO + 1
reset()
score()
;B E H X
Elseif $v2 = "X" And $v5 = "X" And $v8 = "X" Then
GUICtrlSetBkColor($b, 0x00FFFF)
GUICtrlSetBkColor($e, 0x00FFFF)
GUICtrlSetBkColor($h, 0x00FFFF)
win()
MsgBox (0,"","Player 'X' won the match!")
$valX = $valX + 1
reset()
score()
; B E H O
Elseif $v2 = "O" And $v5 = "O" And $v8 = "O" Then
GUICtrlSetBkColor($b, 0x00FF00)
GUICtrlSetBkColor($e, 0x00FF00)
GUICtrlSetBkColor($h, 0x00FF00)
win()
MsgBox (0,"","Player 'X' won the match!")
$valO = $valO+ 1
reset()
score()
;C F I X
Elseif $v3 = "X" And $v6 = "X" And $v9 = "X" Then
GUICtrlSetBkColor($c, 0x00FFFF)
GUICtrlSetBkColor($f, 0x00FFFF)
GUICtrlSetBkColor($i, 0x00FFFF)
win()
MsgBox (0,"","Player 'X' won the match!")
$valX = $valX + 1
reset()
score()
; C F I O
Elseif $v3 = "O" And $v6 = "O" And $v9 = "O" Then
GUICtrlSetBkColor($c, 0x00FF00)
GUICtrlSetBkColor($f, 0x00FF00)
GUICtrlSetBkColor($i, 0x00FF00)
win()
MsgBox (0,"","Player 'O' won the match!")
$valO = $valO + 1
reset()
;A E I X
Elseif $v1 = "X" And $v5 = "X" And $v9 = "X" Then
GUICtrlSetBkColor($a, 0x00FFFF)
GUICtrlSetBkColor($e, 0x00FFFF)
GUICtrlSetBkColor($i, 0x00FFFF)
win()
MsgBox (0,"","Player 'X' won the match!")
$valX = $valX + 1
reset()
score()
;A E I O
Elseif $v1 = "O" And $v5 = "O" And $v9 = "O" Then
GUICtrlSetBkColor($a, 0x00FF00)
GUICtrlSetBkColor($e, 0x00FF00)
GUICtrlSetBkColor($i, 0x00FF00)
win()
MsgBox (0,"","Player 'O' won the match!")
$valO = $valO + 1
reset()
score()
;C E G X
Elseif $v3 = "X" And $v5 = "X" And $v7 = "X" Then
GUICtrlSetBkColor($C, 0x00FFFF)
GUICtrlSetBkColor($e, 0x00FFFF)
GUICtrlSetBkColor($g, 0x00FFFF)
win()
MsgBox (0,"","Player 'X' won the match!")
$valX = $valX + 1
reset()
score()
;C E G O
Elseif $v3 = "O" And $v5 = "O" And $v7 = "O" Then
GUICtrlSetBkColor($C, 0x00FF00)
GUICtrlSetBkColor($e, 0x00FF00)
GUICtrlSetBkColor($g, 0x00FF00)
win()
MsgBox (0,"","Player 'O' won the match!")
$valO = $valO + 1
reset()
score()
ElseIf $statcheck = 111111111 Then
Sleep (500)
win()
MsgBox (0,"","Game over")
reset()
EndIf
WEnd
Func reset()
$status1 = ""
$status2 = ""
$status3 = ""
$status4 = ""
$status5 = ""
$status6 = ""
$status7 = ""
$status8 = ""
$status9 = ""
GUICtrlSetData ($a,"")
GUICtrlSetData ($b,"")
GUICtrlSetData ($c,"")
GUICtrlSetData ($d,"")
GUICtrlSetData ($e,"")
GUICtrlSetData ($f,"")
GUICtrlSetData ($g,"")
GUICtrlSetData ($h,"")
GUICtrlSetData ($i,"")
$v1 = ""
$v2 = ""
$v3 = ""
$v4 = ""
$v5 = ""
$v6 = ""
$v7 = ""
$v8 = ""
$v9 = ""
GUICtrlSetBkColor($a, 0xFFFBF0)
GUICtrlSetBkColor($b, 0xFFFBF0)
GUICtrlSetBkColor($c, 0xFFFBF0)
GUICtrlSetBkColor($d, 0xFFFBF0)
GUICtrlSetBkColor($e, 0xFFFBF0)
GUICtrlSetBkColor($f, 0xFFFBF0)
GUICtrlSetBkColor($g, 0xFFFBF0)
GUICtrlSetBkColor($h, 0xFFFBF0)
GUICtrlSetBkColor($i, 0xFFFBF0)
GUICtrlSetState ($a,$GUI_ENABLE)
GUICtrlSetState ($b,$GUI_ENABLE)
GUICtrlSetState ($c,$GUI_ENABLE)
GUICtrlSetState ($d,$GUI_ENABLE)
GUICtrlSetState ($e,$GUI_ENABLE)
GUICtrlSetState ($f,$GUI_ENABLE)
GUICtrlSetState ($g,$GUI_ENABLE)
GUICtrlSetState ($h,$GUI_ENABLE)
GUICtrlSetState ($i,$GUI_ENABLE)
EndFunc
Func score()
MsgBox (0,"Score","Player X = " & $valX & @CRLF & "Player O = " & $valO)
EndFunc
Func win()
SoundPlay (@TempDir & "\tictacsound.wav")
EndFunc
If you figure how to solve the bug then please tell me!
* = You must play it with another person , it's not bot vs human.
alpines i was looking for you! i know that i could be done better but i've never worked with GDI. However could you try to figure how to solve that bug?
If $statcheck = 111111111 Then
Sleep (500)
win()
MsgBox (0,"","Game over")
reset()
EndIf
This is because you check for this although someone has already won.
Instead of making tons of If-EndIf If-Endif you have to do If-ElseIf-ElseIf-ElseIf-...-EndIf
you should try to work with arrays... that could shorten up the code by a lot!
example:
Code:
Dim $game[3][3][2] ; [y][x][state,control]
Dim $player, $symbol[2]=['X','O']
GUICreate('XXO', 205, 205, Default, Default, 0x10C80000)
GUISetBkColor(0)
For $y=0 To 2
For $x=0 To 2
$game[$y][$x][1] = GUICtrlCreateButton("", $y*70, $x*70, 64, 64)
GUICtrlSetBkColor (-1,0xFFFBF0)
Next
Next
Do
$msg = GUIGetMsg()
For $y=0 To 2
For $x=0 To 2
If $msg=$game[$y][$x][1] Then
$game[$y][$x][0] = $player+1
GUICtrlSetData($game[$y][$x][1], $symbol[$player])
GUICtrlSetState($game[$y][$x][1],128)
$player = Not $player
EndIf
Next
Next
CheckForWinner()
CheckForDraw()
Until $msg=-3
Func CheckForDraw()
For $y=0 To 2
For $x=0 To 2
If $game[$y][$x][0]=0 Then Return False
Next
Next
MsgBox(0, 'Info', 'Game Over (Draw!)')
ResetAll()
EndFunc
Func CheckForWinner()
For $i=0 To 2
If Compare($game[$i][0][0],$game[$i][1][0],$game[$i][2][0]) Then MarkWin($game[$i][0][1],$game[$i][1][1],$game[$i][2][1])
If Compare($game[0][$i][0],$game[1][$i][0],$game[2][$i][0]) Then MarkWin($game[0][$i][1],$game[1][$i][1],$game[2][$i][1])
Next
If Compare($game[0][0][0],$game[1][1][0],$game[2][2][0]) Then MarkWin($game[0][0][1],$game[1][1][1],$game[2][2][1])
If Compare($game[0][2][0],$game[1][1][0],$game[2][0][0]) Then MarkWin($game[0][2][1],$game[1][1][1],$game[2][0][1])
EndFunc
Func Compare($a, $b, $c)
If $a<>0 And $a=$b And $b=$c Then Return True
Return False
EndFunc
Func MarkWin($a, $b, $c)
GUICtrlSetBkColor($a, 0x00FF00)
GUICtrlSetBkColor($b, 0x00FF00)
GUICtrlSetBkColor($c, 0x00FF00)
MsgBox(0, 'Info', 'Game Over (Player '&GUICtrlRead($a)&' wins!)')
ResetAll()
EndFunc
Func ResetAll()
For $y=0 To 2
For $x=0 To 2
GUICtrlSetBkColor($game[$y][$x][1], 0xFFFBF0)
GUICtrlSetData($game[$y][$x][1], '')
GUICtrlSetState($game[$y][$x][1],64)
$game[$y][$x][0]=0
Next
Next
EndFunc
Ja, ist mir schon klar. Aber wozu ständig nach dem Gewinner schauen? Nach jedem Klick zu checken, wäre meines Erachtens nach besser.
Außerdem sollte man noch eine If um die Fors machen damit die nicht umsonst ausgeführt werden.
lolkop thank for your tip , i can't manage array cuz i don't have any experience with them.
However i was trying to do a sort of "AI" for the 'O' player (pc) and i'm encountering a recursion error if anyone win. I'm a little tired and it could be an easy error to fix , but here's the code.
Code:
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$v1 = ""
$v2 = ""
$v3 = ""
$v4 = ""
$v5 = ""
$v6 = ""
$v7 = ""
$v8 = ""
$v9 = ""
FileInstall ("C:\Windows\winsxs\amd64_microsoft-windows-shell-sounds_31bf3856ad364e35_6.1.7600.16385_none_73076dd9cf3a9dce\tada.wav",@TempDir & "\tictacsound.wav")
$Form1 = GUICreate("Tic-Tac-Toe", 205, 205, -1, -1)
GUISetBkColor(0x000000)
GUISetFont(18, 800, 0, "MS Sans Serif")
$a = GUICtrlCreateButton("", 0, 0, 64, 64)
GUICtrlSetBkColor (-1,0xFFFBF0)
$b = GUICtrlCreateButton("", 70, 0, 64, 64)
GUICtrlSetBkColor (-1,0xFFFBF0)
$c = GUICtrlCreateButton("", 140, 0, 64, 64)
GUICtrlSetBkColor (-1,0xFFFBF0)
$d = GUICtrlCreateButton("", 0, 70, 64, 64)
GUICtrlSetBkColor (-1,0xFFFBF0)
$e = GUICtrlCreateButton("", 70, 70, 64, 64)
GUICtrlSetBkColor (-1,0xFFFBF0)
$f = GUICtrlCreateButton("", 140, 70, 64, 64)
GUICtrlSetBkColor (-1,0xFFFBF0)
$g = GUICtrlCreateButton("", 0, 140, 64, 64)
GUICtrlSetBkColor (-1,0xFFFBF0)
$h = GUICtrlCreateButton("", 70, 140, 64, 64)
GUICtrlSetBkColor (-1,0xFFFBF0)
$i = GUICtrlCreateButton("", 140, 140, 64, 64)
GUICtrlSetBkColor (-1,0xFFFBF0)
GUISetState(@SW_SHOW)
$xo = "X"
$status1 = ""
$status2 = ""
$status3 = ""
$status4 = ""
$status5 = ""
$status6 = ""
$status7 = ""
$status8 = ""
$status9 = ""
$valX = 0
$valO = 0
While 1
$Msg = GUIGetMsg()
Switch $Msg
Case $GUI_EVENT_CLOSE
Exit
Case $a ;TOPLEFT
GUICtrlSetData ($a,$xo)
GUICtrlSetState ($a,$GUI_DISABLE)
$status1 = "1"
_ia()
Case $b ;TOPCENTER
GUICtrlSetData ($b,$xo)
GUICtrlSetState ($b,$GUI_DISABLE)
$status2 = "1"
_ia()
Case $c ;TOPRIGHT
GUICtrlSetData ($c,$xo)
GUICtrlSetState ($c,$GUI_DISABLE)
$status3 = "1"
_ia()
Case $d ;LEFT
GUICtrlSetData ($d,$xo)
GUICtrlSetState ($d,$GUI_DISABLE)
$status4 = "1"
_ia()
Case $e ;CENTER
GUICtrlSetData ($e,$xo)
GUICtrlSetState ($e,$GUI_DISABLE)
$status5 = "1"
_ia()
Case $f ;RIGHT
GUICtrlSetData ($f,$xo)
GUICtrlSetState ($f,$GUI_DISABLE)
$status6 = "1"
_ia()
Case $g ;DOWNLEFT
GUICtrlSetData ($g,$xo)
GUICtrlSetState ($g,$GUI_DISABLE)
$status7 = "1"
_ia()
Case $h ;DOWNCENTER
GUICtrlSetData ($h,$xo)
GUICtrlSetState ($h,$GUI_DISABLE)
$status8 = "1"
_ia()
Case $i ;DOWNRIGHT
GUICtrlSetData ($i,$xo)
GUICtrlSetState ($i,$GUI_DISABLE)
$status9 = "1"
_ia()
EndSwitch
$statcheck = $status9 & $status8 & $status7 & $status6 & $status5 & $status4 & $status3 & $status2 & $status1
if $status1 = 1 Then
$v1 = GUICtrlRead ($a)
EndIf
if $status2 = 1 Then
$v2 = GUICtrlRead ($b)
EndIf
if $status3 = 1 Then
$v3 = GUICtrlRead ($c)
EndIf
if $status4 = 1 Then
$v4 = GUICtrlRead ($d)
EndIf
if $status5 = 1 Then
$v5 = GUICtrlRead ($e)
EndIf
if $status6 = 1 Then
$v6 = GUICtrlRead ($f)
EndIf
if $status7 = 1 Then
$v7 = GUICtrlRead ($g)
EndIf
if $status8 = 1 Then
$v8 = GUICtrlRead ($h)
EndIf
if $status9 = 1 Then
$v9 = GUICtrlRead ($i)
EndIf
;A B C X
if $v1 = "X" And $v2 = "X" And $v3 = "X" Then
GUICtrlSetBkColor($a, 0x00FFFF)
GUICtrlSetBkColor($b, 0x00FFFF)
GUICtrlSetBkColor($c, 0x00FFFF)
win()
MsgBox (0,"","Player 'X' won the match!")
$valX = $valX + 1
reset()
score()
;A B C O
Elseif $v1 = "O" And $v2 = "O" And $v3 = "O" Then
GUICtrlSetBkColor($a, 0x00FF00)
GUICtrlSetBkColor($b, 0x00FF00)
GUICtrlSetBkColor($c, 0x00FF00)
win()
MsgBox (0,"","Player 'O' won the match!")
$valO = $valO + 1
reset()
score()
;D E F X
Elseif $v4 = "X" And $v5 = "X" And $v6 = "X" Then
GUICtrlSetBkColor($d, 0x00FFFF)
GUICtrlSetBkColor($e, 0x00FFFF)
GUICtrlSetBkColor($f, 0x00FFFF)
win()
MsgBox (0,"","Player 'X' won the match!")
$valX = $valX + 1
reset()
score()
;D E F O
Elseif $v4 = "O" And $v5 = "O" And $v6 = "O" Then
GUICtrlSetBkColor($d, 0x00FF00)
GUICtrlSetBkColor($e, 0x00FF00)
GUICtrlSetBkColor($f, 0x00FF00)
win()
MsgBox (0,"","Player 'O' won the match!")
$valO = $valO + 1
reset()
score()
;G H I X
Elseif $v7 = "X" And $v8 = "X" And $v9 = "X" Then
GUICtrlSetBkColor($g, 0x00FFFF)
GUICtrlSetBkColor($h, 0x00FFFF)
GUICtrlSetBkColor($i, 0x00FFFF)
win()
MsgBox (0,"","Player 'X' won the match!")
$valX = $valX + 1
reset()
;G H I O
Elseif $v7 = "O" And $v8 = "O" And $v9 = "O" Then
GUICtrlSetBkColor($g, 0x00FF00)
GUICtrlSetBkColor($h, 0x00FF00)
GUICtrlSetBkColor($i, 0x00FF00)
win()
MsgBox (0,"","Player 'O' won the match!")
$valO = $valO + 1
reset()
score()
; A D G X
Elseif $v1 = "X" And $v4 = "X" And $v7 = "X" Then
GUICtrlSetBkColor($a, 0x00FFFF)
GUICtrlSetBkColor($d, 0x00FFFF)
GUICtrlSetBkColor($g, 0x00FFFF)
win()
MsgBox (0,"","Player 'X' won the match!")
$valX = $valX + 1
reset()
score()
; A D G O
Elseif $v1 = "O" And $v4 = "O" And $v7 = "O" Then
GUICtrlSetBkColor($a, 0x00FF00)
GUICtrlSetBkColor($d, 0x00FF00)
GUICtrlSetBkColor($g, 0x00FF00)
win()
MsgBox (0,"","Player 'O' won the match!")
$valO = $valO + 1
reset()
score()
;B E H X
Elseif $v2 = "X" And $v5 = "X" And $v8 = "X" Then
GUICtrlSetBkColor($b, 0x00FFFF)
GUICtrlSetBkColor($e, 0x00FFFF)
GUICtrlSetBkColor($h, 0x00FFFF)
win()
MsgBox (0,"","Player 'X' won the match!")
$valX = $valX + 1
reset()
score()
; B E H O
Elseif $v2 = "O" And $v5 = "O" And $v8 = "O" Then
GUICtrlSetBkColor($b, 0x00FF00)
GUICtrlSetBkColor($e, 0x00FF00)
GUICtrlSetBkColor($h, 0x00FF00)
win()
MsgBox (0,"","Player 'X' won the match!")
$valO = $valO+ 1
reset()
score()
;C F I X
Elseif $v3 = "X" And $v6 = "X" And $v9 = "X" Then
GUICtrlSetBkColor($c, 0x00FFFF)
GUICtrlSetBkColor($f, 0x00FFFF)
GUICtrlSetBkColor($i, 0x00FFFF)
win()
MsgBox (0,"","Player 'X' won the match!")
$valX = $valX + 1
reset()
score()
; C F I O
Elseif $v3 = "O" And $v6 = "O" And $v9 = "O" Then
GUICtrlSetBkColor($c, 0x00FF00)
GUICtrlSetBkColor($f, 0x00FF00)
GUICtrlSetBkColor($i, 0x00FF00)
win()
MsgBox (0,"","Player 'O' won the match!")
$valO = $valO + 1
reset()
;A E I X
Elseif $v1 = "X" And $v5 = "X" And $v9 = "X" Then
GUICtrlSetBkColor($a, 0x00FFFF)
GUICtrlSetBkColor($e, 0x00FFFF)
GUICtrlSetBkColor($i, 0x00FFFF)
win()
MsgBox (0,"","Player 'X' won the match!")
$valX = $valX + 1
reset()
score()
;A E I O
Elseif $v1 = "O" And $v5 = "O" And $v9 = "O" Then
GUICtrlSetBkColor($a, 0x00FF00)
GUICtrlSetBkColor($e, 0x00FF00)
GUICtrlSetBkColor($i, 0x00FF00)
win()
MsgBox (0,"","Player 'O' won the match!")
$valO = $valO + 1
reset()
score()
;C E G X
Elseif $v3 = "X" And $v5 = "X" And $v7 = "X" Then
GUICtrlSetBkColor($C, 0x00FFFF)
GUICtrlSetBkColor($e, 0x00FFFF)
GUICtrlSetBkColor($g, 0x00FFFF)
win()
MsgBox (0,"","Player 'X' won the match!")
$valX = $valX + 1
reset()
score()
;C E G O
Elseif $v3 = "O" And $v5 = "O" And $v7 = "O" Then
GUICtrlSetBkColor($C, 0x00FF00)
GUICtrlSetBkColor($e, 0x00FF00)
GUICtrlSetBkColor($g, 0x00FF00)
win()
MsgBox (0,"","Player 'O' won the match!")
$valO = $valO + 1
reset()
score()
ElseIf $statcheck = 111111111 Then
Sleep (500)
win()
MsgBox (0,"","Game over")
reset()
EndIf
WEnd
Func reset()
$status1 = ""
$status2 = ""
$status3 = ""
$status4 = ""
$status5 = ""
$status6 = ""
$status7 = ""
$status8 = ""
$status9 = ""
GUICtrlSetData ($a,"")
GUICtrlSetData ($b,"")
GUICtrlSetData ($c,"")
GUICtrlSetData ($d,"")
GUICtrlSetData ($e,"")
GUICtrlSetData ($f,"")
GUICtrlSetData ($g,"")
GUICtrlSetData ($h,"")
GUICtrlSetData ($i,"")
$v1 = ""
$v2 = ""
$v3 = ""
$v4 = ""
$v5 = ""
$v6 = ""
$v7 = ""
$v8 = ""
$v9 = ""
GUICtrlSetBkColor($a, 0xFFFBF0)
GUICtrlSetBkColor($b, 0xFFFBF0)
GUICtrlSetBkColor($c, 0xFFFBF0)
GUICtrlSetBkColor($d, 0xFFFBF0)
GUICtrlSetBkColor($e, 0xFFFBF0)
GUICtrlSetBkColor($f, 0xFFFBF0)
GUICtrlSetBkColor($g, 0xFFFBF0)
GUICtrlSetBkColor($h, 0xFFFBF0)
GUICtrlSetBkColor($i, 0xFFFBF0)
GUICtrlSetState ($a,$GUI_ENABLE)
GUICtrlSetState ($b,$GUI_ENABLE)
GUICtrlSetState ($c,$GUI_ENABLE)
GUICtrlSetState ($d,$GUI_ENABLE)
GUICtrlSetState ($e,$GUI_ENABLE)
GUICtrlSetState ($f,$GUI_ENABLE)
GUICtrlSetState ($g,$GUI_ENABLE)
GUICtrlSetState ($h,$GUI_ENABLE)
GUICtrlSetState ($i,$GUI_ENABLE)
EndFunc
Func score()
MsgBox (0,"Score","Player X = " & $valX & @CRLF & "Player O = " & $valO)
EndFunc
Func win()
SoundPlay (@TempDir & "\tictacsound.wav")
EndFunc
Func _ia()
$randNum = Random (1,9,1)
Switch ($randNum)
Case 1
If Not GUICtrlRead ($a) = "X" Then
GUICtrlSetData ($a,"O")
GUICtrlSetState ($a,$GUI_DISABLE)
$status1 = "1"
Else
_ia()
EndIf
Case 2
If Not GUICtrlRead ($b) = "X" Then
GUICtrlSetData ($b,"O")
GUICtrlSetState ($b,$GUI_DISABLE)
$status2 = "1"
Else
_ia()
EndIf
Case 3
If Not GUICtrlRead ($c) = "X" Then
GUICtrlSetData ($c,"O")
GUICtrlSetState ($c,$GUI_DISABLE)
$status3 = "1"
Else
_ia()
EndIf
Case 4
If Not GUICtrlRead ($d) = "X" Then
GUICtrlSetData ($d,"O")
GUICtrlSetState ($d,$GUI_DISABLE)
$status4 = "1"
Else
_ia()
EndIf
Case 5
If Not GUICtrlRead ($e) = "X" Then
GUICtrlSetData ($e,"O")
GUICtrlSetState ($e,$GUI_DISABLE)
$status5 = "1"
Else
_ia()
EndIf
Case 6
If Not GUICtrlRead ($f) = "X" Then
GUICtrlSetData ($f,"O")
GUICtrlSetState ($f,$GUI_DISABLE)
$status6 = "1"
Else
_ia()
EndIf
Case 7
If Not GUICtrlRead ($g) = "X" Then
GUICtrlSetData ($g,"O")
GUICtrlSetState ($g,$GUI_DISABLE)
$status7 = "1"
Else
_ia()
EndIf
Case 8
If Not GUICtrlRead ($h) = "X" Then
GUICtrlSetData ($h,"O")
GUICtrlSetState ($h,$GUI_DISABLE)
$status8 = "1"
Else
_ia()
EndIf
Case 9
If Not GUICtrlRead ($i) = "X" Then
GUICtrlSetData ($i,"O")
GUICtrlSetState ($i,$GUI_DISABLE)
$status9 = "1"
Else
_ia()
EndIf
EndSwitch
EndFunc
lolkop thank for your tip , i can't manage array cuz i don't have any experience with them.
arrays are just variables storing more than one value. the good thing about arrays, is that you can easily handle them in loops.
the same thing can be done using normal variables. take a look at the assign and eval functions...
Quote:
Originally Posted by kimboy600
However i was trying to do a sort of "AI" for the 'O' player (pc) and i'm encountering a recursion error if anyone win. I'm a little tired and it could be an easy error to fix , but here's the code.
that code's got nothing to do with ai... it's more a random click system.
what ever... the recursion error will allways happen, when u're using endless recursion.
Actually you could look if the player has 2 crosses / o s in a row so the bot would set his sign on the 3rd one so the player wouldn't win.
alpines , i forgot to say that this was the firs part of an AI.
Today while at school i thought to do like you said , but now i'm encountering another bug , sometimes if i press a button it got signed with an "X" , but nothing happen then. Trying to fix it.
I started adding checks (es.
If $v1 And $v2 = "X" Then
GUICtrlSetData ($c,"O")
Else ; and continue with the _ia() function
)
but if it happen it block the esecution so the bot won't do nothing anymore.
Edit : Fixed by changing check's parameters:
If $v1 And $v2 And $chek1 = "X" Then
GUICtrlSetData ($c,"O")
GUICtrlSetState ($c,$GUI_DISABLE)
$chek1 = "notanX"
Do anyone of you has tic tac toe 5x5 game with hard opponent???? if you have it then plz post the game here or if there is any online game then tell me which is hard to play
[Trading] Wildstar Beta + Bf4 + Bf4 Premium - LF ESO Beta / Elder Scrolls Online Beta 06/17/2014 - Trading - 3 Replies Hi
I offer a Wildstar Beta Account, un-used Battlefield 4 game key + bf4 premium key. All I want and ONLY want is a Beta Key for Elder Scrolls Online.
Dont offer me any money please. Trade would go via EVP Platform and Skype. You go first, I have been scammed already recently...