Results 1 to 12 of 12
Like Tree1Likes
  • 1 Post By Junky

Thread: Help with Tic Tac Toe

  1. #1
    Dants is offline Member
    Join Date
    Aug 2011
    Posts
    5
    Rep Power
    0

    Post Help with Tic Tac Toe

    Hello, I need some help with this TicTacToe game, as you may see I can already play but the problem is that I need to make it learn from every game and each time it plays learns more becoming harder to win, but I'm blocked already and I don't know how should I do it, thanks for the help and sorry for my poor english Practica 2.zip

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,882
    Rep Power
    25

    Default

    I need to make it learn from every game and each time it plays learns more becoming harder to win,
    That sounds like you need an AI algorithm.
    Do you have one? Have you tried Google to see if you can find one?

    What can the program learn? List something that the program could learn? Two in a row by the opponent is bad

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    I (and many others) won't download your code. Post your code here. If it is too long only post the relevant section or create a SSCCE. Then ask a specific question.

  4. #4
    Dants is offline Member
    Join Date
    Aug 2011
    Posts
    5
    Rep Power
    0

    Default

    Well the code it’s pretty much useful, as Norm said I think I need some AI, I read I could extract the info from a text file located along the code, after each game it saves the order of the game and in the next games it seeks that text file and try to play the winning order again or if it’s not possible it tries to tie the game, this until it gets every possible move.

    I got some examples of the AI but I don’t really know how to apply them, that’s why I am blocked, I already made some changes to the first code, now you can play against the CPU being you the first to move or second, also an exit button, but the AI stills no good.

    Hi Junky, well I’m not sure how to put the code, is a little long but as I told you I need help for it to start learning from every game so I’m not sure how to do it, I will post the code in the next post, I hope it isn’t too long and affects the reading in the board, thank for your time!

    BTW I wanted to add that I am using NetBeans 6.8 also my second language is English so many of the code has references in Spanish, I hope it’s not a problem and again, thanks!
    Last edited by Dants; 08-04-2011 at 04:14 AM.

  5. #5
    Dants is offline Member
    Join Date
    Aug 2011
    Posts
    5
    Rep Power
    0

    Default

    import javax.swing.*;

    public class Gato extends javax.swing.JFrame {

    int cont=0, juega=0, Azar=0, ban=0, Fin=1, exit=0;
    String letra = "";
    boolean gano = false;

    public Gato() {
    initComponents();
    }

    public void CPU (){
    do{
    ban=0;
    Azar=(int)(Math.random()*9);
    switch (Azar)
    {
    case 0:
    if (jButton1.getText()== ""){
    jButton1.setEnabled(false);
    jButton1.setText(letra); break;
    }
    else {
    ban=1; break;
    }

    case 1:
    if (jButton2.getText()== ""){
    jButton2.setEnabled(false);
    jButton2.setText(letra); break;
    }
    else {
    ban=1; break;
    }
    case 2:
    if (jButton3.getText()== ""){
    jButton3.setEnabled(false);
    jButton3.setText(letra); break;
    }
    else {
    ban=1; break;
    }
    case 3:
    if (jButton4.getText()== ""){
    jButton4.setEnabled(false);
    jButton4.setText(letra); break;
    }
    else {
    ban=1; break;
    }
    case 4:
    if (jButton5.getText()== ""){
    jButton5.setEnabled(false);
    jButton5.setText(letra); break;
    }
    else {
    ban=1; break;
    }
    case 5:
    if (jButton6.getText()== ""){
    jButton6.setEnabled(false);
    jButton6.setText(letra); break;
    }
    else {
    ban=1; break;
    }
    case 6:
    if (jButton7.getText()== ""){
    jButton7.setEnabled(false);
    jButton7.setText(letra); break;
    }
    else {
    ban=1; break;
    }
    case 7:
    if (jButton8.getText()== ""){
    jButton8.setEnabled(false);
    jButton8.setText(letra); break;
    }
    else {
    ban=1; break;
    }
    case 8:
    if (jButton9.getText()== ""){
    jButton9.setEnabled(false);
    jButton9.setText(letra); break;
    }
    else {
    ban=1; break;
    }
    }
    }
    while (ban==1);
    }

    public void Turnos (){
    cont++;
    if(cont == 1 || cont == 3 || cont == 5 || cont == 7 || cont == 9)
    {
    letra = "X";
    }
    else if(cont == 2 || cont == 4 || cont == 6 || cont == 8 || cont == 10)
    {
    letra = "O";
    }
    }

    public void Ganador (){
    if( jButton1.getText() == jButton2.getText() && jButton2.getText() == jButton3.getText() && jButton1.getText() != ""){
    gano=true;
    }
    else if(jButton4.getText() == jButton5.getText() && jButton5.getText() == jButton6.getText() && jButton4.getText() != ""){
    gano=true;
    }
    else if(jButton7.getText() == jButton8.getText() && jButton8.getText() == jButton9.getText() && jButton7.getText() != ""){
    gano=true;
    }
    else if(jButton1.getText() == jButton4.getText() && jButton4.getText() == jButton7.getText() && jButton1.getText() != ""){
    gano=true;
    }
    else if(jButton2.getText() == jButton5.getText() && jButton5.getText() == jButton8.getText() && jButton2.getText() != ""){
    gano=true;
    }
    else if(jButton3.getText() == jButton6.getText() && jButton6.getText() == jButton9.getText() && jButton3.getText() != ""){
    gano=true;
    }
    else if(jButton1.getText() == jButton5.getText() && jButton5.getText() == jButton9.getText() && jButton1.getText() != ""){
    gano=true;
    }
    else if(jButton3.getText() == jButton5.getText() && jButton5.getText() == jButton7.getText() && jButton3.getText() != ""){
    gano=true;
    }
    else
    {
    gano=false;
    }

    if(gano==true)
    {
    JOptionPane.showMessageDialog(null, letra + " Gano!");
    Fin=2;
    }
    else if(cont==9 && gano==false)
    {
    JOptionPane.showMessageDialog(null, "Juego Empatado!");
    Fin=2;
    }

    }

    @SuppressWarnings("unchecked")
    // "Generated Code">

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
    if (juega==1)
    {
    Turnos ();
    jButton1.setText(letra);
    jButton1.setEnabled(false);
    Ganador ();
    }
    else if (juega==2)
    {
    Turnos ();
    jButton1.setText(letra);
    jButton1.setEnabled(false);
    Ganador ();
    if (Fin==1){
    Turnos ();
    CPU ();
    Ganador ();
    }
    }
    else
    {
    JOptionPane.showMessageDialog(null,"No seleccionaste jugador!");
    }
    }

    private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {
    if (juega==1)
    {
    Turnos ();
    jButton2.setText(letra);
    jButton2.setEnabled(false);
    Ganador ();
    }
    else if (juega==2)
    {
    Turnos ();
    jButton2.setText(letra);
    jButton2.setEnabled(false);
    Ganador ();
    if (Fin==1){
    Turnos ();
    CPU ();
    Ganador ();
    }
    }
    else
    {
    JOptionPane.showMessageDialog(null,"No seleccionaste jugador!");
    }
    }

    private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {
    if (juega==1)
    {
    Turnos ();
    jButton3.setText(letra);
    jButton3.setEnabled(false);
    Ganador ();
    }
    else if (juega==2)
    {
    Turnos ();
    jButton3.setText(letra);
    jButton3.setEnabled(false);
    Ganador ();
    if (Fin==1){
    Turnos ();
    CPU ();
    Ganador ();
    }
    }
    else
    {
    JOptionPane.showMessageDialog(null,"No seleccionaste jugador!");
    }
    }

    private void jButton4MouseClicked(java.awt.event.MouseEvent evt) {
    if (juega==1)
    {
    Turnos ();
    jButton4.setText(letra);
    jButton4.setEnabled(false);
    Ganador ();
    }
    else if (juega==2)
    {
    Turnos ();
    jButton4.setText(letra);
    jButton4.setEnabled(false);
    Ganador ();
    if (Fin==1){
    Turnos ();
    CPU ();
    Ganador ();
    }
    }
    else
    {
    JOptionPane.showMessageDialog(null,"No seleccionaste jugador!");
    }
    }

    private void jButton5MouseClicked(java.awt.event.MouseEvent evt) {
    if (juega==1)
    {
    Turnos ();
    jButton5.setText(letra);
    jButton5.setEnabled(false);
    Ganador ();
    }
    else if (juega==2)
    {
    Turnos ();
    jButton5.setText(letra);
    jButton5.setEnabled(false);
    Ganador ();
    if (Fin==1){
    Turnos ();
    CPU ();
    Ganador ();
    }
    }
    else
    {
    JOptionPane.showMessageDialog(null,"No seleccionaste jugador!");
    }
    }

    private void jButton6MouseClicked(java.awt.event.MouseEvent evt) {
    if (juega==1)
    {
    Turnos ();
    jButton6.setText(letra);
    jButton6.setEnabled(false);
    Ganador ();
    }
    else if (juega==2)
    {
    Turnos ();
    jButton6.setText(letra);
    jButton6.setEnabled(false);
    Ganador ();
    if (Fin==1){
    Turnos ();
    CPU ();
    Ganador ();
    }
    }
    else
    {
    JOptionPane.showMessageDialog(null,"No seleccionaste jugador!");
    }
    }

    private void jButton7MouseClicked(java.awt.event.MouseEvent evt) {
    if (juega==1)
    {
    Turnos ();
    jButton7.setText(letra);
    jButton7.setEnabled(false);
    Ganador ();
    }
    else if (juega==2)
    {
    Turnos ();
    jButton7.setText(letra);
    jButton7.setEnabled(false);
    Ganador ();
    if (Fin==1){
    Turnos ();
    CPU ();
    Ganador ();
    }
    }
    else
    {
    JOptionPane.showMessageDialog(null,"No seleccionaste jugador!");
    }
    }

    private void jButton8MouseClicked(java.awt.event.MouseEvent evt) {
    if (juega==1)
    {
    Turnos ();
    jButton8.setText(letra);
    jButton8.setEnabled(false);
    Ganador ();
    }
    else if (juega==2)
    {
    Turnos ();
    jButton8.setText(letra);
    jButton8.setEnabled(false);
    Ganador ();
    if (Fin==1){
    Turnos ();
    CPU ();
    Ganador ();
    }
    }
    else
    {
    JOptionPane.showMessageDialog(null,"No seleccionaste jugador!");
    }
    }

    private void jButton9MouseClicked(java.awt.event.MouseEvent evt) {
    if (juega==1)
    {
    Turnos ();
    jButton9.setText(letra);
    jButton9.setEnabled(false);
    Ganador ();
    }
    else if (juega==2)
    {
    Turnos ();
    jButton9.setText(letra);
    jButton9.setEnabled(false);
    Ganador ();
    if (Fin==1){
    Turnos ();
    CPU ();
    Ganador ();
    }
    }
    else
    {
    JOptionPane.showMessageDialog(null,"No seleccionaste jugador!");
    }
    }

    private void jButton10MouseClicked(java.awt.event.MouseEvent evt) {
    juega=1;
    jButton10.setEnabled(true);
    jButton11.setEnabled(false);
    jButton13.setEnabled(false);
    }

    private void jButton11MouseClicked(java.awt.event.MouseEvent evt) {
    juega=2;
    jButton10.setEnabled(false);
    jButton11.setEnabled(true);
    jButton13.setEnabled(false);
    }

    private void jButton12ActionPerformed(java.awt.event.ActionEven t evt) {

    System.exit(0);

    }

    private void jButton13MouseClicked(java.awt.event.MouseEvent evt) {
    juega=2;
    jButton10.setEnabled(false);
    jButton11.setEnabled(false);
    jButton13.setEnabled(true);
    Turnos ();
    CPU ();
    }
    Last edited by Dants; 08-04-2011 at 04:12 AM. Reason: Minor changes

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,882
    Rep Power
    25

    Default

    Java Code:
    jButton1.getText() == jButton2.getText()
    You should be using the equals() method for comparing Strings instead of the == operator.

    Java Code:
    jButton6.getText()== "")
    The String class has methods for this test. I assume you are testing for an empty String (length==0)

  7. #7
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    Quote Originally Posted by Junky View Post
    Post your code here. If it is too long only post the relevant section or create a SSCCE.
    Perhaps you didn't see that part of my previous post.

  8. #8
    Dants is offline Member
    Join Date
    Aug 2011
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Java Code:
    jButton1.getText() == jButton2.getText()
    You should be using the equals() method for comparing Strings instead of the == operator.

    Java Code:
    jButton6.getText()== "")
    The String class has methods for this test. I assume you are testing for an empty String (length==0)
    Ok, I made the changes to that part

    Junky sorry if it is a problem, I need some help with that and if you or other members of the forum don't want to download the file I posted it so I can get some help, thanks again for your time and again sorry for causing you so much trouble!
    Last edited by Dants; 08-04-2011 at 04:45 AM.

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,882
    Rep Power
    25

    Default

    This isn't really about his code, although it does need a LOT of improvement.
    He's looking for an algorithm to have the program "learn" and play better in the future.
    I don't think there is much to learn in TTT. The only thing I think of is to block the opponent if he gets 2 in a row.
    Not really a java programming problem.

    The code is a mass of copy and pastes. It Needs to have some lists for the buttons etc vs the repeated code.

  10. #10
    Dants is offline Member
    Join Date
    Aug 2011
    Posts
    5
    Rep Power
    0

    Default

    I found one code for a TicTacToe, it supposedly learns very well and each time it gets harder to defeat, the problem is that I can’t really interpret hoe he does it to apply it on java, again this is the code and it’s not made by me!
    'Tic Tac Toe by JengHowe, with the ability to learn (or true AI)
    'Keeps a record of all the games that it has lost and calculates the best possible
    'move. If the CPU is allowed to play first, it would use the record to find the best
    'move to win. The record file that came with this code 'MovHis.txt' is with all possible
    'combinations the CPU would lose, so basically the CPU would not lose, and if allowed to
    'play first, would win you if you are not careful. To make the CPU dumb again, just delete
    'the record file, "movhis.txt".
    '
    'This is a revolutionary way of coding tic tac toe AI. the AI is is extremely robust
    'and is capable of self improvement, and all this is done in a short time and without
    'any really complex algorithms and long code.
    '
    'Note, the CPU only learns when you are the one who start, and it only gets as smart
    'as you do.

    Dim CPUplay As Boolean
    Dim whowin, playstr As String
    Dim NumBoxFilled, NGP, games_played As Integer
    Dim MovHis() As String
    Dim loseweight(8) As Integer

    'Numbering of the Picture Box
    ' 0 1 2
    ' 3 4 5
    ' 6 7 8
    '
    'Draws X on the desinated Picture Box, Also Sets the tag property to 'X'
    Private Sub drawX(Index As Integer)
    Box(Index).Line (0, 1)-(38, 39)
    Box(Index).Line (0, 0)-(39, 39)
    Box(Index).Line (1, 0)-(39, 38)
    Box(Index).Line (38, 1)-(1, 38)
    Box(Index).Line (38, 0)-(0, 38)
    Box(Index).Line (37, 0)-(0, 37)
    Box(Index).Tag = "X"
    End Sub

    'Draws O on the desinated Picture Box, Also sets the tag property to 'O'
    Private Sub drawO(Index As Integer)
    Box(Index).FillStyle = 0
    Box(Index).FillColor = &H0&
    Box(Index).Circle (20, 20), 19
    Box(Index).FillColor = &H8000000F
    Box(Index).Circle (20, 20), 17
    Box(Index).Tag = "O"
    End Sub

    'New Button
    'Clears all the Picture Box, and reinitialises the variables
    Private Sub Command1_Click()
    Dim mv As Integer
    For i = 0 To 8
    Box(i).Cls
    Box(i).Tag = ""
    Next
    CPUplay = False
    whowin = ""
    playstr = ""
    NumBoxFilled = 0
    Gtype(1).Enabled = True
    Gtype(2).Enabled = True
    Gtype(1).Value = True
    End Sub

    'Function that returns true if a winning combination is found
    Private Function win() As Boolean
    If rowsame(0, 1, 2) Or rowsame(3, 4, 5) Or rowsame(6, 7, 8) Or _
    rowsame(0, 3, 6) Or rowsame(1, 4, 7) Or rowsame(2, 5, 8) Or _
    rowsame(0, 4, 8) Or rowsame(2, 4, 6) Then win = True
    End Function

    'Sub Function used by Win() to check wheter the 3 PictureBox has the same Symbol
    Private Function rowsame(i1, i2, i3 As Integer) As Boolean
    If (Box(i1).Tag = Box(i2).Tag) And (Box(i2).Tag = Box(i3).Tag) And (Box(i1).Tag = "X" Or Box(i1).Tag = "O") Then
    rowsame = True
    whowin = Box(i1).Tag
    Else
    rowsame = False
    End If
    End Function

    'Exit Button
    'Compacts the move history by only saving losing moves, then saves it into a file
    'named 'movhis.txt'
    Private Sub Command2_Click()
    Dim CompactHis() As String
    Dim CNum, i, j, k As Integer
    For i = 1 To NGP
    If Right(MovHis(i), 1) = "X" Then 'Saves only losing moves
    CNum = CNum + 1
    ReDim Preserve CompactHis(CNum)
    CompactHis(CNum) = MovHis(i)
    End If
    Next
    If NGP = 0 Then End
    'Open File for output
    Open App.Path + "\MoveHis.txt" For Output As #1
    Print #1, CNum
    For i = 1 To CNum
    Print #1, CompactHis(i)
    Next
    Close #1
    End
    End Sub

    'Executes when the Picture Boxes are clicked
    Private Sub Box_Click(Index As Integer)
    Dim i, mvpos, rp As Integer
    Dim mvstr As String
    Gtype(1).Enabled = False
    Gtype(2).Enabled = False

    playstr = playstr + CStr(Index)
    If Box(Index).Tag = "" Then
    drawX (Index)
    CPUplay = True
    NumBoxFilled = NumBoxFilled + 1
    End If

    'If either side wins or draw, exit subroutine
    If checkforwin Then Exit Sub

    'CPU Play
    If CPUplay Then
    mvstr = FindMoves
    rp = Int(Rnd * Len(mvstr)) + 1
    mvpos = CDec(Mid(mvstr, rp, 1))
    Debug.Print "Available Moves:"; mvstr; " Choose:"; mvpos
    drawO (mvpos)
    playstr = playstr + CStr(mvpos)
    CPUplay = False
    NumBoxFilled = NumBoxFilled + 1
    End If

    If checkforwin Then Exit Sub
    End Sub

    'Function that checks for winning combination
    'when CPU loses, it will then record the current game moves into the move history
    'Since the game board is 3x3 matrix, it is symmetrical in 8 ways, so 1 game played
    'in a particular direction can be interpreted into 8 identical games. Matrix
    'manipulation "Transpose" and "Rotate" is used to obtain the extra 7 equivalent games.
    '
    'Basically, what this does is it speeds up the CPU learning process by 8 fold.
    Private Function checkforwin() As Boolean
    checkforwin = False
    If win Then
    MsgBox whowin + " Won", , "Game Over!"
    games_played = games_played + 1
    ScoreBoard.AddItem ("Game " + CStr(games_played) + " : " + whowin + " Win")
    playstr = playstr + whowin
    Debug.Print playstr
    If Gtype(1).Value Then
    NGP = NGP + 1: ReDim Preserve MovHis(NGP): MovHis(NGP) = playstr
    NGP = NGP + 1: ReDim Preserve MovHis(NGP): MovHis(NGP) = transpose(playstr)
    NGP = NGP + 1: ReDim Preserve MovHis(NGP): MovHis(NGP) = rotate(playstr)
    NGP = NGP + 1: ReDim Preserve MovHis(NGP): MovHis(NGP) = transpose(rotate(playstr))
    NGP = NGP + 1: ReDim Preserve MovHis(NGP): MovHis(NGP) = rotate(rotate(playstr))
    NGP = NGP + 1: ReDim Preserve MovHis(NGP): MovHis(NGP) = transpose(rotate(rotate(playstr)))
    NGP = NGP + 1: ReDim Preserve MovHis(NGP): MovHis(NGP) = rotate(rotate(rotate(playstr)))
    NGP = NGP + 1: ReDim Preserve MovHis(NGP): MovHis(NGP) = transpose(rotate(rotate(rotate(playstr))))
    End If
    Gtype(1).Enabled = True
    Gtype(2).Enabled = True
    Gtype(1).Value = True
    Call Command1_Click
    checkforwin = True
    ElseIf NumBoxFilled = 9 Then
    MsgBox "Draw", , "Game Over!"
    games_played = games_played + 1
    ScoreBoard.AddItem ("Game " + CStr(games_played) + " : " + "Draw")
    playstr = playstr + "D"
    Debug.Print playstr
    Call Command1_Click
    checkforwin = True
    Gtype(1).Enabled = True
    Gtype(2).Enabled = True
    Gtype(1).Value = True
    End If
    End Function

    'Matrix Manipulation Function
    '
    ' 012 036
    ' 345 => 147
    ' 678 258
    Private Function transpose(tstr As String) As String
    Dim temp, c, c1 As String
    Dim i, rp As Integer
    For i = 1 To Len(tstr)
    c = Mid(tstr, i, 1)
    Select Case c
    Case Is = "1": c1 = "3"
    Case Is = "3": c1 = "1"
    Case Is = "2": c1 = "6"
    Case Is = "6": c1 = "2"
    Case Is = "5": c1 = "7"
    Case Is = "7": c1 = "5"
    Case Else: c1 = c
    End Select
    temp = temp + c1
    Next
    transpose = temp
    End Function

    'Matrix Manipulation Function
    'Rotates the Matrix by 90 degrees, to rotate 180, just use the function twice
    'for 270, three times
    '
    ' 012 258
    ' 345 => 147
    ' 678 036

    Private Function rotate(tstr As String) As String
    Dim temp, c, c1 As String
    Dim i, rp As Integer
    For i = 1 To Len(tstr)
    c = Mid(tstr, i, 1)
    Select Case c
    Case Is = "0": c1 = "2"
    Case Is = "1": c1 = "5"
    Case Is = "2": c1 = "8"
    Case Is = "3": c1 = "1"
    Case Is = "4": c1 = "4"
    Case Is = "5": c1 = "7"
    Case Is = "6": c1 = "0"
    Case Is = "7": c1 = "3"
    Case Is = "8": c1 = "6"
    Case Else: c1 = c
    End Select
    temp = temp + c1
    Next
    rotate = temp
    End Function

    'Finds the Appropriate move for the CPU, the function returns a string containing all
    'possible moves
    Private Function FindMoves() As String
    Dim i, j, l, mv, sml As Integer
    Dim pst, mvc As String
    For i = 0 To 8
    loseweight(i) = 0
    Next
    For j = 0 To 8
    pst = playstr + CStr(j)
    l = Len(pst)
    For i = 1 To NGP
    If l < Len(MovHis(i)) Then
    If pst = Left(MovHis(i), l) Then
    If Right(MovHis(i), 1) = "X" Then loseweight(j) = loseweight(j) + 1
    End If
    End If
    Next i
    Next j

    'Different weight calculation when the CPU moves first
    If Gtype(1).Value Then 'When CPU moves Second
    sml = 32767
    For i = 0 To 8
    If sml > loseweight(i) And Box(i).Tag = "" Then sml = loseweight(i)
    Next
    Else 'When CPU moves First
    sml = 0
    For i = 0 To 8
    If sml < loseweight(i) And Box(i).Tag = "" Then sml = loseweight(i)
    Next
    End If

    For i = 0 To 8
    If loseweight(i) = sml And Box(i).Tag = "" Then mvc = mvc + CStr(i)
    Next

    'Checks wheter if the Human Player has a winning move, if there is, then block it
    For i = 0 To 8
    If Box(i).Tag = "" Then
    Box(i).Tag = "X"
    If win Then mvc = CStr(i)
    Box(i).Tag = ""

    End If
    Next

    'Checks wheter the CPU has a winning move, if it does, then choose that move.
    For i = 0 To 8
    If Box(i).Tag = "" Then
    Box(i).Tag = "O"
    If win Then mvc = CStr(i)
    Box(i).Tag = ""

    End If
    Next
    FindMoves = mvc
    End Function

    'Clears Score Board
    Private Sub Command3_Click()
    games_played = 0
    ScoreBoard.Clear
    End Sub

    'Executed when the Program starts, loads the move history from file if available
    Private Sub Form_Load()
    Dim i As Integer
    Randomize Timer
    On Error GoTo errHand
    Open App.Path + "\MoveHis.txt" For Input As #1
    Input #1, NGP
    ReDim MovHis(NGP)
    For i = 1 To NGP
    Input #1, MovHis(i)
    Next
    errHand:
    Close #1
    End Sub

    'Executes when the Options menu are Clicked
    'Chooses between CPU play first or Human First
    Private Sub Gtype_Click(Index As Integer)
    If Gtype(2).Value Then
    mv = Int(Rnd * 9)
    drawO (mv)
    NumBoxFilled = NumBoxFilled + 1
    playstr = CStr(mv)
    Gtype(1).Enabled = False
    Gtype(2).Enabled = False
    End If
    End Sub

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,882
    Rep Power
    25

    Default

    That's interesting, maybe some will wonder about it enough to look at it. Not being java makes it hard to work with.

    Maybe if you tried on a VB forum someone could explain it to you.

  12. #12
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    Quote Originally Posted by Dants View Post
    Junky sorry if it is a problem, I need some help with that and if you or other members of the forum don't want to download the file I posted it so I can get some help, thanks again for your time and again sorry for causing you so much trouble!
    I was just offering you some tips on how to improve your chances of getting help. Norm is a top bloke with the patience of a Saint but I and many others won't bother to wade through elebenty gazillion lines of code. Therefore instead of getting help from 2 or 3 or more people which might lead to you solving your problem sooner, your only help is coming from Norm.
    DarrylBurke likes this.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •