Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 132,655 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,174 people online right now. Registration is fast and FREE... Join Now!




problem with AI

 
Reply to this topicStart new topic

problem with AI, the AI is acting up in my VB6 tic tac toe program.

Rating  4
jakerman999
post 8 Aug, 2008 - 05:04 PM
Post #1


New D.I.C Head

*
Joined: 7 Aug, 2008
Posts: 11



Thanked 1 times
My Contributions


my programming teacher said that a tic tac toe program was a good example for a end of year project. now, after the course is over, I thought I'd try my hand at it anyway.

so far the only problem I've found is that when you click the centre button(computer/AI takes the right button) then you click the left button, the AI skips it's move.

so far, here's my code(and a whole lot of it):
vb
Dim strCurrentplayer As String
Dim strEnemyplayer As String
Dim intPlayer As Integer

Private Sub cmdMidMid_Click()
cmdMidMid.Caption = strCurrentplayer
cmdMidMid.Enabled = False
checkwin
AIMove
checkwin
End Sub
Function checkwin()
If oWin() = True Then
MsgBox "You Win!", vbokayonly, "Game Over"
newgame
End If
If xWin() = True Then
MsgBox "You Lose.", vbokayonly, "Game Over"
newgame
End If
If Cats() = True Then
MsgBox "DRAW!", vbokayonly, "Game Over"
newgame
End If
End Function

Function xWin() As Boolean
xWin = False
If cmdBottomLeft.Caption = strEnemyplayer Then
If cmdBottomMid.Caption = strEnemyplayer And cmdBottomRight.Caption = strEnemyplayer Then
xWin = True
ElseIf cmdMidLeft.Caption = strEnemyplayer And cmdTopLeft.Caption = strEnemyplayer Then
xWin = True
ElseIf cmdMidMid.Caption = strEnemyplayer And cmdTopRight.Caption = strEnemyplayer Then
xWin = True
End If
ElseIf cmdBottomRight.Caption = strEnemyplayer Then
If cmdMidMid.Caption = strEnemyplayer And cmdTopLeft.Caption = strEnemyplayer Then
xWin = True
ElseIf cmdMidRight.Caption = strEnemyplayer And cmdTopRight.Caption = strEnemyplayer Then
xWin = True
End If
ElseIf cmdMidMid.Caption = strEnemyplayer Then
If cmdMidLeft.Caption = strEnemyplayer And cmdMidRight.Caption = strEnemyplayer Then
xWin = True
ElseIf cmdBottomMid.Caption = strEnemyplayer And cmdTopMid.Caption = strEnemyplayer Then
xWin = True
End If
ElseIf cmdTopLeft.Caption = strEnemyplayer And cmdTopRight.Caption = strEnemyplayer And cmdTopMid.Caption = strEnemyplayer Then
xWin = True
Else
xWin = False
End If
End Function
Function oWin() As Boolean
oWin = False
If cmdBottomLeft.Caption = strCurrentplayer Then
If cmdBottomMid.Caption = strCurrentplayer And cmdBottomRight.Caption = strCurrentplayer Then
oWin = True
ElseIf cmdMidLeft.Caption = strCurrentplayer And cmdTopLeft.Caption = strCurrentplayer Then
oWin = True
ElseIf cmdMidMid.Caption = strCurrentplayer And cmdTopRight.Caption = strCurrentplayer Then
oWin = True
End If
ElseIf cmdBottomRight.Caption = strCurrentplayer Then
If cmdMidMid.Caption = strCurrentplayer And cmdTopLeft.Caption = strCurrentplayer Then
oWin = True
ElseIf cmdMidRight.Caption = strCurrentplayer And cmdTopRight.Caption = strCurrentplayer Then
oWin = True
End If
ElseIf cmdMidMid.Caption = strCurrentplayer Then
If cmdMidLeft.Caption = strCurrentplayer And cmdMidRight.Caption = strCurrentplayer Then
oWin = True
ElseIf cmdBottomMid.Caption = strCurrentplayer And cmdTopMid.Caption = strCurrentplayer Then
oWin = True
End If
ElseIf cmdTopLeft.Caption = strCurrentplayer And cmdTopRight.Caption = strCurrentplayer And cmdTopMid.Caption = strCurrentplayer Then
oWin = True
End If
End Function
Function Cats() As Boolean
Cats = False
If xWin() = False And oWin() = False Then
If cmdBottomLeft.Enabled = False And cmdBottomMid.Enabled = False And cmdBottomRight.Enabled = False And cmdMidLeft.Enabled = False And cmdMidMid.Enabled = False And cmdMidRight.Enabled = False And cmdTopLeft.Enabled = False And cmdTopMid.Enabled = False And cmdTopRight.Enabled = False Then
Cats = True
End If
End If
End Function
Function newgame()
cmdBottomLeft.Enabled = True
cmdBottomMid.Enabled = True
cmdBottomRight.Enabled = True
cmdMidLeft.Enabled = True
cmdMidMid.Enabled = True
cmdMidRight.Enabled = True
cmdTopLeft.Enabled = True
cmdTopMid.Enabled = True
cmdTopRight.Enabled = True
cmdBottomLeft.Caption = ""
cmdBottomMid.Caption = ""
cmdBottomRight.Caption = ""
cmdMidLeft.Caption = ""
cmdMidMid.Caption = ""
cmdMidRight.Caption = ""
cmdTopLeft.Caption = ""
cmdTopMid.Caption = ""
cmdTopRight.Caption = ""
End Function
Function AIMove()
If Cats() = False Then
If cmdBottomLeft.Caption = strEnemyplayer Then
If cmdBottomMid.Caption = strEnemyplayer And cmdBottomRight.Enabled = True Then
cmdBottomRight.Caption = strEnemyplayer
cmdBottomRight.Enabled = False
ElseIf cmdBottomRight.Caption = strEnemyplayer And cmdBottomMid.Enabled = True Then
cmdBottomMid.Caption = strEnemyplayer
cmdBottomMid.Enabled = False
ElseIf cmdMidLeft.Caption = strEnemyplayer And cmdTopLeft.Enabled = True Then
cmdTopLeft.Caption = strEnemyplayer
cmdTopLeft.Enabled = False
ElseIf cmdTopLeft.Caption = strEnemyplayer And cmdMidLeft.Enabled = True Then
cmdMidLeft.Caption = strEnemyplayer
cmdMidLeft.Enabled = False
ElseIf cmdMidMid.Caption = strEnemyplayer And cmdTopRight.Enabled = True Then
cmdTopRight.Caption = strEnemyplayer
cmdTopRight.Enabled = False
ElseIf cmdTopRight.Caption = strEnemyplayer And cmdMidMid.Enabled = True Then
cmdMidMid.Caption = strEnemyplayer
cmdMidMid.Enabled = False
End If
ElseIf cmdBottomMid.Caption = strEnemyplayer Then
If cmdBottomRight.Caption = strEnemyplayer And cmdBottomLeft.Enabled = True Then
cmdBottomLeft.Caption = strEnemyplayer
cmdBottomLeft.Enabled = False
ElseIf cmdMidMid.Caption = strEnemyplayer And cmdTopMid.Enabled = True Then
cmdTopMid.Caption = strEnemyplayer
cmdTopMid.Enabled = False
End If
ElseIf cmdBottomRight.Caption = strEnemyplayer Then
If cmdMidRight.Caption = strEnemyplayer And cmdTopRight.Enabled = True Then
cmdTopRight.Caption = strEnemyplayer
cmdTopRight.Enabled = False
ElseIf cmdTopRight.Caption = strEnemyplayer And cmdMidRight.Enabled = True Then
cmdMidRight.Caption = strEnemyplayer
cmdMidRight.Enabled = False
ElseIf cmdMidMid.Caption = strEnemyplayer And cmdTopLeft.Enabled = True Then
cmdTopLeft.Caption = strEnemyplayer
cmdTopLeft.Enabled = False
End If
ElseIf cmdMidLeft.Caption = strEnemyplayer Then
If cmdTopLeft.Caption = strEnemyplayer And cmdBottomLeft.Enabled = True Then
cmdBottomLeft.Caption = strEnemyplayer
cmdBottomLeft.Enabled = False
ElseIf cmdMidMid.Caption = strEnemyplayer And cmdMidRight.Enabled = True Then
cmdMidRight.Caption = strEnemyplayer
cmdMidRight.Enabled = False
End If
ElseIf cmdMidRight.Caption = strEnemyplayer Then
If cmdMidMid.Caption = strEnemyplayer And cmdMidLeft.Enabled = True Then
cmdMidLeft.Caption = strEnemyplayer
cmdMidLeft.Enabled = False
ElseIf cmdTopRight.Caption = strEnemyplayer And cmdBottomRight.Enabled = True Then
cmdBottomRight.Caption = strEnemyplayer
cmdBottomRight.Enabled = False
End If
ElseIf cmdTopLeft.Caption = strEnemyplayer Then
If cmdMidMid.Caption = strEnemyplayer And cmdBottomRight.Enabled = True Then
cmdBottomRight.Caption = strEnemyplayer
cmdBottomRight.Enabled = False
ElseIf cmdTopMid.Caption = strEnemyplayer And cmdTopRight.Enabled = True Then
cmdTopRight.Caption = strEnemyplayer
cmdTopRight.Enabled = False
ElseIf cmdTopRight.Caption = strEnemyplayer And cmdTopMid.Enabled = True Then
cmdTopMid.Caption = strEnemyplayer
cmdTopMid.Enabled = False
End If
ElseIf cmdTopMid.Caption = strEnemyplayer Then
If cmdTopRight.Caption = strEnemyplayer And cmdTopLeft.Enabled = True Then
cmdTopLeft.Caption = strEnemyplayer
cmdTopLeft.Enabled = False
ElseIf cmdMidMid.Caption = strEnemyplayer And cmdBottomMid.Enabled = True Then
cmdBottomMid.Caption = strEnemyplayer
cmdBottomMid.Enabled = False
End If
ElseIf cmdTopRight.Caption = strEnemyplayer And cmdMidMid.Caption = strEnemyplayer And cmdBottomLeft.Enabled = True Then
cmdBottomLeft.Caption = strEnemyplayer
cmdBottomLeft.Enabled = False
Else
If cmdMidMid.Enabled = True Then
cmdMidMid.Caption = strEnemyplayer
cmdMidMid.Enabled = False
ElseIf cmdMidLeft.Enabled = True Then
cmdMidLeft.Caption = strEnemyplayer
cmdMidLeft.Enabled = False
ElseIf cmdMidRight.Enabled = True Then
cmdMidRight.Caption = strEnemyplayer
cmdMidRight.Enabled = False
ElseIf cmdBottomMid.Enabled = True Then
cmdBottomMid.Caption = strEnemyplayer
cmdBottomMid.Enabled = False
ElseIf cmdTopMid.Enabled = True Then
cmdTopMid.Caption = strEnemyplayer
cmdTopMid.Enabled = False
ElseIf cmdTopLeft.Enabled = True Then
cmdTopLeft.Caption = strEnemyplayer
cmdTopLeft.Enabled = False
ElseIf cmdTopRight.Enabled = True Then
cmdTopRight.Caption = strEnemyplayer
cmdTopRight.Enabled = False
ElseIf cmdBottomLeft.Enabled = True Then
cmdBottomLeft.Caption = strEnemyplayer
cmdBottomLeft.Enabled = False
ElseIf cmdBottomRight.Enabled = True Then
cmdBottomRight.Caption = strEnemyplayer
cmdBottomRight.Enabled = False
End If
End If
Else
MsgBox "draw", vbokayonly, "Game Over"
End If
End Function

Private Sub cmdTopRight_Click()
cmdTopRight.Caption = strCurrentplayer
cmdTopRight.Enabled = False
If cmdTopLeft.Caption = strCurrentplayer And cmdTopMid.Enabled = True Then
cmdTopMid.Caption = strEnemyplayer
cmdTopMid.Enabled = False
ElseIf cmdTopMid.Caption = strCurrentplayer And cmdTopLeft.Enabled = True Then
cmdTopLeft.Caption = strEnemyplayer
cmdTopLeft.Enabled = False
ElseIf cmdMidRight.Caption = strCurrentplayer And cmdBottomRight.Enabled = True Then
cmdBottomRight.Caption = strEnemyplayer
cmdBottomRight.Enabled = False
ElseIf cmdBottomRight.Caption = strCurrentplayer And cmdMidRight.Enabled = True Then
cmdMidRight.Caption = strEnemyplayer
cmdMidRight.Enabled = False
ElseIf cmdMidMid.Caption = strCurrentplayer And cmdBottomLeft.Enabled = True Then
cmdBottomLeft.Caption = strEnemyplayer
cmdBottomLeft.Enabled = False
Else
checkwin
AIMove
checkwin
End If
End Sub
Private Sub cmdTopLeft_Click()
cmdTopLeft.Caption = strCurrentplayer
cmdTopLeft.Enabled = False
If cmdTopMid.Caption = strCurrentplayer And cmdTopRight.Enabled = True Then
cmdTopRight.Caption = strEnemyplayer
cmdTopRight.Enabled = False
ElseIf cmdTopRight.Caption = strCurrentplayer And cmdTopMid.Enabled = True Then
cmdTopMid.Caption = strEnemyplayer
cmdTopMid.Enabled = False
ElseIf cmdMidMid.Caption = strCurrentplayer And cmdBottomRight.Enabled = True Then
cmdBottomRight.Caption = strEnemyplayer
cmdBottomRight.Enabled = False
ElseIf cmdMidLeft.Caption = strCurrentplayer And cmdBottomLeft.Enabled = True Then
cmdBottomLeft.Caption = strEnemyplayer
cmdBottomLeft.Enabled = False
ElseIf cmdBottomLeft.Caption = strCurrentplayer And cmdMidLeft.Enabled = True Then
cmdMidLeft.Caption = strEnemyplayer
cmdMidLeft.Enabled = False
Else
checkwin
AIMove
checkwin
End If
End Sub
Private Sub cmdTopMid_Click()
cmdTopMid.Caption = strCurrentplayer
cmdTopMid.Enabled = False
If cmdTopLeft.Caption = strCurrentplayer And cmdTopRight.Enabled = True Then
cmdTopRight.Caption = strEnemyplayer
cmdTopRight.Enabled = False
ElseIf cmdTopRight.Caption = strCurrentplayer And cmdTopLeft.Enabled = True Then
cmdTopLeft.Caption = strEnemyplayer
cmdTopLeft.Enabled = False
ElseIf cmdMidMid.Caption = strCurrentplayer And cmdBottomMid.Enabled = True Then
cmdBottomMid.Caption = strEnemyplayer
cmdBottomMid.Enabled = False
Else
checkwin
AIMove
checkwin
End If
End Sub
Private Sub cmdMidLeft_Click()
cmdMidLeft.Caption = strCurrentplayer
cmdMidLeft.Enabled = False
If cmdBottomLeft.Caption = strCurrentplayer And cmdTopLeft.Enabled = True Then
cmdTopLeft.Caption = strEnemyplayer
cmdTopLeft.Enabled = False
ElseIf cmdTopLeft.Caption = strCurrentplayer And cmdBottomLeft.Enabled = True Then
cmdBottomLeft.Caption = strEnemyplayer
cmdBottomLeft.Enabled = False
ElseIf cmdMidMid.Caption = strCurrentplayer And cmdMidRight.Enabled = True Then
cmdMidRight.Caption = strEnemyplayer
cmdMidRight.Enabled = False
Else
checkwin
AIMove
checkwin
End If
End Sub
Private Sub cmdMidRight_Click()
cmdMidRight.Caption = strCurrentplayer
cmdMidRight.Enabled = False
If cmdTopRight.Caption = strCurrentplayer And cmdBottomRight.Enabled = True Then
cmdBottomRight.Caption = strEnemyplayer
cmdBottomRight.Enabled = False
ElseIf cmdBottomRight.Caption = strCurrentplayer And cmdTopRight.Enabled = True Then
cmdTopRight.Caption = strEnemyplayer
cmdTopRight.Enabled = False
ElseIf cmdMidMid.Caption = strCurrentplayer And cmdMidLeft.Enabled = True Then
cmdMidLeft.Caption = strEnemyplayer
cmdMidLeft.Enabled = False
Else
checkwin
AIMove
checkwin
End If
End Sub
Private Sub cmdBottomLeft_Click()
cmdBottomLeft.Caption = strCurrentplayer
cmdBottomLeft.Enabled = False
If cmdMidLeft.Caption = strCurrentplayer And cmdTopLeft.Enabled = True Then
cmdTopLeft.Caption = strEnemyplayer
cmdTopLeft.Enabled = False
ElseIf cmdMidLeft.Enabled = True And cmdMidLeft.Caption = strCurrentplayer Then
cmdMidLeft.Caption = strEnemyplayer
cmdMidLeft.Enabled = False
ElseIf cmdMidMid.Caption = strCurrentplayer And cmdTopRight.Enabled = True Then
cmdTopRight.Caption = strEnemyplayer
cmdTopRight.Enabled = False
ElseIf cmdBottomMid.Caption = strCurrentplayer And cmdBottomRight.Enabled = True Then
cmdBottomRight.Caption = strEnemyplayer
cmdBottomRight.Enabled = False
ElseIf cmdBottomRight.Caption = strCurrentplayer And cmdBottomMid.Enabled = True Then
cmdBottomMid.Caption = strEnemyplayer
cmdBottomMid.Enabled = False
Else
checkwin
AIMove
checkwin
End If
End Sub
Private Sub cmdBottomMid_Click()
cmdBottomMid.Caption = strCurrentplayer
cmdBottomMid.Enabled = False
If cmdBottomLeft.Caption = strCurrentplayer And cmdBottomRight.Enabled = True Then
cmdBottomRight.Caption = strEnemyplayer
cmdBottomRight.Enabled = False
ElseIf cmdBottomRight.Caption = strCurrentplayer And cmdBottomLeft.Enabled = True Then
cmdBottomLeft.Caption = strEnemyplayer
cmdBottomLeft.Enabled = False
ElseIf cmdMidMid.Caption = strCurrentplayer And cmdTopMid.Enabled = True Then
cmdTopMid.Caption = strEnemyplayer
cmdTopMid.Enabled = False
Else
checkwin
AIMove
checkwin
End If
End Sub
Private Sub cmdBottomRight_Click()
cmdBottomRight.Caption = strCurrentplayer
cmdBottomRight.Enabled = False
If cmdBottomMid.Caption = strCurrentplayer And cmdBottomLeft.Enabled = True Then
cmdBottomLeft.Caption = strEnemyplayer
cmdBottomLeft.Enabled = False
ElseIf cmdBottomLeft.Caption = strCurrentplayer And cmdBottomMid.Enabled = True Then
cmdBottomMid.Caption = strEnemyplayer
cmdBottomMid.Enabled = False
ElseIf cmdMidMid.Caption = strCurrentplayer And cmdTopLeft.Enabled = True Then
cmdTopLeft.Caption = strEnemyplayer
cmdTopLeft.Enabled = False
ElseIf cmdMidRight.Caption = strCurrentplayer And cmdTopRight.Enabled = True Then
cmdTopRight.Caption = strEnemyplayer
cmdTopRight.Enabled = False
ElseIf cmdTopRight.Caption = strCurrentplayer And cmdMidRight.Enabled = True Then
cmdMidRight.Caption = strEnemyplayer
cmdMidRight.Enabled = False
Else
checkwin
AIMove
checkwin
End If
End Sub


Private Sub Form_Load()
If MsgBox("do you wish to play as player O?", vbYesNo, "Player?") = Yes Then
strCurrentplayer = "O"
strEnemyplayer = "X"
Else
strCurrentplayer = "X"
strEnemyplayer = "O"
End If
End Sub


so far it think my error is in the AImove function or cmdMidLeft_click sub. Does anyone have a better idea as to why this error happens?
User is offlineProfile CardPM

Go to the top of the page

Arblique
post 31 Aug, 2008 - 06:06 AM
Post #2


New D.I.C Head

*
Joined: 31 Aug, 2008
Posts: 10



Thanked 1 times
My Contributions


Hi there. This isn't an answer to your AI bug but it might me useful to you nonetheless.

Looking at your code gave me a bit of a headache so i thought I'd show you how to get it all working in an a) simplified manner and cool.gif graphical appliction.

As you can see it uses a way more friendly array to hold the data for the game instead of messy Windows User Interface bits. Using an array like this means that we use for-loops to determine a win, and draw the peices, and analyse the grid for the AI.


CODE
Option Explicit                     'Always put this in.  It forces you to declare your variables which is very good practice
Dim gX As Integer                       'Two variables to hold the location data
Dim gY As Integer

Dim bRunning As Boolean                 'if this is true then the game is on.  Gets set to false to allow program exit

Dim grid(0 To 2, 0 To 2) As Byte        'This be your actual playboard.  We don't need much here so we'll use bytes
                                        'Each cell in this array will be assigned to a player id

Dim playerFinished As Boolean           'Give us a signal to set the AI going

Private Sub Form_Load()
    Dim pl As Integer                   'This will hold the winners id
    Dim temp As Integer
    
    Me.Show                             'When using do loops, the form won't show itself unless you call this!
    
    Do                                  'Start a global loop
    resetgame                           'reset the game board
    bRunning = True                     'set the game running
    
        Do                                  'Start the loop
            DoEvents                        'ALWAYS put this statement in loops! Otherwise the app will lock up
            draw                            'redraw the piccybox
            If playerFinished = True Then   'If player1 has finished...
                playerFinished = False      '...reset this switch...
                AI                          '...and get the AI to move
            End If
            pl = checkwin()                 'Check for a win
            If pl > 0 Then bRunning = False 'If we have a winner, tell the loop to quit and move to next bit o'code
        Loop While bRunning = True          'End of loop
    
        If pl > 0 Then                      'If we have a winner make a message box and handle the response
            temp = MsgBox("Player " & Str$(pl) & " won!!!", vbRetryCancel)
            If temp = 4 Then                'Retry pressed
                pl = 0
            Else
                End                         'Abort pressed
            End If
        End If
    Loop
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    End                                     'Handles a close window request
End Sub

Private Sub Form_Resize()
    Me.Height = Me.Width + 390
    picVDU.Width = Me.Width - 390
    picVDU.Height = Me.Height - (390 * 2)
    draw
End Sub

Private Sub picVDU_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    gX = Int(x / (picVDU.ScaleWidth / 3))   'These are normalized coordinates that point to the playing grid
    gY = Int(y / (picVDU.ScaleWidth / 3))   'They return 0 to 2

End Sub

Private Sub picVDU_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    If grid(gX, gY) = 0 And Shift = 0 Then             'Test that cell is free
        grid(gX, gY) = Button               'Because I haven't put the AI in for you it uses left & right mouse clicks
                                            'Left for p1 and right for p2
        playerFinished = True               'Have player1 finished
    End If
    If Shift = 1 Then
        resetgame
    End If
    
End Sub

Private Sub resetgame()
    Dim y As Byte                           'loop variables
    Dim x As Byte
    For y = 0 To 2
        For x = 0 To 2
            grid(x, y) = 0                  'set all grid cells to 0
        Next
    Next
End Sub

Private Sub draw()
    Dim td As Integer
    Dim x As Byte
    Dim y As Byte
    
    picVDU.Cls                              'clear the picturebox
    
    For x = 1 To 2                          'draw a grid
        picVDU.Line (picVDU.ScaleLeft, (picVDU.ScaleHeight / 3) * x)-(picVDU.ScaleWidth, (picVDU.ScaleHeight / 3) * x), QBColor(15)
        picVDU.Line ((picVDU.ScaleWidth / 3) * x, picVDU.ScaleTop)-((picVDU.ScaleWidth / 3) * x, picVDU.ScaleHeight), QBColor(15)
    Next
    
    
    td = Int(picVDU.ScaleWidth / 7)         'adapt a radius for circle drawing - also use for the x's
    For y = 0 To 2
        For x = 0 To 2
            Select Case grid(x, y)
                Case 1                      'O - We draw a circle in the right location and the radius we calculated earlier
                                            'The equations here allow us to resize the window - Cool ;)
                    picVDU.Circle (x * (picVDU.ScaleWidth / 3) + (picVDU.ScaleWidth / 6), y * (picVDU.ScaleHeight / 3) + (picVDU.ScaleHeight / 6)), td, QBColor(15)
                                    
                Case 2                      'X - We draw an X
                    picVDU.Line (x * (picVDU.ScaleWidth / 3) + (picVDU.ScaleWidth / 6) - td, y * (picVDU.ScaleHeight / 3) + (picVDU.ScaleHeight / 6) - td)-(x * (picVDU.ScaleWidth / 3) + (picVDU.ScaleWidth / 6) + td, y * (picVDU.ScaleHeight / 3) + (picVDU.ScaleHeight / 6) + td), QBColor(15)
                    picVDU.Line (x * (picVDU.ScaleWidth / 3) + (picVDU.ScaleWidth / 6) + td, y * (picVDU.ScaleHeight / 3) + (picVDU.ScaleHeight / 6) - td)-(x * (picVDU.ScaleWidth / 3) + (picVDU.ScaleWidth / 6) - td, y * (picVDU.ScaleHeight / 3) + (picVDU.ScaleHeight / 6) + td), QBColor(15)
            End Select
        Next
    Next
End Sub

Private Function checkwin() As Integer
    Dim p As Integer
    Dim x As Byte
    For p = 1 To 2                          'loop for each player
        For x = 0 To 2                      'loop for each column
                                            'this first bit tests the columns for a win
            If grid(x, 0) = p And grid(x, 1) = p And grid(x, 2) = p Then
                checkwin = p                'as soon as each if block detects a win it sends back the player id
                Exit Function               'and exits the function
            End If
                                            'this next bit does the rows (we can reuse the "x" to save another loop)
            If grid(0, x) = p And grid(1, x) = p And grid(2, x) = p Then
                checkwin = p
                Exit Function
            End If
        Next x
                                            'Lastly check the diaganols
        If grid(0, 0) = p And grid(1, 1) = p And grid(2, 2) = p Then
            checkwin = p
            Exit Function
        End If
            
        If grid(2, 0) = p And grid(1, 1) = p And grid(0, 2) = p Then
            checkwin = p
            Exit Function
        End If
            
    Next p
End Function

Private Sub AI()
    'Your AI goes here
End Sub



Just put a picturebox on a form and call it picVDU and cut and paste the code into the Form code bit (delete the original stuff put in by VB).

Good luck!
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 05:28AM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month