13 Replies - 3815 Views - Last Post: 15 January 2007 - 04:32 PM Rate Topic: -----

#1 barbd1969  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 13-January 07

NEED HELP with VB.NET code for game like tic tac toe

Posted 14 January 2007 - 06:54 PM

Hi,

This is my first attemp at posting a question for help. I'm an IT student and I have very limited experience with programming. I am currently enrolled in a VB.NET programming class where our first project is to program a game of Tic Tac Techno which is like tic tac toe but on a 4x4 grid instead of a 3x3 grid. This is intended to be a one player game and the alternate move is programmed in to the code.

The game seems to work properly with one little glitch, (which is actually really big) sometimes when a box is chosen (which marks it with an X) it sometimes results in more than one O (computer move). I have proofed my code and can't seem to find any errors. I'm sure there is a simple solution to this, but being so new to this it's not so simple to me.

I know this is a lot of code to post, but I'm sure it's the only way you can really see what I may be doing wrong or what I'm missing. I'm also going to add it in as an attachment. Not sure which way is better, so I'll cover all the bases.

Thank you in acvance for your time and effort.
Barb


Public Class TicTacTechno

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, _
Button3.Click, Button4.Click, Button5.Click, Button6.Click, Button7.Click, Button8.Click, Button9.Click, Button10.Click, _
Button11.Click, Button12.Click, Button13.Click, Button14.Click, Button15.Click, Button16.Click

If sender.text = "" Then
sender.text = "X"
End If

If Button1.Text = "X" And Button6.Text = "" Then
Button6.Text = "O"
ElseIf Button1.Text = "X" And Button6.Text = "X" And Button7.Text = "" Then
Button7.Text = "O"
ElseIf Button1.Text = "X" And Button7.Text = "X" And Button8.Text = "" Then
Button8.Text = "O"
ElseIf Button1.Text = "X" And Button8.Text = "X" And Button9.Text = "" Then
Button9.Text = "O"
ElseIf Button1.Text = "X" And Button9.Text = "X" And Button10.Text = "" Then
Button10.Text = "O"
ElseIf Button1.Text = "X" And Button10.Text = "X" And Button11.Text = "" Then
Button11.Text = "O"
ElseIf Button1.Text = "X" And Button11.Text = "X" And Button12.Text = "" Then
Button12.Text = "O"
ElseIf Button1.Text = "X" And Button12.Text = "X" And Button13.Text = "" Then
Button13.Text = "O"
ElseIf Button1.Text = "X" And Button13.Text = "X" And Button14.Text = "" Then
Button14.Text = "O"
ElseIf Button1.Text = "X" And Button14.Text = "X" And Button15.Text = "" Then
Button15.Text = "O"
ElseIf Button1.Text = "X" And Button15.Text = "X" And Button16.Text = "" Then
Button16.Text = "O"
ElseIf Button1.Text = "X" And Button16.Text = "X" And Button2.Text = "" Then
Button2.Text = "O"
ElseIf Button1.Text = "X" And Button2.Text = "X" And Button3.Text = "" Then
Button3.Text = "O"
ElseIf Button1.Text = "X" And Button3.Text = "X" And Button4.Text = "" Then
Button4.Text = "O"
ElseIf Button1.Text = "X" And Button4.Text = "X" And Button5.Text = "" Then
Button5.Text = "O"
End If

If Button2.Text = "X" And Button14.Text = "" Then
Button14.Text = "O"
ElseIf Button2.Text = "X" And Button14.Text = "X" And Button7.Text = "" Then
Button7.Text = "O"
ElseIf Button2.Text = "X" And Button7.Text = "X" And Button8.Text = "" Then
Button8.Text = "O"
ElseIf Button2.Text = "X" And Button8.Text = "X" And Button9.Text = "" Then
Button9.Text = "O"
ElseIf Button2.Text = "X" And Button9.Text = "X" And Button10.Text = "" Then
Button10.Text = "O"
ElseIf Button2.Text = "X" And Button10.Text = "X" And Button11.Text = "" Then
Button11.Text = "O"
ElseIf Button2.Text = "X" And Button11.Text = "X" And Button12.Text = "" Then
Button12.Text = "O"
ElseIf Button2.Text = "X" And Button12.Text = "X" And Button13.Text = "" Then
Button13.Text = "O"
ElseIf Button2.Text = "X" And Button13.Text = "X" And Button14.Text = "" Then
Button14.Text = "O"
ElseIf Button2.Text = "X" And Button14.Text = "X" And Button15.Text = "" Then
Button15.Text = "O"
ElseIf Button2.Text = "X" And Button15.Text = "X" And Button16.Text = "" Then
Button16.Text = "O"
ElseIf Button2.Text = "X" And Button16.Text = "X" And Button1.Text = "" Then
Button1.Text = "O"
ElseIf Button2.Text = "X" And Button1.Text = "X" And Button3.Text = "" Then
Button3.Text = "O"
ElseIf Button2.Text = "X" And Button3.Text = "X" And Button4.Text = "" Then
Button4.Text = "O"
ElseIf Button2.Text = "X" And Button4.Text = "X" And Button5.Text = "" Then
Button5.Text = "O"
End If

If Button3.Text = "X" And Button5.Text = "" Then
Button5.Text = "O"
ElseIf Button3.Text = "X" And Button5.Text = "X" And Button7.Text = "" Then
Button7.Text = "O"
ElseIf Button3.Text = "X" And Button7.Text = "X" And Button8.Text = "" Then
Button8.Text = "O"
ElseIf Button3.Text = "X" And Button8.Text = "X" And Button9.Text = "" Then
Button9.Text = "O"
ElseIf Button3.Text = "X" And Button9.Text = "X" And Button10.Text = "" Then
Button10.Text = "O"
ElseIf Button3.Text = "X" And Button10.Text = "X" And Button11.Text = "" Then
Button11.Text = "O"
ElseIf Button3.Text = "X" And Button11.Text = "X" And Button12.Text = "" Then
Button12.Text = "O"
ElseIf Button3.Text = "X" And Button12.Text = "X" And Button13.Text = "" Then
Button13.Text = "O"
ElseIf Button3.Text = "X" And Button13.Text = "X" And Button14.Text = "" Then
Button14.Text = "O"
ElseIf Button3.Text = "X" And Button14.Text = "X" And Button15.Text = "" Then
Button15.Text = "O"
ElseIf Button3.Text = "X" And Button15.Text = "X" And Button16.Text = "" Then
Button16.Text = "O"
ElseIf Button3.Text = "X" And Button16.Text = "X" And Button1.Text = "" Then
Button1.Text = "O"
ElseIf Button3.Text = "X" And Button1.Text = "X" And Button2.Text = "" Then
Button2.Text = "O"
ElseIf Button3.Text = "X" And Button2.Text = "X" And Button4.Text = "" Then
Button4.Text = "O"
ElseIf Button3.Text = "X" And Button4.Text = "X" And Button6.Text = "" Then
Button6.Text = "O"
End If

If Button4.Text = "X" And Button16.Text = "" Then
Button16.Text = "O"
ElseIf Button4.Text = "X" And Button16.Text = "X" And Button7.Text = "" Then
Button7.Text = "O"
ElseIf Button4.Text = "X" And Button7.Text = "X" And Button8.Text = "" Then
Button8.Text = "O"
ElseIf Button4.Text = "X" And Button8.Text = "X" And Button9.Text = "" Then
Button9.Text = "O"
ElseIf Button4.Text = "X" And Button9.Text = "X" And Button10.Text = "" Then
Button10.Text = "O"
ElseIf Button4.Text = "X" And Button10.Text = "X" And Button11.Text = "" Then
Button11.Text = "O"
ElseIf Button4.Text = "X" And Button11.Text = "X" And Button12.Text = "" Then
Button12.Text = "O"
ElseIf Button4.Text = "X" And Button12.Text = "X" And Button13.Text = "" Then
Button13.Text = "O"
ElseIf Button4.Text = "X" And Button13.Text = "X" And Button14.Text = "" Then
Button14.Text = "O"
ElseIf Button4.Text = "X" And Button14.Text = "X" And Button15.Text = "" Then
Button15.Text = "O"
ElseIf Button4.Text = "X" And Button15.Text = "X" And Button1.Text = "" Then
Button1.Text = "O"
ElseIf Button4.Text = "X" And Button1.Text = "X" And Button2.Text = "" Then
Button2.Text = "O"
ElseIf Button4.Text = "X" And Button2.Text = "X" And Button3.Text = "" Then
Button3.Text = "O"
ElseIf Button4.Text = "X" And Button3.Text = "X" And Button5.Text = "" Then
Button5.Text = "O"
ElseIf Button4.Text = "X" And Button5.Text = "X" And Button6.Text = "" Then
Button6.Text = "O"
End If

If Button5.Text = "X" And Button2.Text = "" Then
Button2.Text = "O"
ElseIf Button5.Text = "X" And Button2.Text = "X" And Button7.Text = "" Then
Button7.Text = "O"
ElseIf Button5.Text = "X" And Button7.Text = "X" And Button8.Text = "" Then
Button8.Text = "O"
ElseIf Button5.Text = "X" And Button8.Text = "X" And Button9.Text = "" Then
Button9.Text = "O"
ElseIf Button5.Text = "X" And Button9.Text = "X" And Button10.Text = "" Then
Button10.Text = "O"
ElseIf Button5.Text = "X" And Button10.Text = "X" And Button11.Text = "" Then
Button11.Text = "O"
ElseIf Button5.Text = "X" And Button11.Text = "X" And Button12.Text = "" Then
Button12.Text = "O"
ElseIf Button5.Text = "X" And Button12.Text = "X" And Button13.Text = "" Then
Button13.Text = "O"
ElseIf Button5.Text = "X" And Button13.Text = "X" And Button14.Text = "" Then
Button14.Text = "O"
ElseIf Button5.Text = "X" And Button14.Text = "X" And Button15.Text = "" Then
Button15.Text = "O"
ElseIf Button5.Text = "X" And Button15.Text = "X" And Button16.Text = "" Then
Button16.Text = "O"
ElseIf Button5.Text = "X" And Button16.Text = "X" And Button1.Text = "" Then
Button1.Text = "O"
ElseIf Button5.Text = "X" And Button1.Text = "X" And Button3.Text = "" Then
Button3.Text = "O"
ElseIf Button5.Text = "X" And Button3.Text = "X" And Button4.Text = "" Then
Button4.Text = "O"
ElseIf Button5.Text = "X" And Button4.Text = "X" And Button6.Text = "" Then
Button6.Text = "O"
End If

If Button6.Text = "X" And Button13.Text = "" Then
Button13.Text = "O"
ElseIf Button6.Text = "X" And Button13.Text = "X" And Button7.Text = "" Then
Button7.Text = "O"
ElseIf Button6.Text = "X" And Button7.Text = "X" And Button8.Text = "" Then
Button8.Text = "O"
ElseIf Button6.Text = "X" And Button8.Text = "X" And Button9.Text = "" Then
Button9.Text = "O"
ElseIf Button6.Text = "X" And Button9.Text = "X" And Button10.Text = "" Then
Button10.Text = "O"
ElseIf Button6.Text = "X" And Button10.Text = "X" And Button11.Text = "" Then
Button11.Text = "O"
ElseIf Button6.Text = "X" And Button11.Text = "X" And Button12.Text = "" Then
Button12.Text = "O"
ElseIf Button6.Text = "X" And Button12.Text = "X" And Button1.Text = "" Then
Button1.Text = "O"
ElseIf Button6.Text = "X" And Button1.Text = "X" And Button14.Text = "" Then
Button14.Text = "O"
ElseIf Button6.Text = "X" And Button14.Text = "X" And Button15.Text = "" Then
Button15.Text = "O"
ElseIf Button6.Text = "X" And Button15.Text = "X" And Button16.Text = "" Then
Button16.Text = "O"
ElseIf Button6.Text = "X" And Button16.Text = "X" And Button2.Text = "" Then
Button2.Text = "O"
ElseIf Button6.Text = "X" And Button2.Text = "X" And Button3.Text = "" Then
Button3.Text = "O"
ElseIf Button6.Text = "X" And Button3.Text = "X" And Button4.Text = "" Then
Button4.Text = "O"
ElseIf Button6.Text = "X" And Button4.Text = "X" And Button5.Text = "" Then
Button5.Text = "O"
End If

If Button7.Text = "X" And Button9.Text = "" Then
Button9.Text = "O"
ElseIf Button7.Text = "X" And Button9.Text = "X" And Button1.Text = "" Then
Button1.Text = "O"
ElseIf Button7.Text = "X" And Button1.Text = "X" And Button8.Text = "" Then
Button8.Text = "O"
ElseIf Button7.Text = "X" And Button8.Text = "X" And Button6.Text = "" Then
Button6.Text = "O"
ElseIf Button7.Text = "X" And Button6.Text = "X" And Button10.Text = "" Then
Button10.Text = "O"
ElseIf Button7.Text = "X" And Button10.Text = "X" And Button11.Text = "" Then
Button11.Text = "O"
ElseIf Button7.Text = "X" And Button11.Text = "X" And Button12.Text = "" Then
Button12.Text = "O"
ElseIf Button7.Text = "X" And Button12.Text = "X" And Button13.Text = "" Then
Button13.Text = "O"
ElseIf Button7.Text = "X" And Button13.Text = "X" And Button14.Text = "" Then
Button14.Text = "O"
ElseIf Button7.Text = "X" And Button14.Text = "X" And Button15.Text = "" Then
Button15.Text = "O"
ElseIf Button7.Text = "X" And Button15.Text = "X" And Button16.Text = "" Then
Button16.Text = "O"
ElseIf Button7.Text = "X" And Button16.Text = "X" And Button2.Text = "" Then
Button2.Text = "O"
ElseIf Button7.Text = "X" And Button2.Text = "X" And Button3.Text = "" Then
Button3.Text = "O"
ElseIf Button7.Text = "X" And Button3.Text = "X" And Button4.Text = "" Then
Button4.Text = "O"
ElseIf Button7.Text = "X" And Button4.Text = "X" And Button5.Text = "" Then
Button5.Text = "O"
End If

If Button8.Text = "X" And Button15.Text = "" Then
Button15.Text = "O"
ElseIf Button8.Text = "X" And Button15.Text = "X" And Button7.Text = "" Then
Button7.Text = "O"
ElseIf Button8.Text = "X" And Button7.Text = "X" And Button1.Text = "" Then
Button1.Text = "O"
ElseIf Button8.Text = "X" And Button1.Text = "X" And Button9.Text = "" Then
Button9.Text = "O"
ElseIf Button8.Text = "X" And Button9.Text = "X" And Button10.Text = "" Then
Button10.Text = "O"
ElseIf Button8.Text = "X" And Button10.Text = "X" And Button11.Text = "" Then
Button11.Text = "O"
ElseIf Button8.Text = "X" And Button11.Text = "X" And Button12.Text = "" Then
Button12.Text = "O"
ElseIf Button8.Text = "X" And Button12.Text = "X" And Button13.Text = "" Then
Button13.Text = "O"
ElseIf Button8.Text = "X" And Button13.Text = "X" And Button14.Text = "" Then
Button14.Text = "O"
ElseIf Button8.Text = "X" And Button14.Text = "X" And Button6.Text = "" Then
Button6.Text = "O"
ElseIf Button8.Text = "X" And Button6.Text = "X" And Button16.Text = "" Then
Button16.Text = "O"
ElseIf Button8.Text = "X" And Button16.Text = "X" And Button2.Text = "" Then
Button2.Text = "O"
ElseIf Button8.Text = "X" And Button2.Text = "X" And Button3.Text = "" Then
Button3.Text = "O"
ElseIf Button8.Text = "X" And Button3.Text = "X" And Button4.Text = "" Then
Button4.Text = "O"
ElseIf Button8.Text = "X" And Button4.Text = "X" And Button5.Text = "" Then
Button5.Text = "O"
End If

If Button9.Text = "X" And Button1.Text = "" Then
Button1.Text = "O"
ElseIf Button9.Text = "X" And Button1.Text = "X" And Button7.Text = "" Then
Button7.Text = "O"
ElseIf Button9.Text = "X" And Button7.Text = "X" And Button8.Text = "" Then
Button8.Text = "O"
ElseIf Button9.Text = "X" And Button8.Text = "X" And Button6.Text = "" Then
Button6.Text = "O"
ElseIf Button9.Text = "X" And Button6.Text = "X" And Button10.Text = "" Then
Button10.Text = "O"
ElseIf Button9.Text = "X" And Button10.Text = "X" And Button11.Text = "" Then
Button11.Text = "O"
ElseIf Button9.Text = "X" And Button11.Text = "X" And Button12.Text = "" Then
Button12.Text = "O"
ElseIf Button9.Text = "X" And Button12.Text = "X" And Button13.Text = "" Then
Button13.Text = "O"
ElseIf Button9.Text = "X" And Button13.Text = "X" And Button14.Text = "" Then
Button14.Text = "O"
ElseIf Button9.Text = "X" And Button14.Text = "X" And Button15.Text = "" Then
Button15.Text = "O"
ElseIf Button9.Text = "X" And Button15.Text = "X" And Button16.Text = "" Then
Button16.Text = "O"
ElseIf Button9.Text = "X" And Button16.Text = "X" And Button2.Text = "" Then
Button2.Text = "O"
ElseIf Button9.Text = "X" And Button2.Text = "X" And Button3.Text = "" Then
Button3.Text = "O"
ElseIf Button9.Text = "X" And Button3.Text = "X" And Button4.Text = "" Then
Button4.Text = "O"
ElseIf Button9.Text = "X" And Button4.Text = "X" And Button5.Text = "" Then
Button5.Text = "O"
End If

If Button10.Text = "X" And Button4.Text = "" Then
Button4.Text = "O"
ElseIf Button10.Text = "X" And Button4.Text = "X" And Button7.Text = "" Then
Button7.Text = "O"
ElseIf Button10.Text = "X" And Button7.Text = "X" And Button8.Text = "" Then
Button8.Text = "O"
ElseIf Button10.Text = "X" And Button8.Text = "X" And Button9.Text = "" Then
Button9.Text = "O"
ElseIf Button10.Text = "X" And Button9.Text = "X" And Button1.Text = "" Then
Button1.Text = "O"
ElseIf Button10.Text = "X" And Button1.Text = "X" And Button11.Text = "" Then
Button11.Text = "O"
ElseIf Button10.Text = "X" And Button11.Text = "X" And Button12.Text = "" Then
Button12.Text = "O"
ElseIf Button10.Text = "X" And Button12.Text = "X" And Button13.Text = "" Then
Button13.Text = "O"
ElseIf Button10.Text = "X" And Button13.Text = "X" And Button14.Text = "" Then
Button14.Text = "O"
ElseIf Button10.Text = "X" And Button14.Text = "X" And Button15.Text = "" Then
Button15.Text = "O"
ElseIf Button10.Text = "X" And Button15.Text = "X" And Button16.Text = "" Then
Button16.Text = "O"
ElseIf Button10.Text = "X" And Button16.Text = "X" And Button2.Text = "" Then
Button2.Text = "O"
ElseIf Button10.Text = "X" And Button2.Text = "X" And Button3.Text = "" Then
Button3.Text = "O"
ElseIf Button10.Text = "X" And Button3.Text = "X" And Button6.Text = "" Then
Button6.Text = "O"
ElseIf Button10.Text = "X" And Button6.Text = "X" And Button5.Text = "" Then
Button5.Text = "O"
End If

If Button11.Text = "X" And Button8.Text = "" Then
Button8.Text = "O"
ElseIf Button11.Text = "X" And Button8.Text = "X" And Button7.Text = "" Then
Button7.Text = "O"
ElseIf Button11.Text = "X" And Button7.Text = "X" And Button6.Text = "" Then
Button6.Text = "O"
ElseIf Button11.Text = "X" And Button6.Text = "X" And Button9.Text = "" Then
Button9.Text = "O"
ElseIf Button11.Text = "X" And Button9.Text = "X" And Button10.Text = "" Then
Button10.Text = "O"
ElseIf Button11.Text = "X" And Button10.Text = "X" And Button1.Text = "" Then
Button1.Text = "O"
ElseIf Button11.Text = "X" And Button1.Text = "X" And Button12.Text = "" Then
Button12.Text = "O"
ElseIf Button11.Text = "X" And Button12.Text = "X" And Button13.Text = "" Then
Button13.Text = "O"
ElseIf Button11.Text = "X" And Button13.Text = "X" And Button14.Text = "" Then
Button14.Text = "O"
ElseIf Button11.Text = "X" And Button14.Text = "X" And Button15.Text = "" Then
Button15.Text = "O"
ElseIf Button11.Text = "X" And Button15.Text = "X" And Button16.Text = "" Then
Button16.Text = "O"
ElseIf Button11.Text = "X" And Button16.Text = "X" And Button2.Text = "" Then
Button2.Text = "O"
ElseIf Button11.Text = "X" And Button2.Text = "X" And Button3.Text = "" Then
Button3.Text = "O"
ElseIf Button11.Text = "X" And Button3.Text = "X" And Button4.Text = "" Then
Button4.Text = "O"
ElseIf Button11.Text = "X" And Button4.Text = "X" And Button5.Text = "" Then
Button5.Text = "O"
End If

If Button12.Text = "X" And Button3.Text = "" Then
Button3.Text = "O"
ElseIf Button12.Text = "X" And Button3.Text = "X" And Button7.Text = "" Then
Button7.Text = "O"
ElseIf Button12.Text = "X" And Button7.Text = "X" And Button8.Text = "" Then
Button8.Text = "O"
ElseIf Button12.Text = "X" And Button8.Text = "X" And Button9.Text = "" Then
Button9.Text = "O"
ElseIf Button12.Text = "X" And Button9.Text = "X" And Button10.Text = "" Then
Button10.Text = "O"
ElseIf Button12.Text = "X" And Button10.Text = "X" And Button11.Text = "" Then
Button11.Text = "O"
ElseIf Button12.Text = "X" And Button11.Text = "X" And Button1.Text = "" Then
Button1.Text = "O"
ElseIf Button12.Text = "X" And Button1.Text = "X" And Button13.Text = "" Then
Button13.Text = "O"
ElseIf Button12.Text = "X" And Button13.Text = "X" And Button14.Text = "" Then
Button14.Text = "O"
ElseIf Button12.Text = "X" And Button14.Text = "X" And Button15.Text = "" Then
Button15.Text = "O"
ElseIf Button12.Text = "X" And Button15.Text = "X" And Button16.Text = "" Then
Button16.Text = "O"
ElseIf Button12.Text = "X" And Button16.Text = "X" And Button2.Text = "" Then
Button2.Text = "O"
ElseIf Button12.Text = "X" And Button2.Text = "X" And Button6.Text = "" Then
Button6.Text = "O"
ElseIf Button12.Text = "X" And Button6.Text = "X" And Button4.Text = "" Then
Button4.Text = "O"
ElseIf Button12.Text = "X" And Button4.Text = "X" And Button5.Text = "" Then
Button5.Text = "O"
End If

If Button13.Text = "X" And Button12.Text = "" Then
Button12.Text = "O"
ElseIf Button13.Text = "X" And Button12.Text = "X" And Button7.Text = "" Then
Button7.Text = "O"
ElseIf Button13.Text = "X" And Button7.Text = "X" And Button8.Text = "" Then
Button8.Text = "O"
ElseIf Button13.Text = "X" And Button8.Text = "X" And Button9.Text = "" Then
Button9.Text = "O"
ElseIf Button13.Text = "X" And Button9.Text = "X" And Button10.Text = "" Then
Button10.Text = "O"
ElseIf Button13.Text = "X" And Button10.Text = "X" And Button11.Text = "" Then
Button11.Text = "O"
ElseIf Button13.Text = "X" And Button11.Text = "X" And Button1.Text = "" Then
Button1.Text = "O"
ElseIf Button13.Text = "X" And Button1.Text = "X" And Button6.Text = "" Then
Button6.Text = "O"
ElseIf Button13.Text = "X" And Button6.Text = "X" And Button14.Text = "" Then
Button14.Text = "O"
ElseIf Button13.Text = "X" And Button14.Text = "X" And Button15.Text = "" Then
Button15.Text = "O"
ElseIf Button13.Text = "X" And Button15.Text = "X" And Button16.Text = "" Then
Button16.Text = "O"
ElseIf Button13.Text = "X" And Button16.Text = "X" And Button2.Text = "" Then
Button2.Text = "O"
ElseIf Button13.Text = "X" And Button2.Text = "X" And Button3.Text = "" Then
Button3.Text = "O"
ElseIf Button13.Text = "X" And Button3.Text = "X" And Button4.Text = "" Then
Button4.Text = "O"
ElseIf Button13.Text = "X" And Button4.Text = "X" And Button5.Text = "" Then
Button5.Text = "O"
End If

If Button14.Text = "X" And Button7.Text = "" Then
Button7.Text = "O"
ElseIf Button14.Text = "X" And Button7.Text = "X" And Button6.Text = "" Then
Button6.Text = "O"
ElseIf Button14.Text = "X" And Button6.Text = "X" And Button8.Text = "" Then
Button8.Text = "O"
ElseIf Button14.Text = "X" And Button8.Text = "X" And Button9.Text = "" Then
Button9.Text = "O"
ElseIf Button14.Text = "X" And Button9.Text = "X" And Button10.Text = "" Then
Button10.Text = "O"
ElseIf Button14.Text = "X" And Button10.Text = "X" And Button11.Text = "" Then
Button11.Text = "O"
ElseIf Button14.Text = "X" And Button11.Text = "X" And Button12.Text = "" Then
Button12.Text = "O"
ElseIf Button14.Text = "X" And Button12.Text = "X" And Button13.Text = "" Then
Button13.Text = "O"
ElseIf Button14.Text = "X" And Button13.Text = "X" And Button1.Text = "" Then
Button1.Text = "O"
ElseIf Button14.Text = "X" And Button1.Text = "X" And Button15.Text = "" Then
Button15.Text = "O"
ElseIf Button14.Text = "X" And Button15.Text = "X" And Button16.Text = "" Then
Button16.Text = "O"
ElseIf Button14.Text = "X" And Button16.Text = "X" And Button2.Text = "" Then
Button2.Text = "O"
ElseIf Button14.Text = "X" And Button2.Text = "X" And Button3.Text = "" Then
Button3.Text = "O"
ElseIf Button14.Text = "X" And Button3.Text = "X" And Button4.Text = "" Then
Button4.Text = "O"
ElseIf Button14.Text = "X" And Button4.Text = "X" And Button5.Text = "" Then
Button5.Text = "O"
End If

If Button15.Text = "X" And Button11.Text = "" Then
Button11.Text = "O"
ElseIf Button15.Text = "X" And Button11.Text = "X" And Button7.Text = "" Then
Button7.Text = "O"
ElseIf Button15.Text = "X" And Button7.Text = "X" And Button8.Text = "" Then
Button8.Text = "O"
ElseIf Button15.Text = "X" And Button8.Text = "X" And Button9.Text = "" Then
Button9.Text = "O"
ElseIf Button15.Text = "X" And Button9.Text = "X" And Button10.Text = "" Then
Button10.Text = "O"
ElseIf Button15.Text = "X" And Button10.Text = "X" And Button1.Text = "" Then
Button1.Text = "O"
ElseIf Button15.Text = "X" And Button1.Text = "X" And Button12.Text = "" Then
Button12.Text = "O"
ElseIf Button15.Text = "X" And Button12.Text = "X" And Button13.Text = "" Then
Button13.Text = "O"
ElseIf Button15.Text = "X" And Button13.Text = "X" And Button14.Text = "" Then
Button14.Text = "O"
ElseIf Button15.Text = "X" And Button14.Text = "X" And Button6.Text = "" Then
Button6.Text = "O"
ElseIf Button15.Text = "X" And Button6.Text = "X" And Button16.Text = "" Then
Button16.Text = "O"
ElseIf Button15.Text = "X" And Button16.Text = "X" And Button2.Text = "" Then
Button2.Text = "O"
ElseIf Button15.Text = "X" And Button2.Text = "X" And Button3.Text = "" Then
Button3.Text = "O"
ElseIf Button15.Text = "X" And Button3.Text = "X" And Button4.Text = "" Then
Button4.Text = "O"
ElseIf Button15.Text = "X" And Button4.Text = "X" And Button5.Text = "" Then
Button5.Text = "O"
End If

If Button16.Text = "X" And Button10.Text = "" Then
Button10.Text = "O"
ElseIf Button16.Text = "X" And Button10.Text = "X" And Button7.Text = "" Then
Button7.Text = "O"
ElseIf Button16.Text = "X" And Button7.Text = "X" And Button8.Text = "" Then
Button8.Text = "O"
ElseIf Button16.Text = "X" And Button8.Text = "X" And Button9.Text = "" Then
Button9.Text = "O"
ElseIf Button16.Text = "X" And Button9.Text = "X" And Button1.Text = "" Then
Button1.Text = "O"
ElseIf Button16.Text = "X" And Button1.Text = "X" And Button11.Text = "" Then
Button11.Text = "O"
ElseIf Button16.Text = "X" And Button11.Text = "X" And Button12.Text = "" Then
Button12.Text = "O"
ElseIf Button16.Text = "X" And Button12.Text = "X" And Button13.Text = "" Then
Button13.Text = "O"
ElseIf Button16.Text = "X" And Button13.Text = "X" And Button14.Text = "" Then
Button14.Text = "O"
ElseIf Button16.Text = "X" And Button14.Text = "X" And Button15.Text = "" Then
Button15.Text = "O"
ElseIf Button16.Text = "X" And Button15.Text = "X" And Button6.Text = "" Then
Button6.Text = "O"
ElseIf Button16.Text = "X" And Button6.Text = "X" And Button2.Text = "" Then
Button2.Text = "O"
ElseIf Button16.Text = "X" And Button2.Text = "X" And Button3.Text = "" Then
Button3.Text = "O"
ElseIf Button16.Text = "X" And Button3.Text = "X" And Button4.Text = "" Then
Button4.Text = "O"
ElseIf Button16.Text = "X" And Button4.Text = "X" And Button5.Text = "" Then
Button5.Text = "O"
End If

If Button1.Text = "X" And Button2.Text = "X" And Button3.Text = "X" And Button4.Text = "X" _
Or Button5.Text = "X" And Button6.Text = "X" And Button7.Text = "X" And Button8.Text = "X" _
Or Button9.Text = "X" And Button10.Text = "X" And Button11.Text = "X" And Button12.Text = "X" _
Or Button13.Text = "X" And Button14.Text = "X" And Button15.Text = "X" And Button16.Text = "X" _
Or Button1.Text = "X" And Button5.Text = "X" And Button9.Text = "X" And Button13.Text = "X" _
Or Button2.Text = "X" And Button6.Text = "X" And Button10.Text = "X" And Button14.Text = "X" _
Or Button3.Text = "X" And Button7.Text = "X" And Button11.Text = "X" And Button15.Text = "X" _
Or Button4.Text = "X" And Button8.Text = "X" And Button9.Text = "X" And Button10.Text = "X" _
Or Button1.Text = "X" And Button6.Text = "X" And Button11.Text = "X" And Button16.Text = "X" _
Or Button4.Text = "X" And Button7.Text = "X" And Button10.Text = "X" And Button13.Text = "X" Then
MessageBox.Show("X has won!")
End If
If Button1.Text = "O" And Button2.Text = "O" And Button3.Text = "O" And Button4.Text = "O" _
Or Button5.Text = "O" And Button6.Text = "O" And Button7.Text = "O" And Button8.Text = "O" _
Or Button9.Text = "O" And Button10.Text = "O" And Button11.Text = "O" And Button12.Text = "O" _
Or Button13.Text = "O" And Button14.Text = "O" And Button15.Text = "O" And Button16.Text = "O" _
Or Button1.Text = "O" And Button5.Text = "O" And Button9.Text = "O" And Button13.Text = "O" _
Or Button2.Text = "O" And Button6.Text = "O" And Button10.Text = "O" And Button14.Text = "O" _
Or Button3.Text = "O" And Button7.Text = "O" And Button11.Text = "O" And Button15.Text = "O" _
Or Button4.Text = "O" And Button8.Text = "O" And Button9.Text = "O" And Button10.Text = "O" _
Or Button1.Text = "O" And Button6.Text = "O" And Button11.Text = "O" And Button16.Text = "O" _
Or Button4.Text = "O" And Button7.Text = "O" And Button10.Text = "O" And Button13.Text = "O" Then
MessageBox.Show("O has won!")
End If


End Sub

Private Sub TicTacTechno_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub
End Class

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: NEED HELP with VB.NET code for game like tic tac toe

#2 KeyWiz  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 8
  • View blog
  • Posts: 438
  • Joined: 26-October 06

Re: NEED HELP with VB.NET code for game like tic tac toe

Posted 14 January 2007 - 07:05 PM

I'ld say it's somewhere in the IF-Then statements. LOL

Look at Tic Tac Toe topic from earlier this month.

even if an early If-Then is executed, so are any following If-Thens unless you redirect it after the computer makes it's move.
Was This Post Helpful? 0
  • +
  • -

#3 barbd1969  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 13-January 07

Re: NEED HELP with VB.NET code for game like tic tac toe

Posted 15 January 2007 - 05:32 AM

View PostKeyWiz, on 14 Jan, 2007 - 07:05 PM, said:

I'ld say it's somewhere in the IF-Then statements. LOL

Look at Tic Tac Toe topic from earlier this month.

even if an early If-Then is executed, so are any following If-Thens unless you redirect it after the computer makes it's move.



I already looked at the tic tac toe topic and all it really did was confuse me more....LOL.

I understand what you're saying about all of the if-then statements being executed, so how would I redirect it?

This post has been edited by barbd1969: 15 January 2007 - 05:35 AM

Was This Post Helpful? 0
  • +
  • -

#4 orangeslide8  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 203
  • Joined: 29-December 06

Re: NEED HELP with VB.NET code for game like tic tac toe

Posted 15 January 2007 - 06:02 AM

Does the tic tac toe game have to have a smart AI
If Not then you can just have if There are three in a row like this
[code]
If Button1.Text = Button2.Text And Button2.Text = Button3.Text And Button4.Text = Button5.Text Then
' What ever you want to do
then for all other possibilities Randomly Pick a box to go in like this
[code]
Private sub Random()
Randomize ()
Dim WhichBox as integer
Randomize()
WhichBox = Int(Rnd() * 15) + 1
' Then set mychoice1 As The button You want To dislplay O in.


John

This post has been edited by orangeslide8: 15 January 2007 - 06:03 AM

Was This Post Helpful? 0
  • +
  • -

#5 m2s87  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 21
  • View blog
  • Posts: 390
  • Joined: 28-November 06

Re: NEED HELP with VB.NET code for game like tic tac toe

Posted 15 January 2007 - 06:08 AM

View Postbarbd1969, on 15 Jan, 2007 - 05:32 AM, said:

View PostKeyWiz, on 14 Jan, 2007 - 07:05 PM, said:

I'ld say it's somewhere in the IF-Then statements. LOL

Look at Tic Tac Toe topic from earlier this month.

even if an early If-Then is executed, so are any following If-Thens unless you redirect it after the computer makes it's move.



I already looked at the tic tac toe topic and all it really did was confuse me more....LOL.

I understand what you're saying about all of the if-then statements being executed, so how would I redirect it?

I guess :blink:

If i understand correctly, you tried to write Al to 4x4 tictactoe. And you wrote a defensive 1 that probably would never win.

You can use goto label in every if, if you want to continue what you started, like you were.

Or you could use
		If Button1.Text = "X" And Button6.Text = "" Then
			Button6.Text = "O"
		Else 'insert your next if on the next line

		end if 'at the end


Was This Post Helpful? 0
  • +
  • -

#6 barbd1969  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 13-January 07

Re: NEED HELP with VB.NET code for game like tic tac toe

Posted 15 January 2007 - 06:16 AM

View Postorangeslide8, on 15 Jan, 2007 - 06:02 AM, said:

Does the tic tac toe game have to have a smart AI
If Not then you can just have if There are three in a row like this
[code]
If Button1.Text = Button2.Text And Button2.Text = Button3.Text And Button4.Text = Button5.Text Then
' What ever you want to do
then for all other possibilities Randomly Pick a box to go in like this
[code]
Private sub Random()
Randomize ()
Dim WhichBox as integer
Randomize()
WhichBox = Int(Rnd() * 15) + 1
' Then set mychoice1 As The button You want To dislplay O in.


John


I'm not quite following you completely here, but I already tried something like that and it doesn't work. Isn't that what you would do for a 2 player game?
In the one I'm doing, the player makes the first and all consecutive odd moves, which triggers the second and all consecutive even moves. (I guess that's what you probably mean by AI, right?)
Was This Post Helpful? 0
  • +
  • -

#7 barbd1969  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 13-January 07

Re: NEED HELP with VB.NET code for game like tic tac toe

Posted 15 January 2007 - 06:23 AM

View Postm2s87, on 15 Jan, 2007 - 06:08 AM, said:

View Postbarbd1969, on 15 Jan, 2007 - 05:32 AM, said:

View PostKeyWiz, on 14 Jan, 2007 - 07:05 PM, said:

I'ld say it's somewhere in the IF-Then statements. LOL

Look at Tic Tac Toe topic from earlier this month.

even if an early If-Then is executed, so are any following If-Thens unless you redirect it after the computer makes it's move.



I already looked at the tic tac toe topic and all it really did was confuse me more....LOL.

I understand what you're saying about all of the if-then statements being executed, so how would I redirect it?

I guess :blink:

If i understand correctly, you tried to write Al to 4x4 tictactoe. And you wrote a defensive 1 that probably would never win.

You can use goto label in every if, if you want to continue what you started, like you were.

Or you could use
		If Button1.Text = "X" And Button6.Text = "" Then
			Button6.Text = "O"
		Else 'insert your next if on the next line

		end if 'at the end



It's not a defensive one that will never win, if you look at the code, I followed the same path for each else-if.

if I use goto will this stop it from checking every else-if statement?

As for the code you wrote here, that is what I did....isn't it? :huh:
Was This Post Helpful? 0
  • +
  • -

#8 m2s87  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 21
  • View blog
  • Posts: 390
  • Joined: 28-November 06

Re: NEED HELP with VB.NET code for game like tic tac toe

Posted 15 January 2007 - 06:30 AM

Quote

It's not a defensive one that will never win, if you look at the code, I followed the same path for each else-if.

if I use goto will this stop it from checking every else-if statement?

As for the code you wrote here, that is what I did....isn't it? :huh:

Using goto label would help, and yes using a if else end if would also work.
Was This Post Helpful? 0
  • +
  • -

#9 Mach1Guy  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 89
  • Joined: 04-December 06

Re: NEED HELP with VB.NET code for game like tic tac toe

Posted 15 January 2007 - 06:41 AM

barbd,
i recently programmed a tic tac toe game. for the AI what i did was first check if the computer player was in a position to win, if so i would have the AI score the win. by this i mean if the computer had 2 O's in a row, then the AI would place a O in the 3rd spot to for the win.
then if there were not 2 computer O's in a row, i would check to see if there were 2 computer X's in a row, so that the computer could block the win. if there were not 2 O's or 2 X's in a row, i would have the computer select a completely random square to go. doing this allowed for a different game everytime. if you program logic such as
If Button1.Text = "X" And Button6.Text = "" Then
Button6.Text = "O"
then everytime the user select button1 the computer will do that exact same thing everytime.

1. check for computer win
2. check for block human win
3. go in random spot

basically i wrote a method/function for each of these and returned a bool from them. so if checkComputerWin() == false then i would call checkBlockHuman() and so forth. let me know if this helps any

This post has been edited by Mach1Guy: 15 January 2007 - 06:42 AM

Was This Post Helpful? 0
  • +
  • -

#10 barbd1969  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 13-January 07

Re: NEED HELP with VB.NET code for game like tic tac toe

Posted 15 January 2007 - 06:50 AM

View PostMach1Guy, on 15 Jan, 2007 - 06:41 AM, said:

barbd,
i recently programmed a tic tac toe game. for the AI what i did was first check if the computer player was in a position to win, if so i would have the AI score the win. by this i mean if the computer had 2 O's in a row, then the AI would place a O in the 3rd spot to for the win.
then if there were not 2 computer O's in a row, i would check to see if there were 2 computer X's in a row, so that the computer could block the win. if there were not 2 O's or 2 X's in a row, i would have the computer select a completely random square to go. doing this allowed for a different game everytime. if you program logic such as
If Button1.Text = "X" And Button6.Text = "" Then
Button6.Text = "O"
then everytime the user select button1 the computer will do that exact same thing everytime.

1. check for computer win
2. check for block human win
3. go in random spot

basically i wrote a method/function for each of these and returned a bool from them. so if checkComputerWin() == false then i would call checkBlockHuman() and so forth. let me know if this helps any


Thank you, but no, this doesn't help. Our professor does not want us to do a "smart" AI game, just the basic I go here, the puter goes there....etc.
Was This Post Helpful? 0
  • +
  • -

#11 orangeslide8  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 203
  • Joined: 29-December 06

Re: NEED HELP with VB.NET code for game like tic tac toe

Posted 15 January 2007 - 07:04 AM

View Postbarbd1969, on 15 Jan, 2007 - 06:50 AM, said:

View PostMach1Guy, on 15 Jan, 2007 - 06:41 AM, said:

barbd,
i recently programmed a tic tac toe game. for the AI what i did was first check if the computer player was in a position to win, if so i would have the AI score the win. by this i mean if the computer had 2 O's in a row, then the AI would place a O in the 3rd spot to for the win.
then if there were not 2 computer O's in a row, i would check to see if there were 2 computer X's in a row, so that the computer could block the win. if there were not 2 O's or 2 X's in a row, i would have the computer select a completely random square to go. doing this allowed for a different game everytime. if you program logic such as
If Button1.Text = "X" And Button6.Text = "" Then
Button6.Text = "O"
then everytime the user select button1 the computer will do that exact same thing everytime.

1. check for computer win
2. check for block human win
3. go in random spot

basically i wrote a method/function for each of these and returned a bool from them. so if checkComputerWin() == false then i would call checkBlockHuman() and so forth. let me know if this helps any


Thank you, but no, this doesn't help. Our professor does not want us to do a "smart" AI game, just the basic I go here, the puter goes there....etc.

yes this is what i was trying to tell you
Was This Post Helpful? 0
  • +
  • -

#12 barbd1969  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 13-January 07

Re: NEED HELP with VB.NET code for game like tic tac toe

Posted 15 January 2007 - 07:22 AM

View Postm2s87, on 15 Jan, 2007 - 06:30 AM, said:

Quote

It's not a defensive one that will never win, if you look at the code, I followed the same path for each else-if.

if I use goto will this stop it from checking every else-if statement?

As for the code you wrote here, that is what I did....isn't it? :huh:

Using goto label would help, and yes using a if else end if would also work.


This is my 4th day straigt working on this for at least 8 hours a day (I work full time too :rolleyes: ) and I'm getting pretty fried. can you help me out with an example of wht you mean by if else end if. Would I have to reprogram everything I've already done? Or do I just need to change some of my else if's to ifs?

How would I do a goto? I've never used one or even seen one in any of the tutorials I've done so far.

This post has been edited by barbd1969: 15 January 2007 - 07:24 AM

Was This Post Helpful? 0
  • +
  • -

#13 barbd1969  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 13-January 07

Re: NEED HELP with VB.NET code for game like tic tac toe

Posted 15 January 2007 - 03:41 PM

View PostKeyWiz, on 14 Jan, 2007 - 07:05 PM, said:

I'ld say it's somewhere in the IF-Then statements. LOL

Look at Tic Tac Toe topic from earlier this month.

even if an early If-Then is executed, so are any following If-Thens unless you redirect it after the computer makes it's move.


How do I redirect it? Do I need to asign turns? How would I do that for a 1 player game?
Was This Post Helpful? 0
  • +
  • -

#14 KeyWiz  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 8
  • View blog
  • Posts: 438
  • Joined: 26-October 06

Re: NEED HELP with VB.NET code for game like tic tac toe

Posted 15 January 2007 - 04:32 PM

I revived the thread that orangeslide8 and I worked on earlier this month. You may need to read it all, all the way through to understand everthing. This is not a simple thing to learn, but that's what it's all about anyway, right?

Continue the orangeslide8 thread instead of returning to this one.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1