Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Tic Tac Toe - Visual Basic 6.0 help please!


  • Please log in to reply
4 replies to this topic

#1 CarmelloFellow

CarmelloFellow

  • Members
  • 3 posts
  • OFFLINE
  •  
  • Local time:11:23 AM

Posted 25 November 2013 - 11:53 AM

'Carmen
'Project Name: TTT
'Form Name: TTT
'November 11, 2013
'A program to simulate a Tic Tac Toe game
' Identify 3 stradegies for a computer to play smart
'We will program pre-determined rules for the computer
 
 
'I NEED HELP WITH THE SIMULATION AND THE END GAME PART
 
 
 
 
 
Private Sub cmdMove_Click()
Computer_Move
 
End Sub
 
Private Sub cmdReset_Click()
lblBoard(Index).Enabled = True
Dim c As Integer
    lblMove = ""
For c = 0 To 8
    lblBoard© = ""
    Next c
For c = 0 To 7
    Ln©.Visible = False
    Next c
End Sub
 
Private Sub Form_Load()
Dim c As Integer
For c = 0 To 7
    Ln©.Visible = False
Next c
lblTurn.Visible = False
lblBoard(Index).Enabled = True
 
 
End Sub
Private Sub Computer_Move()
 
'Move 1: Random corner
'Move 2: Opposite corner(if available)
'Move,3 , 4 , and 5:
'       1. check to see if X can win
'       2. if cant win, check to see if you have to block
'       3. Any available corner
'       4.Random location
 
 Randomize
 
 Dim move As Integer
 
If Val(lblMove) = 1 Then
 ' Random corner
    Do
     move = Int(9 * Rnd) + 0
    Loop Until lblBoard(move) = "" And (move = 0 Or move = 2 Or move = 6 Or move = 8)
    
     lblBoard(move) = "X"
 
If Val(lblMove) = 2 Then
 ' Random corner
    Do
     move = Int(9 * Rnd) + 0
    Loop Until lblBoard(move) = "" And (move = 1 Or move = 3 Or move = 5 Or move = 7)
    
     lblBoard(move) = "O"
 
End If
 
 
 
'If Val(lblMove) = 1 Or Val(lblMove) = 2 Or Val(lblMove) = 3 Or Val(lblMove) = 4 Or Val(lblMove) = 5 Then
 
 
End If
lblMove = Val(lblMove) + 1
 
If lblBoard(0) = "X" Then lblMove = Val(lblMove) + 1
 
 
End Sub
Private Sub Check_Win()
If lblBoard(0) = "X" And lblBoard(1) = "X" And lblBoard(2) = "X" Then Ln(1).Visible = True
If lblBoard(0) = "X" And lblBoard(3) = "X" And lblBoard(6) = "X" Then Ln(0).Visible = True
If lblBoard(6) = "X" And lblBoard(7) = "X" And lblBoard(8) = "X" Then Ln(2).Visible = True
If lblBoard(2) = "X" And lblBoard(5) = "X" And lblBoard(8) = "X" Then Ln(6).Visible = True
If lblBoard(1) = "X" And lblBoard(4) = "X" And lblBoard(7) = "X" Then Ln(3).Visible = True
If lblBoard(0) = "X" And lblBoard(4) = "X" And lblBoard(8) = "X" Then Ln(7).Visible = True
If lblBoard(2) = "X" And lblBoard(4) = "X" And lblBoard(6) = "X" Then Ln(5).Visible = True
If lblBoard(3) = "X" And lblBoard(4) = "X" And lblBoard(5) = "X" Then Ln(4).Visible = True
 
If lblBoard(0) = "O" And lblBoard(1) = "O" And lblBoard(2) = "O" Then Ln(1).Visible = True
If lblBoard(0) = "O" And lblBoard(3) = "O" And lblBoard(6) = "O" Then Ln(0).Visible = True
If lblBoard(6) = "O" And lblBoard(7) = "O" And lblBoard(8) = "O" Then Ln(2).Visible = True
If lblBoard(2) = "O" And lblBoard(5) = "O" And lblBoard(8) = "O" Then Ln(6).Visible = True
If lblBoard(1) = "O" And lblBoard(4) = "O" And lblBoard(7) = "O" Then Ln(3).Visible = True
If lblBoard(0) = "O" And lblBoard(4) = "O" And lblBoard(8) = "O" Then Ln(7).Visible = True
If lblBoard(2) = "O" And lblBoard(4) = "O" And lblBoard(6) = "O" Then Ln(5).Visible = True
If lblBoard(3) = "O" And lblBoard(4) = "O" And lblBoard(5) = "O" Then Ln(4).Visible = True
 
End Sub
 
Private Sub lblBoard_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
'index (0-8) is the lbl that was clicked
'Button: 1 - Left ;Button: 2 - Right ; Button: 4 - Middle
Dim turn As Integer
 
If Button = 1 And lblBoard(Index) = "" Then lblBoard(Index) = "X"
If Button = 2 And lblBoard(Index) = "" Then lblBoard(Index) = "O"
'If Button = 4 Then lblBoard(Index) = ""
 
If lblBoard(Index) = "" Then lblBoard(Index) = "O"
 
If lblTurn = 1 Then lblBoard(Index) = "X"
If lblTurn = 2 Then lblBoard(Index) = "O"
 
If lblTurn = 1 Then
lblTurn = 2
Else
lblTurn = 1
End If
 
If lblTurn = 1 Then lblXOTurn = "X's Turn"
If lblTurn = 2 Then lblXOTurn = "O's Turn"
 
 
 
 
 
Check_Win
Wins
End_Game
End Sub
 
Private Sub Wins()
If lblBoard(0) = "X" And lblBoard(1) = "X" And lblBoard(2) = "X" Then lblXWins = Val(lblXWins) + 1
If lblBoard(0) = "X" And lblBoard(3) = "X" And lblBoard(6) = "X" Then lblXWins = Val(lblXWins) + 1
If lblBoard(6) = "X" And lblBoard(7) = "X" And lblBoard(8) = "X" Then lblXWins = Val(lblXWins) + 1
If lblBoard(2) = "X" And lblBoard(5) = "X" And lblBoard(8) = "X" Then lblXWins = Val(lblXWins) + 1
If lblBoard(1) = "X" And lblBoard(4) = "X" And lblBoard(7) = "X" Then lblXWins = Val(lblXWins) + 1
If lblBoard(0) = "X" And lblBoard(4) = "X" And lblBoard(8) = "X" Then lblXWins = Val(lblXWins) + 1
If lblBoard(2) = "X" And lblBoard(4) = "X" And lblBoard(6) = "X" Then lblXWins = Val(lblXWins) + 1
If lblBoard(3) = "X" And lblBoard(4) = "X" And lblBoard(5) = "X" Then lblXWins = Val(lblXWins) + 1
 
If lblBoard(0) = "O" And lblBoard(1) = "O" And lblBoard(2) = "O" Then lblOWins = Val(lblOWins) + 1
If lblBoard(0) = "O" And lblBoard(3) = "O" And lblBoard(6) = "O" Then lblOWins = Val(lblOWins) + 1
If lblBoard(6) = "O" And lblBoard(7) = "O" And lblBoard(8) = "O" Then lblOWins = Val(lblOWins) + 1
If lblBoard(2) = "O" And lblBoard(5) = "O" And lblBoard(8) = "O" Then lblOWins = Val(lblOWins) + 1
If lblBoard(1) = "O" And lblBoard(4) = "O" And lblBoard(7) = "O" Then lblOWins = Val(lblOWins) + 1
If lblBoard(0) = "O" And lblBoard(4) = "O" And lblBoard(8) = "O" Then lblOWins = Val(lblOWins) + 1
If lblBoard(2) = "O" And lblBoard(4) = "O" And lblBoard(6) = "O" Then lblOWins = Val(lblOWins) + 1
If lblBoard(3) = "O" And lblBoard(4) = "O" And lblBoard(5) = "O" Then lblOWins = Val(lblOWins) + 1
 
End Sub
 
Private Sub End_Game()
If lblBoard(0) = "X" And lblBoard(1) = "X" And lblBoard(2) = "X" Then lblBoard(0).Enabled = False And lblBoard(1).Enabled = False And lblBoard(2).Enabled = False
If lblBoard(0) = "X" And lblBoard(3) = "X" And lblBoard(6) = "X" Then lblBoard(0).Enabled = False And lblBoard(3).Enabled = False And lblBoard(6).Enabled = False
If lblBoard(6) = "X" And lblBoard(7) = "X" And lblBoard(8) = "X" Then lblBoard(6).Enabled = False And lblBoard(7).Enabled = False And lblBoard(8).Enabled = False
If lblBoard(2) = "X" And lblBoard(5) = "X" And lblBoard(8) = "X" Then lblBoard(2).Enabled = False And lblBoard(5).Enabled = False And lblBoard(8).Enabled = False
If lblBoard(1) = "X" And lblBoard(4) = "X" And lblBoard(7) = "X" Then lblBoard(1).Enabled = False And lblBoard(4).Enabled = False And lblBoard(7).Enabled = False
If lblBoard(0) = "X" And lblBoard(4) = "X" And lblBoard(8) = "X" Then lblBoard(0).Enabled = False And lblBoard(4).Enabled = False And lblBoard(8).Enabled = False
If lblBoard(2) = "X" And lblBoard(4) = "X" And lblBoard(6) = "X" Then lblBoard(2).Enabled = False And lblBoard(4).Enabled = False And lblBoard(6).Enabled = False
If lblBoard(3) = "X" And lblBoard(4) = "X" And lblBoard(5) = "X" Then lblBoard(3).Enabled = False And lblBoard(4).Enabled = False And lblBoard(5).Enabled = False
 
If lblBoard(0) = "O" And lblBoard(1) = "O" And lblBoard(2) = "O" Then lblBoard(0).Enabled = False And lblBoard(1).Enabled = False And lblBoard(2).Enabled = False
If lblBoard(0) = "O" And lblBoard(3) = "O" And lblBoard(6) = "O" Then lblBoard(0).Enabled = False And lblBoard(3).Enabled = False And lblBoard(6).Enabled = False
If lblBoard(6) = "O" And lblBoard(7) = "O" And lblBoard(8) = "O" Then lblBoard(6).Enabled = False And lblBoard(7).Enabled = False And lblBoard(8).Enabled = False
If lblBoard(2) = "O" And lblBoard(5) = "O" And lblBoard(8) = "O" Then lblBoard(2).Enabled = False And lblBoard(5).Enabled = False And lblBoard(8).Enabled = False
If lblBoard(1) = "O" And lblBoard(4) = "O" And lblBoard(7) = "O" Then lblBoard(1).Enabled = False And lblBoard(4).Enabled = False And lblBoard(7).Enabled = False
If lblBoard(0) = "O" And lblBoard(4) = "O" And lblBoard(8) = "O" Then lblBoard(0).Enabled = False And lblBoard(4).Enabled = False And lblBoard(8).Enabled = False
If lblBoard(2) = "O" And lblBoard(4) = "O" And lblBoard(6) = "O" Then lblBoard(2).Enabled = False And lblBoard(4).Enabled = False And lblBoard(6).Enabled = False
If lblBoard(3) = "O" And lblBoard(4) = "O" And lblBoard(5) = "O" Then lblBoard(3).Enabled = False And lblBoard(4).Enabled = False And lblBoard(5).Enabled = False
 
End Sub
 


BC AdBot (Login to Remove)

 


#2 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:09:23 AM

Posted 25 November 2013 - 02:22 PM

1. Why are you using VB6 for a new project?
2. I don't see a question here.

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#3 CarmelloFellow

CarmelloFellow
  • Topic Starter

  • Members
  • 3 posts
  • OFFLINE
  •  
  • Local time:11:23 AM

Posted 25 November 2013 - 02:44 PM

It is and will always be the best. And I need help with the automated computer moves (cmdMove)



#4 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:09:23 AM

Posted 25 November 2013 - 02:54 PM

We can agree to disagree I guess. What have you tried for automated computer moves?

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#5 CarmelloFellow

CarmelloFellow
  • Topic Starter

  • Members
  • 3 posts
  • OFFLINE
  •  
  • Local time:11:23 AM

Posted 25 November 2013 - 02:56 PM

Haha okay.

And my attempts so far are under the Private Sub Computer_Move (). I have a move button to have the computer randomly pick a spot. And I want it's first choice to be a corner on the board.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users