Advertisement
Guest User

TicTacToeW/AI

a guest
Dec 13th, 2015
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Class Form1
  2.  
  3.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  4.  
  5.         If Button2.Text = "X" Then
  6.             If Button3.Text = "X" Then
  7.                 If Button4.Text = "X" Then
  8.                     If Button6.Text = "X" Then
  9.  
  10.                     End If
  11.                 End If
  12.             End If
  13.         ElseIf Button3.Text = " " Then
  14.             Button3.Text = "O"
  15.         End If
  16.  
  17.  
  18.  
  19.  
  20.     End Sub
  21.  
  22.     Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  23.         Dim a, b, c As String 'A = button 3, A=1,B=2,C=3, random number gen 1-3 then num = a,b or c then txtbox= the letter, changed button
  24.        Dim rnd As Double
  25.         Dim rn As New Random
  26.         ListBox1.Items.Add(rnd)
  27.         Button2.Enabled = False
  28.         Button2.Text = "X"
  29.  
  30.         If Button3.Text = "X" Then
  31.  
  32.         ElseIf Button3.Text = " " Then
  33.             a = 1
  34.             If Button6.Text = " " Then
  35.                 b = 2
  36.                 If Button5.Text = " " Then
  37.                     c = 3
  38.                 End If
  39.             End If
  40.  
  41.             rnd = (rn.Next(1, 4)) 'random # gen, from number 1-3
  42.  
  43.         End If
  44.         If rnd = 1 Then
  45.             Button3.Text = "O"
  46.             Button3.Enabled = False
  47.         End If
  48.         If rnd = 2 Then
  49.             Button6.Text = "O"
  50.             Button6.Enabled = False
  51.         End If
  52.         If rnd = 3 Then
  53.             Button5.Text = "O"
  54.             Button5.Enabled = False
  55.         End If
  56.         ListBox1.Items.Add(rnd)
  57.  
  58.         If rnd = 1 Then 'Debugger
  59.            ListBox1.Items.Add("Bot placed O on A2")
  60.         ElseIf rnd = 2 Then
  61.             ListBox1.Items.Add("Bot placed O on B2")
  62.         ElseIf rnd = 3 Then
  63.             ListBox1.Items.Add("Bot placed O on B1")
  64.         End If
  65.  
  66.     End Sub
  67.  
  68.     Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
  69.         Dim a, b, c As String 'A = button 3, A=1,B=2,C=3, random number gen 1-3 then num = a,b or c then txtbox= the letter, changed button
  70.        Dim rnd As Double
  71.         Dim rn As New Random
  72.  
  73.  
  74.         If Button3.Text = "O" Then
  75.             Button3.Enabled = False
  76.             Button3.Text = "O"
  77.         ElseIf Button3.Text = " " Then
  78.             Button3.Enabled = False
  79.             Button3.Text = "X"
  80.  
  81.         End If
  82.        
  83.  
  84.         If Button3.Text = "X" Then
  85.  
  86.          Button2.Text = " "
  87.             a = 1
  88.  
  89.             If Button6.Text = " " Then
  90.                 b = 2
  91.                 If Button4.Text = " " Then
  92.                     c = 3
  93.                 End If
  94.             End If
  95.  
  96.  
  97.             rnd = (rn.Next(1, 4)) 'random # gen, from number 1-3
  98.  
  99.         End If
  100.         If rnd = 1 Then
  101.             Button2.Text = "O"
  102.             Button2.Enabled = False
  103.         End If
  104.         If rnd = 2 Then
  105.             Button6.Text = "O"
  106.             Button6.Enabled = False
  107.         End If
  108.         If rnd = 3 Then
  109.             Button4.Text = "O"
  110.             Button4.Enabled = False
  111.         End If
  112.  
  113.         ListBox1.Items.Add(rnd)
  114.  
  115.         If rnd = 1 Then 'Debugger
  116.            ListBox1.Items.Add("Bot placed O on A2")
  117.         ElseIf rnd = 2 Then
  118.             ListBox1.Items.Add("Bot placed O on B2")
  119.         ElseIf rnd = 3 Then
  120.             ListBox1.Items.Add("Bot placed O on A3")
  121.         End If
  122.  
  123.     End Sub
  124.  
  125.     Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
  126.  
  127.         Dim a, b, c As String 'A = button 3, A=1,B=2,C=3, random number gen 1-3 then num = a,b or c then txtbox= the letter, changed button
  128.        Dim rnd As Double
  129.         Dim rn As New Random
  130.  
  131.  
  132.         If Button4.Text = "O" Then
  133.             Button4.Enabled = False
  134.             Button4.Text = "O"
  135.         ElseIf Button4.Text = " " Then
  136.             Button4.Enabled = False
  137.             Button4.Text = "X"
  138.  
  139.         End If
  140.  
  141.  
  142.         If Button4.Text = "X" Then
  143.  
  144.             Button3.Text = " "
  145.             a = 1
  146.  
  147.             If Button6.Text = " " Then
  148.                 b = 2
  149.                 If Button7.Text = " " Then
  150.                     c = 3
  151.                 End If
  152.             End If
  153.  
  154.  
  155.             rnd = (rn.Next(1, 4)) 'random # gen, from number 1-3
  156.  
  157.         End If
  158.         If rnd = 1 Then
  159.             Button4.Text = "O"
  160.             Button4.Enabled = False
  161.         End If
  162.         If rnd = 2 Then
  163.             Button6.Text = "O"
  164.             Button6.Enabled = False
  165.         End If
  166.         If rnd = 3 Then
  167.             Button7.Text = "O"
  168.             Button7.Enabled = False
  169.         End If
  170.         ListBox1.Items.Add(rnd)
  171.  
  172.         If rnd = 1 Then 'Debugger
  173.            ListBox1.Items.Add("Bot placed O on A2")
  174.         ElseIf rnd = 2 Then
  175.             ListBox1.Items.Add("Bot placed O on B2")
  176.         ElseIf rnd = 3 Then
  177.             ListBox1.Items.Add("Bot placed O on B3")
  178.         End If
  179.  
  180.     End Sub
  181.  
  182.    
  183.  
  184.     Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
  185.  
  186.         Dim a, b, c As String 'A = button 3, A=1,B=2,C=3, random number gen 1-3 then num = a,b or c then txtbox= the letter, changed button
  187.        Dim rnd As Double
  188.         Dim rn As New Random
  189.  
  190.  
  191.         If Button5.Text = "O" Then
  192.             Button5.Enabled = False
  193.             Button5.Text = "O"
  194.         ElseIf Button5.Text = " " Then
  195.             Button5.Enabled = False
  196.             Button5.Text = "X"
  197.  
  198.         End If
  199.  
  200.  
  201.         If Button5.Text = "X" Then
  202.  
  203.             Button2.Text = " "
  204.             a = 1
  205.  
  206.             If Button6.Text = " " Then
  207.                 b = 2
  208.                 If Button8.Text = " " Then
  209.                     c = 3
  210.                 End If
  211.             End If
  212.  
  213.  
  214.             rnd = (rn.Next(1, 4)) 'random # gen, from number 1-3
  215.  
  216.         End If
  217.         If rnd = 1 Then
  218.             Button2.Text = "O"
  219.             Button2.Enabled = False
  220.         End If
  221.         If rnd = 2 Then
  222.             Button6.Text = "O"
  223.             Button6.Enabled = False
  224.         End If
  225.         If rnd = 3 Then
  226.             Button8.Text = "O"
  227.             Button8.Enabled = False
  228.         End If
  229.  
  230.         ListBox1.Items.Add(rnd)
  231.  
  232.         If rnd = 1 Then 'Debugger
  233.            ListBox1.Items.Add("Bot placed O on A1")
  234.         ElseIf rnd = 2 Then
  235.             ListBox1.Items.Add("Bot placed O on B2")
  236.         ElseIf rnd = 3 Then
  237.             ListBox1.Items.Add("Bot placed O on C1")
  238.         End If
  239.  
  240.     End Sub
  241.     'This code is a bit messed up
  242.    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
  243.  
  244.         Dim a, b, c, d As String 'A = button 3, A=1,B=2,C=3, random number gen 1-3 then num = a,b or c then txtbox= the letter, changed button
  245.        Dim rnd As Double
  246.         Dim rn As New Random
  247.  
  248.  
  249.         If Button6.Text = "O" Then
  250.             Button6.Enabled = False
  251.             Button6.Text = "O"
  252.         ElseIf Button6.Text = " " Then
  253.             Button6.Enabled = False
  254.             Button6.Text = "X"
  255.  
  256.         End If
  257.  
  258.  
  259.         If Button5.Text = "X" Then
  260.  
  261.             Button2.Text = " "
  262.             a = 1
  263.  
  264.             If Button6.Text = " " Then
  265.                 b = 2
  266.                 If Button8.Text = " " Then
  267.                     c = 3
  268.                     If Button9.Text = " " Then
  269.                         d = 4
  270.                     End If
  271.                 End If
  272.             End If
  273.  
  274.  
  275.             rnd = (rn.Next(1, 5)) 'Middle square, code changes a bit for four spaces
  276.  
  277.         End If
  278.         If rnd = 1 Then
  279.             Button3.Text = "O"
  280.             Button3.Enabled = False
  281.         End If
  282.         If rnd = 2 Then
  283.             Button7.Text = "O"
  284.             Button7.Enabled = False
  285.         End If
  286.         If rnd = 3 Then
  287.             Button9.Text = "O"
  288.             Button9.Enabled = False
  289.         End If
  290.         If rnd = 4 Then
  291.             Button5.Text = "O"
  292.             Button5.Enabled = False
  293.         End If
  294.  
  295.         ListBox1.Items.Add(rnd)
  296.  
  297.         If rnd = 1 Then 'Debugger
  298.            ListBox1.Items.Add("Bot placed O on A2")
  299.         ElseIf rnd = 2 Then
  300.             ListBox1.Items.Add("Bot placed O on B3")
  301.         ElseIf rnd = 3 Then
  302.             ListBox1.Items.Add("Bot placed O on C2")
  303.         ElseIf rnd = 4 Then
  304.             ListBox1.Items.Add("Bot placed O on b1")
  305.         End If
  306.  
  307.     End Sub
  308. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement