Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > AutoIt
You last visited: Today at 18:19

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Tic Tac Toe [BETA]

Discussion on Tic Tac Toe [BETA] within the AutoIt forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Apr 2011
Posts: 65
Received Thanks: 12
Smile Tic Tac Toe [BETA]

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.
Attached Files
File Type: rar Tic Tac Toe v0.1.rar (512.3 KB, 20 views)
kimboy600 is offline  
Old 12/17/2013, 15:56   #2
 
alpines's Avatar
 
elite*gold: 60
Join Date: Aug 2009
Posts: 2,256
Received Thanks: 815
Not bad, but I think you can write the code shorter.
If you want to then you can make a new version with GDI+ which would look nicer.
alpines is offline  
Old 12/17/2013, 16:03   #3
 
elite*gold: 0
Join Date: Apr 2011
Posts: 65
Received Thanks: 12
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?
kimboy600 is offline  
Old 12/17/2013, 16:04   #4
 
alpines's Avatar
 
elite*gold: 60
Join Date: Aug 2009
Posts: 2,256
Received Thanks: 815
The msgbox which displays Game Over?
Code:
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
alpines is offline  
Thanks
1 User
Old 12/17/2013, 16:12   #5
 
elite*gold: 0
Join Date: Apr 2011
Posts: 65
Received Thanks: 12
Ok got it , I'll try to do it later now i'm quite busy. thanks a lot!

Changed code , fixed bug wich showed 2 messages if someone won with the last space.
Thanks to alpines.
kimboy600 is offline  
Old 12/17/2013, 20:44   #6
 
lolkop's Avatar
 
elite*gold: 280
Join Date: May 2007
Posts: 2,818
Received Thanks: 3,483
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
lolkop is offline  
Thanks
1 User
Old 12/17/2013, 20:54   #7
 
alpines's Avatar
 
elite*gold: 60
Join Date: Aug 2009
Posts: 2,256
Received Thanks: 815
Kannst du um eine Zeile kürzen
Return False brauchst du nicht, da AutoIt Funktionen automatisch 0 returnen wenn sie nichts returnen und auslaufen.
alpines is offline  
Old 12/17/2013, 21:02   #8
 
lolkop's Avatar
 
elite*gold: 280
Join Date: May 2007
Posts: 2,818
Received Thanks: 3,483
der code soll keine perfektion demonstrieren, sondern lediglich darauf aufmerksam machen, wie sehr doch arrays in 2d anwendungen sinn machen...

es gibt ohne zweifel viel, was verbessert noch werden könnte...
lolkop is offline  
Old 12/17/2013, 21:21   #9
 
alpines's Avatar
 
elite*gold: 60
Join Date: Aug 2009
Posts: 2,256
Received Thanks: 815
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.
alpines is offline  
Old 12/17/2013, 22:49   #10
 
elite*gold: 0
Join Date: Apr 2011
Posts: 65
Received Thanks: 12
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
kimboy600 is offline  
Old 12/17/2013, 23:20   #11
 
alpines's Avatar
 
elite*gold: 60
Join Date: Aug 2009
Posts: 2,256
Received Thanks: 815
Wow, dat AI.

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 is offline  
Old 12/18/2013, 00:37   #12
 
lolkop's Avatar
 
elite*gold: 280
Join Date: May 2007
Posts: 2,818
Received Thanks: 3,483
Quote:
Originally Posted by kimboy600 View Post
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 View Post
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.
lolkop is offline  
Old 12/18/2013, 14:35   #13
 
elite*gold: 0
Join Date: Apr 2011
Posts: 65
Received Thanks: 12
Quote:
Originally Posted by alpines View Post
Wow, dat AI.

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"
kimboy600 is offline  
Old 12/18/2013, 20:49   #14
 
YatoDev's Avatar
 
elite*gold: 50
Join Date: Sep 2012
Posts: 3,841
Received Thanks: 1,462
Tic tac toe source code with KI
YatoDev is offline  
Old 03/24/2014, 18:43   #15
 
elite*gold: 0
Join Date: Jun 2010
Posts: 85
Received Thanks: 11
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
umair86 is offline  
Reply


Similar Threads Similar Threads
WTT FireFall Beta Key Or Smite Beta Key For Path Of Exile Beta key!
07/10/2014 - Smite Trading - 1 Replies
WTT FireFall Beta Key Or Smite Beta Key For Path Of Exile Beta key! Pm me if intressted
[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...
WTT My Firefall Beta Key+Smite Beta Key For 1 Path Of Exile Beta Key
08/02/2012 - Path of Exile Trading - 0 Replies
Hello i wanna trade my Firefall beta key and Smite Beta Key For 1 Path Of Exile beta key.. Pm Me If intressted :)
[BETA]VERKAUFE METIN2 BETA ACCOUNT[BETA]
01/19/2011 - Metin2 Trading - 1 Replies
Ja sorry wusste ich nicht... Closed..



All times are GMT +2. The time now is 18:19.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.