JellyFish666 Posted June 1, 2008 Share Posted June 1, 2008 (edited) I am really impressed I made it this far with my coding, but got some Errors, please help. It's Strip Tic Tac Toe so i won't post the images but if you can fix the script that would be great. I can fix the computers bot skills on my own but help would be great my main problem is... - Title "Wins come back as False for some reason but Loses work fine" - I go to tell the bot some how if the spot has already been played. - I got to find away if there is no more moves because this isn't working. If Not GUICtrlRead($Square[1][1]) = "" And GUICtrlRead($Square[1][2]) = "" And GUICtrlRead($Square[1][3]) = "" And GUICtrlRead($Square[2][1]) = "" And GUICtrlRead($Square[2][2]) = "" And GUICtrlRead($Square[2][3]) = "" And GUICtrlRead($Square[3][1]) = "" And GUICtrlRead($Square[3][2]) = "" And GUICtrlRead($Square[3][3]) = "" Then _ClearBoard(3) will mean a lot if someone helps me, the Strip part of the game is to keep me motivated if I actually finish this with some help ill put friendly images and post this with the examples. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $WinZ = 0 , $Loses = 0 , $Tied = 0 , $SS_REALSIZEIMAGE , $Babe = 1 , $Square[99][99] , $Resource = @ScriptDir & "\Resource\" $A1 = False $A2 = False $A3 = False $B1 = False $B2 = False $B3 = False $C1 = False $C2 = False $C3 = False $GUI = GUICreate("Wins " & $WinZ & " Loses " & $Loses & " Tied " & $Tied, 1056, 606) GUISetBkColor(0x000000) $Board = GUICtrlCreatePic($Resource & "Pictures\Board.bmp", 450 , 0, 606, 606, $SS_REALSIZEIMAGE) $Square[1][1] = GUICtrlCreateButton("", 460, 10, 180, 180, 0) $Square[1][2] = GUICtrlCreateButton("", 660, 10, 180, 180, 0) $Square[1][3] = GUICtrlCreateButton("", 860, 10 , 180, 180, 0) $Square[2][1] = GUICtrlCreateButton("", 460, 210, 180, 180, 0) $Square[2][2] = GUICtrlCreateButton("", 660, 210, 180, 180, 0) $Square[2][3] = GUICtrlCreateButton("", 860, 210, 180, 180, 0) $Square[3][1] = GUICtrlCreateButton("", 460, 410, 180, 180, 0) $Square[3][2] = GUICtrlCreateButton("", 660, 410, 180, 180, 0) $Square[3][3] = GUICtrlCreateButton("", 860, 410, 180, 180, 0) $Strip = GUICtrlCreatePic($Resource & "Pictures\1.bmp", 0 , 0, 450, 600, $SS_REALSIZEIMAGE) GUISetState(@SW_SHOW) While 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE Exit Case $Square[1][1] _Win() $A1 = True _Block(1 , $Square[1][1]) Case $Square[1][2] _Win() $A2 = True _Block(1 , $Square[1][2]) Case $Square[1][3] _Win() $A3 = True _Block(1 , $Square[1][3]) Case $Square[2][1] _Win() $B1 = True _Block(1 , $Square[2][1]) Case $Square[2][2] _Win() $B2 = True _Block(1 , $Square[2][2]) Case $Square[2][3] _Win() $B3 = True _Block(1 , $Square[2][3]) Case $Square[3][1] _Win() $C1 = True _Block(1 , $Square[3][1]) Case $Square[3][2] _Win() $C2 = True _Block(1 , $Square[3][2]) Case $Square[3][3] _Win() $C3 = True _Block(1 , $Square[3][3]) EndSwitch _Win() WEnd Func _Babe() If $Babe = 23 Then $Babe = 1 GUICtrlDelete($Strip) $Strip = GUICtrlCreatePic($Resource & "Pictures\" & $Babe & ".bmp", 0 , 0, 450, 600, $SS_REALSIZEIMAGE) SoundPlay($Resource & "Sounds\End.mp3") MsgBox(0 , "Game Over" , "You Won") Else $Babe = $Babe +1 GUICtrlDelete($Strip) $Strip = GUICtrlCreatePic($Resource & "Pictures\" & $Babe & ".bmp", 0 , 0, 450, 600, $SS_REALSIZEIMAGE) EndIf EndFunc Func _Block($Player , $Block) If $Player = 1 Then GUICtrlSetState($Block , $GUI_DISABLE) GUICtrlSetData($Block , "X") GUICtrlSetFont($Block, 30, 800, 0, "Times New Roman") _Computer() ElseIf $Player = 2 Then GUICtrlSetState($Block , $GUI_DISABLE) GUICtrlSetData($Block , "O") GUICtrlSetFont($Block, 30, 800, 0, "Times New Roman") Else MsgBox(0 , "Error" , "Block Error") EndIf EndFunc Func _Computer() $Ran1 = Random(1 , 3 , 1) $Ran2 = Random(1 , 3 , 1) _Block(2 , $Square[$Ran1][$Ran2]) ;If $Ran1 = 1 And $Ran2 = 2 Then $A2 = True ;If $Ran1 = 1 And $Ran2 = 3 Then $A3 = True ;If $Ran1 = 2 And $Ran2 = 1 Then $B1 = True ;If $Ran1 = 2 And $Ran2 = 2 then $B2 = True ;If $Ran1 = 2 And $Ran2 = 3 Then $B3 = True ;If $Ran1 = 3 And $Ran2 = 1 Then $C1 = True ;If $Ran1 = 3 And $Ran2 = 2 Then $C2 = True ;If $Ran1 = 3 And $Ran2 = 3 Then $C3 = True EndFunc Func _ClearBoard($Winner) If $Winner = 1 Then $WinZ = $WinZ +1 WinSetTitle($GUI , "" , "Wins " & $WinZ & " Loses " & $Loses & " Tied " & $Tied) SoundPlay($Resource & "Sounds\Good.mp3") _Babe() ElseIf $Winner = 2 Then $Loses = $Loses +1 WinSetTitle($GUI , "" , "Wins " & $WinZ & " Loses " & $Loses & " Tied " & $Tied) SoundPlay($Resource & "Sounds\Bad.mp3") ElseIf $Winner = 3 Then $Tied = $Tied +1 WinSetTitle($GUI , "" , "Wins " & $WinZ & " Loses " & $Loses & " Tied " & $Tied) SoundPlay($Resource & "Sounds\Draw.mp3") Else MsgBox(0 , "Error" , "Winner Error") EndIf $A1 = False $A2 = False $A3 = False $B1 = False $B2 = False $B3 = False $C1 = False $C2 = False $C3 = False GUICtrlSetData($Square[1][1] , "") GUICtrlSetData($Square[1][2] , "") GUICtrlSetData($Square[1][3] , "") GUICtrlSetData($Square[2][1] , "") GUICtrlSetData($Square[2][2] , "") GUICtrlSetData($Square[2][3] , "") GUICtrlSetData($Square[3][1] , "") GUICtrlSetData($Square[3][2] , "") GUICtrlSetData($Square[3][3] , "") GUICtrlSetState($Square[1][1] , $GUI_ENABLE) GUICtrlSetState($Square[1][2] , $GUI_ENABLE) GUICtrlSetState($Square[1][3] , $GUI_ENABLE) GUICtrlSetState($Square[2][1] , $GUI_ENABLE) GUICtrlSetState($Square[2][2] , $GUI_ENABLE) GUICtrlSetState($Square[2][3] , $GUI_ENABLE) GUICtrlSetState($Square[3][1] , $GUI_ENABLE) GUICtrlSetState($Square[3][2] , $GUI_ENABLE) GUICtrlSetState($Square[3][3] , $GUI_ENABLE) EndFunc Func _Win() ;"X" $Win = 1 ;Across If GUICtrlRead($Square[1][1]) = "X" And GUICtrlRead($Square[1][2]) = "X" And GUICtrlRead($Square[1][3]) = "X" Then Return _ClearBoard(1) If GUICtrlRead($Square[2][1]) = "X" And GUICtrlRead($Square[2][2]) = "X" And GUICtrlRead($Square[2][3]) = "X" Then Return _ClearBoard(1) If GUICtrlRead($Square[3][1]) = "X" And GUICtrlRead($Square[3][2]) = "X" And GUICtrlRead($Square[3][3]) = "X" Then Return _ClearBoard(1) ;Down If GUICtrlRead($Square[1][1]) = "X" And GUICtrlRead($Square[2][1]) = "X" And GUICtrlRead($Square[3][1]) = "X" Then Return _ClearBoard(1) If GUICtrlRead($Square[1][2]) = "X" And GUICtrlRead($Square[2][2]) = "X" And GUICtrlRead($Square[3][2]) = "X" Then Return _ClearBoard(1) If GUICtrlRead($Square[1][3]) = "X" And GUICtrlRead($Square[2][3]) = "X" And GUICtrlRead($Square[3][3]) = "X" Then Return _ClearBoard(1) ;Dial If GUICtrlRead($Square[1][1]) = "X" And GUICtrlRead($Square[2][2]) = "X" And GUICtrlRead($Square[3][3]) = "X" Then Return _ClearBoard(1) If GUICtrlRead($Square[1][3]) = "X" And GUICtrlRead($Square[2][2]) = "X" And GUICtrlRead($Square[1][3]) = "X" Then Return _ClearBoard(1) ;"O" $Win = 2 ;Across If GUICtrlRead($Square[1][1]) = "O" And GUICtrlRead($Square[1][2]) = "O" And GUICtrlRead($Square[1][3]) = "O" Then Return _ClearBoard(2) If GUICtrlRead($Square[2][1]) = "O" And GUICtrlRead($Square[2][2]) = "O" And GUICtrlRead($Square[2][3]) = "O" Then Return _ClearBoard(2) If GUICtrlRead($Square[3][1]) = "O" And GUICtrlRead($Square[3][2]) = "O" And GUICtrlRead($Square[3][3]) = "O" Then Return _ClearBoard(2) ;Down If GUICtrlRead($Square[1][1]) = "O" And GUICtrlRead($Square[2][1]) = "O" And GUICtrlRead($Square[3][1]) = "O" Then Return _ClearBoard(2) If GUICtrlRead($Square[1][2]) = "O" And GUICtrlRead($Square[2][2]) = "O" And GUICtrlRead($Square[3][2]) = "O" Then Return _ClearBoard(2) If GUICtrlRead($Square[1][3]) = "O" And GUICtrlRead($Square[2][3]) = "O" And GUICtrlRead($Square[3][3]) = "O" Then Return _ClearBoard(2) ;Dial If GUICtrlRead($Square[1][1]) = "O" And GUICtrlRead($Square[2][2]) = "O" And GUICtrlRead($Square[3][3]) = "O" Then Return _ClearBoard(2) If GUICtrlRead($Square[1][3]) = "O" And GUICtrlRead($Square[2][2]) = "O" And GUICtrlRead($Square[1][3]) = "O" Then Return _ClearBoard(2) ;If Not GUICtrlRead($Square[1][1]) = "" And GUICtrlRead($Square[1][2]) = "" And GUICtrlRead($Square[1][3]) = "" And GUICtrlRead($Square[2][1]) = "" And GUICtrlRead($Square[2][2]) = "" And GUICtrlRead($Square[2][3]) = "" And GUICtrlRead($Square[3][1]) = "" And GUICtrlRead($Square[3][2]) = "" And GUICtrlRead($Square[3][3]) = "" Then _ClearBoard(3) EndFunc Edited June 2, 2008 by JellyFish666 Link to comment Share on other sites More sharing options...
enaiman Posted June 1, 2008 Share Posted June 1, 2008 There are at least 2 Tic-Tac-Toe on example scripts (mine and Nahuel's) both having code. You might have a look at the code and you might get some ideas. What I did: I've considered the table having 8 distinct "rows" 4 5 6 7 8 \ | | | / 3-x x x 2-x x x 1-x x x and I have assigned a value of 2 to a "0" square and a value of 5 to an "X" square. The computer will calculate the "row" value and act accordingly. The computer will be always 0 so if one of the columns returns 2+2 and it is computer's turn then it will play in the 3rd space (win situation). If none of them return 4 it will look for a "row" returning 10 (the player has 2 spaces there and it could win) and the computer will block that "row" ... and so on. If none of this situations are returned it will play on a "row" returning 2 or ... somewhere else. This is my approach to the problem, it might be solved in a million different ways but doing it this way and considering the situations you might end up with an unbeatable one. Lol - I can see you don't want one to win always - so you will have to put some "Random" statements in the code. It is an interresting and challenging project - I wish you good luck About your questions: If you assign a value to any "played" squares then it will be easy to recognize which squares are empty. That will solve your "no more moves" as well. SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
JellyFish666 Posted June 1, 2008 Author Share Posted June 1, 2008 (edited) There are at least 2 Tic-Tac-Toe on example scripts (mine and Nahuel's) both having code. You might have a look at the code and you might get some ideas.What I did: I've considered the table having 8 distinct "rows" 4 5 6 7 8 \ | | | /3-x x x2-x x x1-x x xand I have assigned a value of 2 to a "0" square and a value of 5 to an "X" square.The computer will calculate the "row" value and act accordingly. The computer will be always 0 so if one of the columns returns 2+2 and it is computer's turn then it will play in the 3rd space (win situation). If none of them return 4 it will look for a "row" returning 10 (the player has 2 spaces there and it could win) and the computer will block that "row" ... and so on. If none of this situations are returned it will play on a "row" returning 2 or ... somewhere else.This is my approach to the problem, it might be solved in a million different ways but doing it this way and considering the situations you might end up with an unbeatable one. Lol - I can see you don't want one to win always - so you will have to put some "Random" statements in the code.It is an interresting and challenging project - I wish you good luck About your questions: If you assign a value to any "played" squares then it will be easy to recognize which squares are empty.That will solve your "no more moves" as well.I only have the bot random for now that will change as soon as everything is fixed, your post has helped me a bit but still stuck with the same errors, although I might try your idea later about assigning the moves played.only got how far I did with pure luck this is my first script I have actually made besides my tiny ones.Thanks Edited June 1, 2008 by JellyFish666 Link to comment Share on other sites More sharing options...
enaiman Posted June 2, 2008 Share Posted June 2, 2008 (edited) here it comes the improved version of your script - try to understand it and you can continue expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $WinZ , $Loses , $SS_REALSIZEIMAGE , $Babe = 1 , $Square[99][99] , $Resource = @ScriptDir & "\Resource\" Global $Lines[9], $Sq_Value[4][4], $CurrentSqValue = 0 $GUI = GUICreate("|Wins 0 | Loses 0|", 1056, 606) GUISetBkColor(0x000000) $Board = GUICtrlCreatePic($Resource & "Pictures\Board.bmp", 450 , 0, 606, 606, $SS_REALSIZEIMAGE) $Square[1][1] = GUICtrlCreateButton("", 460, 10, 180, 180, 0) $Square[1][2] = GUICtrlCreateButton("", 660, 10, 180, 180, 0) $Square[1][3] = GUICtrlCreateButton("", 860, 10 , 180, 180, 0) $Square[2][1] = GUICtrlCreateButton("", 460, 210, 180, 180, 0) $Square[2][2] = GUICtrlCreateButton("", 660, 210, 180, 180, 0) $Square[2][3] = GUICtrlCreateButton("", 860, 210, 180, 180, 0) $Square[3][1] = GUICtrlCreateButton("", 460, 410, 180, 180, 0) $Square[3][2] = GUICtrlCreateButton("", 660, 410, 180, 180, 0) $Square[3][3] = GUICtrlCreateButton("", 860, 410, 180, 180, 0) $Strip = GUICtrlCreatePic($Resource & "Pictures\1.bmp", 0 , 0, 450, 600, $SS_REALSIZEIMAGE) _InitGame() GUISetState(@SW_SHOW) ;$i = 1 ;Do ; Sleep(500) ; $i = $i +1 ; GUICtrlDelete($Strip) ; $Strip = GUICtrlCreatePic($Resource & "Pictures\" & $i & ".bmp", 0 , 0, 450, 600, $SS_REALSIZEIMAGE) ;Until $i = 24 While 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE Exit Case $Square[1][1] _Win() _Block(1 , $Square[1][1]) Case $Square[1][2] _Win() _Block(1 , $Square[1][2]) Case $Square[1][3] _Win() _Block(1 , $Square[1][3]) Case $Square[2][1] _Win() _Block(1 , $Square[2][1]) Case $Square[2][2] _Win() _Block(1 , $Square[2][2]) Case $Square[2][3] _Win() _Block(1 , $Square[2][3]) Case $Square[3][1] _Win() _Block(1 , $Square[3][1]) Case $Square[3][2] _Win() _Block(1 , $Square[3][2]) Case $Square[3][3] _Win() _Block(1 , $Square[3][3]) EndSwitch _Win() WEnd Func _Babe() If $Babe = 23 Then $Babe = 1 GUICtrlDelete($Strip) $Strip = GUICtrlCreatePic($Resource & "Pictures\" & $Babe & ".bmp", 0 , 0, 450, 600, $SS_REALSIZEIMAGE) ;SoundPlay($Resource & "Sounds\End.mp3") MsgBox(0 , "Game Over" , "You Won") Else $Babe = $Babe +1 GUICtrlDelete($Strip) $Strip = GUICtrlCreatePic($Resource & "Pictures\" & $Babe & ".bmp", 0 , 0, 450, 600, $SS_REALSIZEIMAGE) EndIf EndFunc Func _Block($Player , $Block) If $Player = 1 Then GUICtrlSetState($Block , $GUI_DISABLE) GUICtrlSetData($Block , "X") GUICtrlSetFont($Block, 30, 800, 0, "Times New Roman") _SetSqValue($Block, 5) ;value 5 for an X square _Computer() ElseIf $Player = 2 Then GUICtrlSetState($Block , $GUI_DISABLE) GUICtrlSetData($Block , "O") GUICtrlSetFont($Block, 30, 800, 0, "Times New Roman") _SetSqValue($Block, 2) ;value 2 for an O square Else MsgBox(0 , "Error" , "Block Error") EndIf EndFunc Func _Computer() Do $SqToPlay = Int(Random(3,11)) ;3-11 because the buttons are identified by these numbers _GetSqValue ($SqToPlay) Until $CurrentSqValue = 0 ;do it until it finds an empty square _Block(2 , $SqToPlay) EndFunc Func _ClearBoard($Winner) If $Winner = 1 Then ;SoundPlay($Resource & "Sounds\Good.mp3") MsgBox(0, "you won", "eee") _Babe() ElseIf $Winner = 2 Then MsgBox(0, "I won", "eee") ;SoundPlay($Resource & "Sounds\Bad.mp3") ElseIf $Winner = 3 Then MsgBox(0 , "" , "test clearing...") ;;; Else MsgBox(0 , "Error" , "Winner Error") EndIf _InitGame() ;reset everything to default EndFunc Func _Win() $Lines[1] = $Sq_Value[3][1] + $Sq_Value[3][2] + $Sq_Value[3][3] ;these are the lines numbered as I shown in my previous post $Lines[2] = $Sq_Value[2][1] + $Sq_Value[2][2] + $Sq_Value[2][3] $Lines[3] = $Sq_Value[1][1] + $Sq_Value[1][2] + $Sq_Value[1][3] $Lines[4] = $Sq_Value[1][1] + $Sq_Value[2][2] + $Sq_Value[3][3] $Lines[5] = $Sq_Value[1][1] + $Sq_Value[2][1] + $Sq_Value[3][1] $Lines[6] = $Sq_Value[1][2] + $Sq_Value[2][2] + $Sq_Value[3][2] $Lines[7] = $Sq_Value[1][3] + $Sq_Value[2][3] + $Sq_Value[3][3] $Lines[8] = $Sq_Value[1][3] + $Sq_Value[2][2] + $Sq_Value[3][1] For $k=1 To 8 If $Lines[$k] = 15 Then ; X X X = 5+5+5 = player win $Win = 1 Return _ClearBoard(1) EndIf If $Lines[$k] = 6 Then ;0 0 0 = 2+2+2 = computer win $Win = 2 Return _ClearBoard(2) EndIf Next EndFunc Func _InitGame() ;clears all values Dim $Lines[9] ;clears the array For $z=1 to 8 $Lines[$z] = 0 ;makes all the line values 0 Next For $i=1 to 3 For $j=1 To 3 $Sq_Value[$i][$j] = 0 ;makes all square values 0 Next Next GUICtrlSetData($Square[1][1] , "") GUICtrlSetData($Square[1][2] , "") GUICtrlSetData($Square[1][3] , "") GUICtrlSetData($Square[2][1] , "") GUICtrlSetData($Square[2][2] , "") GUICtrlSetData($Square[2][3] , "") GUICtrlSetData($Square[3][1] , "") GUICtrlSetData($Square[3][2] , "") GUICtrlSetData($Square[3][3] , "") GUICtrlSetState($Square[1][1] , $GUI_ENABLE) GUICtrlSetState($Square[1][2] , $GUI_ENABLE) GUICtrlSetState($Square[1][3] , $GUI_ENABLE) GUICtrlSetState($Square[2][1] , $GUI_ENABLE) GUICtrlSetState($Square[2][2] , $GUI_ENABLE) GUICtrlSetState($Square[2][3] , $GUI_ENABLE) GUICtrlSetState($Square[3][1] , $GUI_ENABLE) GUICtrlSetState($Square[3][2] , $GUI_ENABLE) GUICtrlSetState($Square[3][3] , $GUI_ENABLE) EndFunc Func _SetSqValue($sqre, $value) ;sets the value of each square Select Case $sqre = 3 ;this is Square [1][1] $Sq_Value[1][1] = $value Case $sqre = 4 ;this is Square [1][2] $Sq_Value[1][2] = $value Case $sqre = 5 $Sq_Value[1][3] = $value Case $sqre = 6 $Sq_Value[2][1] = $value Case $sqre = 7 $Sq_Value[2][2] = $value Case $sqre = 8 $Sq_Value[2][3] = $value Case $sqre = 9 $Sq_Value[3][1] = $value Case $sqre = 10 $Sq_Value[3][2] = $value Case $sqre = 11 $Sq_Value[3][3] = $value Case Else MsgBox(16, "Error", "Error setting block value", 1) EndSelect EndFunc Func _GetSqValue($sqre) ;gets the value of each square Select Case $sqre = 3 ;this is Square [1][1] $CurrentSqValue = $Sq_Value[1][1] Case $sqre = 4 ;this is Square [1][2] $CurrentSqValue = $Sq_Value[1][2] Case $sqre = 5 $CurrentSqValue = $Sq_Value[1][3] Case $sqre = 6 $CurrentSqValue = $Sq_Value[2][1] Case $sqre = 7 $CurrentSqValue = $Sq_Value[2][2] Case $sqre = 8 $CurrentSqValue = $Sq_Value[2][3] Case $sqre = 9 $CurrentSqValue = $Sq_Value[3][1] Case $sqre = 10 $CurrentSqValue = $Sq_Value[3][2] Case $sqre = 11 $CurrentSqValue = $Sq_Value[3][3] Case Else MsgBox(16, "Error", "Error getting block value") EndSelect EndFunc Edited June 2, 2008 by enaiman SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
JellyFish666 Posted June 2, 2008 Author Share Posted June 2, 2008 (edited) here it comes the improved version of your script - try to understand it and you can continue expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $WinZ , $Loses , $SS_REALSIZEIMAGE , $Babe = 1 , $Square[99][99] , $Resource = @ScriptDir & "\Resource\" Global $Lines[9], $Sq_Value[4][4], $CurrentSqValue = 0 $GUI = GUICreate("|Wins 0 | Loses 0|", 1056, 606) GUISetBkColor(0x000000) $Board = GUICtrlCreatePic($Resource & "Pictures\Board.bmp", 450 , 0, 606, 606, $SS_REALSIZEIMAGE) $Square[1][1] = GUICtrlCreateButton("", 460, 10, 180, 180, 0) $Square[1][2] = GUICtrlCreateButton("", 660, 10, 180, 180, 0) $Square[1][3] = GUICtrlCreateButton("", 860, 10 , 180, 180, 0) $Square[2][1] = GUICtrlCreateButton("", 460, 210, 180, 180, 0) $Square[2][2] = GUICtrlCreateButton("", 660, 210, 180, 180, 0) $Square[2][3] = GUICtrlCreateButton("", 860, 210, 180, 180, 0) $Square[3][1] = GUICtrlCreateButton("", 460, 410, 180, 180, 0) $Square[3][2] = GUICtrlCreateButton("", 660, 410, 180, 180, 0) $Square[3][3] = GUICtrlCreateButton("", 860, 410, 180, 180, 0) $Strip = GUICtrlCreatePic($Resource & "Pictures\1.bmp", 0 , 0, 450, 600, $SS_REALSIZEIMAGE) _InitGame() GUISetState(@SW_SHOW) ;$i = 1 ;Do ; Sleep(500) ; $i = $i +1 ; GUICtrlDelete($Strip) ; $Strip = GUICtrlCreatePic($Resource & "Pictures\" & $i & ".bmp", 0 , 0, 450, 600, $SS_REALSIZEIMAGE) ;Until $i = 24 While 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE Exit Case $Square[1][1] _Win() _Block(1 , $Square[1][1]) Case $Square[1][2] _Win() _Block(1 , $Square[1][2]) Case $Square[1][3] _Win() _Block(1 , $Square[1][3]) Case $Square[2][1] _Win() _Block(1 , $Square[2][1]) Case $Square[2][2] _Win() _Block(1 , $Square[2][2]) Case $Square[2][3] _Win() _Block(1 , $Square[2][3]) Case $Square[3][1] _Win() _Block(1 , $Square[3][1]) Case $Square[3][2] _Win() _Block(1 , $Square[3][2]) Case $Square[3][3] _Win() _Block(1 , $Square[3][3]) EndSwitch _Win() WEnd Func _Babe() If $Babe = 23 Then $Babe = 1 GUICtrlDelete($Strip) $Strip = GUICtrlCreatePic($Resource & "Pictures\" & $Babe & ".bmp", 0 , 0, 450, 600, $SS_REALSIZEIMAGE) ;SoundPlay($Resource & "Sounds\End.mp3") MsgBox(0 , "Game Over" , "You Won") Else $Babe = $Babe +1 GUICtrlDelete($Strip) $Strip = GUICtrlCreatePic($Resource & "Pictures\" & $Babe & ".bmp", 0 , 0, 450, 600, $SS_REALSIZEIMAGE) EndIf EndFunc Func _Block($Player , $Block) If $Player = 1 Then GUICtrlSetState($Block , $GUI_DISABLE) GUICtrlSetData($Block , "X") GUICtrlSetFont($Block, 30, 800, 0, "Times New Roman") _SetSqValue($Block, 5) ;value 5 for an X square _Computer() ElseIf $Player = 2 Then GUICtrlSetState($Block , $GUI_DISABLE) GUICtrlSetData($Block , "O") GUICtrlSetFont($Block, 30, 800, 0, "Times New Roman") _SetSqValue($Block, 2) ;value 2 for an O square Else MsgBox(0 , "Error" , "Block Error") EndIf EndFunc Func _Computer() Do $SqToPlay = Int(Random(3,11)) ;3-11 because the buttons are identified by these numbers _GetSqValue ($SqToPlay) Until $CurrentSqValue = 0 ;do it until it finds an empty square _Block(2 , $SqToPlay) EndFunc Func _ClearBoard($Winner) If $Winner = 1 Then ;SoundPlay($Resource & "Sounds\Good.mp3") MsgBox(0, "you won", "eee") _Babe() ElseIf $Winner = 2 Then MsgBox(0, "I won", "eee") ;SoundPlay($Resource & "Sounds\Bad.mp3") ElseIf $Winner = 3 Then MsgBox(0 , "" , "test clearing...") ;;; Else MsgBox(0 , "Error" , "Winner Error") EndIf _InitGame() ;reset everything to default EndFunc Func _Win() $Lines[1] = $Sq_Value[3][1] + $Sq_Value[3][2] + $Sq_Value[3][3] ;these are the lines numbered as I shown in my previous post $Lines[2] = $Sq_Value[2][1] + $Sq_Value[2][2] + $Sq_Value[2][3] $Lines[3] = $Sq_Value[1][1] + $Sq_Value[1][2] + $Sq_Value[1][3] $Lines[4] = $Sq_Value[1][1] + $Sq_Value[2][2] + $Sq_Value[3][3] $Lines[5] = $Sq_Value[1][1] + $Sq_Value[2][1] + $Sq_Value[3][1] $Lines[6] = $Sq_Value[1][2] + $Sq_Value[2][2] + $Sq_Value[3][2] $Lines[7] = $Sq_Value[1][3] + $Sq_Value[2][3] + $Sq_Value[3][3] $Lines[8] = $Sq_Value[1][3] + $Sq_Value[2][2] + $Sq_Value[3][1] For $k=1 To 8 If $Lines[$k] = 15 Then ; X X X = 5+5+5 = player win $Win = 1 Return _ClearBoard(1) EndIf If $Lines[$k] = 6 Then ;0 0 0 = 2+2+2 = computer win $Win = 2 Return _ClearBoard(2) EndIf Next EndFunc Func _InitGame() ;clears all values Dim $Lines[9] ;clears the array For $z=1 to 8 $Lines[$z] = 0 ;makes all the line values 0 Next For $i=1 to 3 For $j=1 To 3 $Sq_Value[$i][$j] = 0 ;makes all square values 0 Next Next GUICtrlSetData($Square[1][1] , "") GUICtrlSetData($Square[1][2] , "") GUICtrlSetData($Square[1][3] , "") GUICtrlSetData($Square[2][1] , "") GUICtrlSetData($Square[2][2] , "") GUICtrlSetData($Square[2][3] , "") GUICtrlSetData($Square[3][1] , "") GUICtrlSetData($Square[3][2] , "") GUICtrlSetData($Square[3][3] , "") GUICtrlSetState($Square[1][1] , $GUI_ENABLE) GUICtrlSetState($Square[1][2] , $GUI_ENABLE) GUICtrlSetState($Square[1][3] , $GUI_ENABLE) GUICtrlSetState($Square[2][1] , $GUI_ENABLE) GUICtrlSetState($Square[2][2] , $GUI_ENABLE) GUICtrlSetState($Square[2][3] , $GUI_ENABLE) GUICtrlSetState($Square[3][1] , $GUI_ENABLE) GUICtrlSetState($Square[3][2] , $GUI_ENABLE) GUICtrlSetState($Square[3][3] , $GUI_ENABLE) EndFunc Func _SetSqValue($sqre, $value) ;sets the value of each square Select Case $sqre = 3 ;this is Square [1][1] $Sq_Value[1][1] = $value Case $sqre = 4 ;this is Square [1][2] $Sq_Value[1][2] = $value Case $sqre = 5 $Sq_Value[1][3] = $value Case $sqre = 6 $Sq_Value[2][1] = $value Case $sqre = 7 $Sq_Value[2][2] = $value Case $sqre = 8 $Sq_Value[2][3] = $value Case $sqre = 9 $Sq_Value[3][1] = $value Case $sqre = 10 $Sq_Value[3][2] = $value Case $sqre = 11 $Sq_Value[3][3] = $value Case Else MsgBox(16, "Error", "Error setting block value", 1) EndSelect EndFunc Func _GetSqValue($sqre) ;gets the value of each square Select Case $sqre = 3 ;this is Square [1][1] $CurrentSqValue = $Sq_Value[1][1] Case $sqre = 4 ;this is Square [1][2] $CurrentSqValue = $Sq_Value[1][2] Case $sqre = 5 $CurrentSqValue = $Sq_Value[1][3] Case $sqre = 6 $CurrentSqValue = $Sq_Value[2][1] Case $sqre = 7 $CurrentSqValue = $Sq_Value[2][2] Case $sqre = 8 $CurrentSqValue = $Sq_Value[2][3] Case $sqre = 9 $CurrentSqValue = $Sq_Value[3][1] Case $sqre = 10 $CurrentSqValue = $Sq_Value[3][2] Case $sqre = 11 $CurrentSqValue = $Sq_Value[3][3] Case Else MsgBox(16, "Error", "Error getting block value") EndSelect EndFunc wow, that will take awhile to absorb, I really appreciate you helping me it means a lot, I think my script is very similar except your AI works really well, but I still don't know how to check if the game is a Tie/Draw that is the hardest part for me. [Edit] hmm by the way Int() I never used that code before wouldn't this be the same though. Random(3,11 , 1) Edited June 2, 2008 by JellyFish666 Link to comment Share on other sites More sharing options...
enaiman Posted June 2, 2008 Share Posted June 2, 2008 lol - very good question: it is indeed the same ... I didn't look at Random synthax - of course yours is more elegant Improved it a little bit - it's not perfect since sometimes it hangs somewhere but unfortunately I don't have so much time right now. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $WinZ , $Loses , $SS_REALSIZEIMAGE , $Babe = 1 , $Square[99][99] , $Resource = @ScriptDir & "\Resource\" Global $Lines[9], $Sq_Value[4][4], $CurrentSqValue = 0, $moves = 0 $GUI = GUICreate("|Wins 0 | Loses 0|", 1056, 606) GUISetBkColor(0x000000) $Board = GUICtrlCreatePic($Resource & "Pictures\Board.bmp", 450 , 0, 606, 606, $SS_REALSIZEIMAGE) $Square[1][1] = GUICtrlCreateButton("", 460, 10, 180, 180, 0) $Square[1][2] = GUICtrlCreateButton("", 660, 10, 180, 180, 0) $Square[1][3] = GUICtrlCreateButton("", 860, 10 , 180, 180, 0) $Square[2][1] = GUICtrlCreateButton("", 460, 210, 180, 180, 0) $Square[2][2] = GUICtrlCreateButton("", 660, 210, 180, 180, 0) $Square[2][3] = GUICtrlCreateButton("", 860, 210, 180, 180, 0) $Square[3][1] = GUICtrlCreateButton("", 460, 410, 180, 180, 0) $Square[3][2] = GUICtrlCreateButton("", 660, 410, 180, 180, 0) $Square[3][3] = GUICtrlCreateButton("", 860, 410, 180, 180, 0) $Strip = GUICtrlCreatePic($Resource & "Pictures\1.bmp", 0 , 0, 450, 600, $SS_REALSIZEIMAGE) _InitGame() GUISetState(@SW_SHOW) ;$i = 1 ;Do ; Sleep(500) ; $i = $i +1 ; GUICtrlDelete($Strip) ; $Strip = GUICtrlCreatePic($Resource & "Pictures\" & $i & ".bmp", 0 , 0, 450, 600, $SS_REALSIZEIMAGE) ;Until $i = 24 While 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE Exit Case $Square[1][1] _Win() _Block(1 , $Square[1][1]) Case $Square[1][2] _Win() _Block(1 , $Square[1][2]) Case $Square[1][3] _Win() _Block(1 , $Square[1][3]) Case $Square[2][1] _Win() _Block(1 , $Square[2][1]) Case $Square[2][2] _Win() _Block(1 , $Square[2][2]) Case $Square[2][3] _Win() _Block(1 , $Square[2][3]) Case $Square[3][1] _Win() _Block(1 , $Square[3][1]) Case $Square[3][2] _Win() _Block(1 , $Square[3][2]) Case $Square[3][3] _Win() _Block(1 , $Square[3][3]) EndSwitch _Win() WEnd Func _Babe() If $Babe = 23 Then $Babe = 1 GUICtrlDelete($Strip) $Strip = GUICtrlCreatePic($Resource & "Pictures\" & $Babe & ".bmp", 0 , 0, 450, 600, $SS_REALSIZEIMAGE) ;SoundPlay($Resource & "Sounds\End.mp3") MsgBox(0 , "Game Over" , "You Won") Else $Babe = $Babe +1 GUICtrlDelete($Strip) $Strip = GUICtrlCreatePic($Resource & "Pictures\" & $Babe & ".bmp", 0 , 0, 450, 600, $SS_REALSIZEIMAGE) EndIf EndFunc Func _Block($Player , $Block) If $Player = 1 Then GUICtrlSetState($Block , $GUI_DISABLE) GUICtrlSetData($Block , "X") GUICtrlSetFont($Block, 30, 800, 0, "Times New Roman") _SetSqValue($Block, 5) ;value 5 for an X square $moves +=1 _Computer() ElseIf $Player = 2 Then GUICtrlSetState($Block , $GUI_DISABLE) GUICtrlSetData($Block , "O") GUICtrlSetFont($Block, 30, 800, 0, "Times New Roman") _SetSqValue($Block, 2) ;value 2 for an O square $moves +=1 Else MsgBox(0 , "Error" , "Block Error") EndIf EndFunc Func _Computer() If $moves = 9 Then _win() Do $SqToPlay = Int(Random(3,11)) ;3-11 because the buttons are identified by these numbers _GetSqValue ($SqToPlay) Until $CurrentSqValue = 0 ;do it until it finds an empty square ; _win() ;check to see if computer win _Block(2 , $SqToPlay) EndFunc Func _ClearBoard($Winner) If $Winner = 1 Then ;SoundPlay($Resource & "Sounds\Good.mp3") MsgBox(0, "you won", "eee") _Babe() ElseIf $Winner = 2 Then MsgBox(0, "I won", "eee") ;SoundPlay($Resource & "Sounds\Bad.mp3") ElseIf $Winner = 3 Then MsgBox(0 , "Nobody won" , "grrrrr") ;;; Else MsgBox(0 , "Error" , "Winner Error") EndIf _InitGame() ;reset everything to default EndFunc Func _Win() $win = 0 ;NEW LINE $Lines[1] = $Sq_Value[3][1] + $Sq_Value[3][2] + $Sq_Value[3][3] ;these are the lines numbered as I shown in my previous post $Lines[2] = $Sq_Value[2][1] + $Sq_Value[2][2] + $Sq_Value[2][3] $Lines[3] = $Sq_Value[1][1] + $Sq_Value[1][2] + $Sq_Value[1][3] $Lines[4] = $Sq_Value[1][1] + $Sq_Value[2][2] + $Sq_Value[3][3] $Lines[5] = $Sq_Value[1][1] + $Sq_Value[2][1] + $Sq_Value[3][1] $Lines[6] = $Sq_Value[1][2] + $Sq_Value[2][2] + $Sq_Value[3][2] $Lines[7] = $Sq_Value[1][3] + $Sq_Value[2][3] + $Sq_Value[3][3] $Lines[8] = $Sq_Value[1][3] + $Sq_Value[2][2] + $Sq_Value[3][1] For $k=1 To 8 If $Lines[$k] = 15 Then ; X X X = 5+5+5 = player win $Win = 1 Return _ClearBoard(1) EndIf If $Lines[$k] = 6 Then ;0 0 0 = 2+2+2 = computer win $Win = 2 Return _ClearBoard(2) EndIf Next If $moves = 9 And $win = 0 Then Return _ClearBoard(3) ;NEW LINE EndFunc Func _InitGame() ;clears all values $moves = 0 ;NEW LINE Dim $Lines[9] ;clears the array For $z=1 to 8 $Lines[$z] = 0 ;makes all the line values 0 Next For $i=1 to 3 For $j=1 To 3 $Sq_Value[$i][$j] = 0 ;makes all square values 0 Next Next GUICtrlSetData($Square[1][1] , "") GUICtrlSetData($Square[1][2] , "") GUICtrlSetData($Square[1][3] , "") GUICtrlSetData($Square[2][1] , "") GUICtrlSetData($Square[2][2] , "") GUICtrlSetData($Square[2][3] , "") GUICtrlSetData($Square[3][1] , "") GUICtrlSetData($Square[3][2] , "") GUICtrlSetData($Square[3][3] , "") GUICtrlSetState($Square[1][1] , $GUI_ENABLE) GUICtrlSetState($Square[1][2] , $GUI_ENABLE) GUICtrlSetState($Square[1][3] , $GUI_ENABLE) GUICtrlSetState($Square[2][1] , $GUI_ENABLE) GUICtrlSetState($Square[2][2] , $GUI_ENABLE) GUICtrlSetState($Square[2][3] , $GUI_ENABLE) GUICtrlSetState($Square[3][1] , $GUI_ENABLE) GUICtrlSetState($Square[3][2] , $GUI_ENABLE) GUICtrlSetState($Square[3][3] , $GUI_ENABLE) EndFunc Func _SetSqValue($sqre, $value) ;sets the value of each square Select Case $sqre = 3 ;this is Square [1][1] $Sq_Value[1][1] = $value Case $sqre = 4 ;this is Square [1][2] $Sq_Value[1][2] = $value Case $sqre = 5 $Sq_Value[1][3] = $value Case $sqre = 6 $Sq_Value[2][1] = $value Case $sqre = 7 $Sq_Value[2][2] = $value Case $sqre = 8 $Sq_Value[2][3] = $value Case $sqre = 9 $Sq_Value[3][1] = $value Case $sqre = 10 $Sq_Value[3][2] = $value Case $sqre = 11 $Sq_Value[3][3] = $value Case Else MsgBox(16, "Error", "Error setting block value", 1) EndSelect EndFunc Func _GetSqValue($sqre) ;gets the value of each square Select Case $sqre = 3 ;this is Square [1][1] $CurrentSqValue = $Sq_Value[1][1] Case $sqre = 4 ;this is Square [1][2] $CurrentSqValue = $Sq_Value[1][2] Case $sqre = 5 $CurrentSqValue = $Sq_Value[1][3] Case $sqre = 6 $CurrentSqValue = $Sq_Value[2][1] Case $sqre = 7 $CurrentSqValue = $Sq_Value[2][2] Case $sqre = 8 $CurrentSqValue = $Sq_Value[2][3] Case $sqre = 9 $CurrentSqValue = $Sq_Value[3][1] Case $sqre = 10 $CurrentSqValue = $Sq_Value[3][2] Case $sqre = 11 $CurrentSqValue = $Sq_Value[3][3] Case Else MsgBox(16, "Error", "Error getting block value") EndSelect EndFunc SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
JellyFish666 Posted June 2, 2008 Author Share Posted June 2, 2008 lol - very good question: it is indeed the same ... I didn't look at Random synthax - of course yours is more elegant Improved it a little bit - it's not perfect since sometimes it hangs somewhere but unfortunately I don't have so much time right now. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $WinZ , $Loses , $SS_REALSIZEIMAGE , $Babe = 1 , $Square[99][99] , $Resource = @ScriptDir & "\Resource\" Global $Lines[9], $Sq_Value[4][4], $CurrentSqValue = 0, $moves = 0 $GUI = GUICreate("|Wins 0 | Loses 0|", 1056, 606) GUISetBkColor(0x000000) $Board = GUICtrlCreatePic($Resource & "Pictures\Board.bmp", 450 , 0, 606, 606, $SS_REALSIZEIMAGE) $Square[1][1] = GUICtrlCreateButton("", 460, 10, 180, 180, 0) $Square[1][2] = GUICtrlCreateButton("", 660, 10, 180, 180, 0) $Square[1][3] = GUICtrlCreateButton("", 860, 10 , 180, 180, 0) $Square[2][1] = GUICtrlCreateButton("", 460, 210, 180, 180, 0) $Square[2][2] = GUICtrlCreateButton("", 660, 210, 180, 180, 0) $Square[2][3] = GUICtrlCreateButton("", 860, 210, 180, 180, 0) $Square[3][1] = GUICtrlCreateButton("", 460, 410, 180, 180, 0) $Square[3][2] = GUICtrlCreateButton("", 660, 410, 180, 180, 0) $Square[3][3] = GUICtrlCreateButton("", 860, 410, 180, 180, 0) $Strip = GUICtrlCreatePic($Resource & "Pictures\1.bmp", 0 , 0, 450, 600, $SS_REALSIZEIMAGE) _InitGame() GUISetState(@SW_SHOW) ;$i = 1 ;Do ; Sleep(500) ; $i = $i +1 ; GUICtrlDelete($Strip) ; $Strip = GUICtrlCreatePic($Resource & "Pictures\" & $i & ".bmp", 0 , 0, 450, 600, $SS_REALSIZEIMAGE) ;Until $i = 24 While 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE Exit Case $Square[1][1] _Win() _Block(1 , $Square[1][1]) Case $Square[1][2] _Win() _Block(1 , $Square[1][2]) Case $Square[1][3] _Win() _Block(1 , $Square[1][3]) Case $Square[2][1] _Win() _Block(1 , $Square[2][1]) Case $Square[2][2] _Win() _Block(1 , $Square[2][2]) Case $Square[2][3] _Win() _Block(1 , $Square[2][3]) Case $Square[3][1] _Win() _Block(1 , $Square[3][1]) Case $Square[3][2] _Win() _Block(1 , $Square[3][2]) Case $Square[3][3] _Win() _Block(1 , $Square[3][3]) EndSwitch _Win() WEnd Func _Babe() If $Babe = 23 Then $Babe = 1 GUICtrlDelete($Strip) $Strip = GUICtrlCreatePic($Resource & "Pictures\" & $Babe & ".bmp", 0 , 0, 450, 600, $SS_REALSIZEIMAGE) ;SoundPlay($Resource & "Sounds\End.mp3") MsgBox(0 , "Game Over" , "You Won") Else $Babe = $Babe +1 GUICtrlDelete($Strip) $Strip = GUICtrlCreatePic($Resource & "Pictures\" & $Babe & ".bmp", 0 , 0, 450, 600, $SS_REALSIZEIMAGE) EndIf EndFunc Func _Block($Player , $Block) If $Player = 1 Then GUICtrlSetState($Block , $GUI_DISABLE) GUICtrlSetData($Block , "X") GUICtrlSetFont($Block, 30, 800, 0, "Times New Roman") _SetSqValue($Block, 5) ;value 5 for an X square $moves +=1 _Computer() ElseIf $Player = 2 Then GUICtrlSetState($Block , $GUI_DISABLE) GUICtrlSetData($Block , "O") GUICtrlSetFont($Block, 30, 800, 0, "Times New Roman") _SetSqValue($Block, 2) ;value 2 for an O square $moves +=1 Else MsgBox(0 , "Error" , "Block Error") EndIf EndFunc Func _Computer() If $moves = 9 Then _win() Do $SqToPlay = Int(Random(3,11)) ;3-11 because the buttons are identified by these numbers _GetSqValue ($SqToPlay) Until $CurrentSqValue = 0 ;do it until it finds an empty square ; _win() ;check to see if computer win _Block(2 , $SqToPlay) EndFunc Func _ClearBoard($Winner) If $Winner = 1 Then ;SoundPlay($Resource & "Sounds\Good.mp3") MsgBox(0, "you won", "eee") _Babe() ElseIf $Winner = 2 Then MsgBox(0, "I won", "eee") ;SoundPlay($Resource & "Sounds\Bad.mp3") ElseIf $Winner = 3 Then MsgBox(0 , "Nobody won" , "grrrrr") ;;; Else MsgBox(0 , "Error" , "Winner Error") EndIf _InitGame() ;reset everything to default EndFunc Func _Win() $win = 0 ;NEW LINE $Lines[1] = $Sq_Value[3][1] + $Sq_Value[3][2] + $Sq_Value[3][3] ;these are the lines numbered as I shown in my previous post $Lines[2] = $Sq_Value[2][1] + $Sq_Value[2][2] + $Sq_Value[2][3] $Lines[3] = $Sq_Value[1][1] + $Sq_Value[1][2] + $Sq_Value[1][3] $Lines[4] = $Sq_Value[1][1] + $Sq_Value[2][2] + $Sq_Value[3][3] $Lines[5] = $Sq_Value[1][1] + $Sq_Value[2][1] + $Sq_Value[3][1] $Lines[6] = $Sq_Value[1][2] + $Sq_Value[2][2] + $Sq_Value[3][2] $Lines[7] = $Sq_Value[1][3] + $Sq_Value[2][3] + $Sq_Value[3][3] $Lines[8] = $Sq_Value[1][3] + $Sq_Value[2][2] + $Sq_Value[3][1] For $k=1 To 8 If $Lines[$k] = 15 Then ; X X X = 5+5+5 = player win $Win = 1 Return _ClearBoard(1) EndIf If $Lines[$k] = 6 Then ;0 0 0 = 2+2+2 = computer win $Win = 2 Return _ClearBoard(2) EndIf Next If $moves = 9 And $win = 0 Then Return _ClearBoard(3) ;NEW LINE EndFunc Func _InitGame() ;clears all values $moves = 0 ;NEW LINE Dim $Lines[9] ;clears the array For $z=1 to 8 $Lines[$z] = 0 ;makes all the line values 0 Next For $i=1 to 3 For $j=1 To 3 $Sq_Value[$i][$j] = 0 ;makes all square values 0 Next Next GUICtrlSetData($Square[1][1] , "") GUICtrlSetData($Square[1][2] , "") GUICtrlSetData($Square[1][3] , "") GUICtrlSetData($Square[2][1] , "") GUICtrlSetData($Square[2][2] , "") GUICtrlSetData($Square[2][3] , "") GUICtrlSetData($Square[3][1] , "") GUICtrlSetData($Square[3][2] , "") GUICtrlSetData($Square[3][3] , "") GUICtrlSetState($Square[1][1] , $GUI_ENABLE) GUICtrlSetState($Square[1][2] , $GUI_ENABLE) GUICtrlSetState($Square[1][3] , $GUI_ENABLE) GUICtrlSetState($Square[2][1] , $GUI_ENABLE) GUICtrlSetState($Square[2][2] , $GUI_ENABLE) GUICtrlSetState($Square[2][3] , $GUI_ENABLE) GUICtrlSetState($Square[3][1] , $GUI_ENABLE) GUICtrlSetState($Square[3][2] , $GUI_ENABLE) GUICtrlSetState($Square[3][3] , $GUI_ENABLE) EndFunc Func _SetSqValue($sqre, $value) ;sets the value of each square Select Case $sqre = 3 ;this is Square [1][1] $Sq_Value[1][1] = $value Case $sqre = 4 ;this is Square [1][2] $Sq_Value[1][2] = $value Case $sqre = 5 $Sq_Value[1][3] = $value Case $sqre = 6 $Sq_Value[2][1] = $value Case $sqre = 7 $Sq_Value[2][2] = $value Case $sqre = 8 $Sq_Value[2][3] = $value Case $sqre = 9 $Sq_Value[3][1] = $value Case $sqre = 10 $Sq_Value[3][2] = $value Case $sqre = 11 $Sq_Value[3][3] = $value Case Else MsgBox(16, "Error", "Error setting block value", 1) EndSelect EndFunc Func _GetSqValue($sqre) ;gets the value of each square Select Case $sqre = 3 ;this is Square [1][1] $CurrentSqValue = $Sq_Value[1][1] Case $sqre = 4 ;this is Square [1][2] $CurrentSqValue = $Sq_Value[1][2] Case $sqre = 5 $CurrentSqValue = $Sq_Value[1][3] Case $sqre = 6 $CurrentSqValue = $Sq_Value[2][1] Case $sqre = 7 $CurrentSqValue = $Sq_Value[2][2] Case $sqre = 8 $CurrentSqValue = $Sq_Value[2][3] Case $sqre = 9 $CurrentSqValue = $Sq_Value[3][1] Case $sqre = 10 $CurrentSqValue = $Sq_Value[3][2] Case $sqre = 11 $CurrentSqValue = $Sq_Value[3][3] Case Else MsgBox(16, "Error", "Error getting block value") EndSelect EndFunc Again Thanks for taking the time to help me it means a lot, I played 20 Ties and around then it finally locked up and I couldn't click the last button but ill try and fix it but would be happy if someone knows whats wrong with it. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now