0% found this document useful (0 votes)
26 views

Noughts and Crosses Code v1

The document describes the logic for a tic-tac-toe game between a player and an AI opponent called Skynet. It tracks the number of moves each player has made, and contains logic for Skynet to determine its move based on where the player has played. On its first move, Skynet will take the center position if available, or block the player from getting three in a row. The code then continues to track moves and uses if/else statements to determine Skynet's response based on the player's previous positions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Noughts and Crosses Code v1

The document describes the logic for a tic-tac-toe game between a player and an AI opponent called Skynet. It tracks the number of moves each player has made, and contains logic for Skynet to determine its move based on where the player has played. On its first move, Skynet will take the center position if available, or block the player from getting three in a row. The code then continues to track moves and uses if/else statements to determine Skynet's response based on the player's previous positions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Dim PlayerMoves, SkynetMoves As Integer

Dim EndGame As Boolean = False


Dim i As Integer = 1
Public Sub Form1()

If Button1.Text = "X" Then


ElseIf Button2.Text = "X" Then
ElseIf Button3.Text = "X" Then
ElseIf Button4.Text = "X" Then
ElseIf Button5.Text = "X" Then
ElseIf Button6.Text = "X" Then
ElseIf Button7.Text = "X" Then
ElseIf Button8.Text = "X" Then
ElseIf Button9.Text = "X" Then
End If
PlayerMoves = PlayerMoves + 1
TextBox1.Text = (PlayerMoves)
If PlayerMoves = 1 Then
If Button1.Text = "X" Then ' if the player places first in a corner
Button5.Text = "O"
ElseIf Button3.Text = "X" Then
Button5.Text = "O"
ElseIf Button7.Text = "X" Then
Button5.Text = "O"
ElseIf Button9.Text = "X" Then
Button5.Text = "O"
End If
If Button5.Text = "X" Then ' if the player places first in a centre,
select 9
Button9.Text = "O"
End If
If Button2.Text = "X" Then ' if the player places first on a side
Button5.Text = "O"
ElseIf Button4.Text = "X" Then
Button5.Text = "O"
ElseIf Button6.Text = "X" Then
Button5.Text = "O"
ElseIf Button8.Text = "X" Then
Button5.Text = "O"
End If
SkynetMoves = SkynetMoves + 1
TextBox2.Text = (SkynetMoves)
End If
If PlayerMoves = 2 Then
' player started on corner, we selected 5
If Button1.Text = "X" Then
If Button2.Text = "X" Then
Button3.Text = "O"
ElseIf Button3.Text = "X" Then
Button2.Text = "O"
ElseIf Button4.Text = "X" Then
Button7.Text = "O"
ElseIf Button6.Text = "X" Then
Button8.Text = "O"
ElseIf Button7.Text = "X" Then
Button4.Text = "O"
ElseIf Button8.Text = "X" Then
Button2.Text = "O"
ElseIf Button9.Text = "X" Then
Button8.Text = "O"
End If
ElseIf Button3.Text = "X" Then
If Button1.Text = "X" Then
Button2.Text = "O"
ElseIf Button2.Text = "X" Then
Button1.Text = "O"
ElseIf Button4.Text = "X" Then
Button8.Text = "O"
ElseIf Button6.Text = "X" Then
Button9.Text = "O"
ElseIf Button7.Text = "X" Then
Button8.Text = "O"
ElseIf Button8.Text = "X" Then
Button2.Text = "O"
ElseIf Button9.Text = "X" Then
Button6.Text = "O"
End If
ElseIf Button7.Text = "X" Then
If Button1.Text = "X" Then
Button4.Text = "O"
ElseIf Button2.Text = "X" Then
Button8.Text = "O"
ElseIf Button3.Text = "X" Then
Button8.Text = "O"
ElseIf Button4.Text = "X" Then
Button1.Text = "O"
ElseIf Button6.Text = "X" Then
Button8.Text = "O"
ElseIf Button8.Text = "X" Then
Button9.Text = "O"
ElseIf Button9.Text = "X" Then
Button8.Text = "O"
End If
ElseIf Button9.Text = "X" Then
If Button1.Text = "X" Then
Button8.Text = "O"
ElseIf Button2.Text = "X" Then
Button8.Text = "O"
ElseIf Button3.Text = "X" Then
Button6.Text = "O"
ElseIf Button4.Text = "X" Then
Button8.Text = "O"
ElseIf Button6.Text = "X" Then
Button3.Text = "O"
ElseIf Button7.Text = "X" Then
Button8.Text = "O"
ElseIf Button8.Text = "X" Then
Button7.Text = "O"
End If
End If
'player first in centre, we selected 9
If Button5.Text = "X" Then
If Button1.Text = "X" Then
Button3.Text = "O"
ElseIf Button2.Text = "X" Then
Button8.Text = "O"
ElseIf Button3.Text = "X" Then
Button7.Text = "O"
ElseIf Button4.Text = "X" Then
Button6.Text = "O"
ElseIf Button6.Text = "X" Then
Button4.Text = "O"
ElseIf Button7.Text = "X" Then
Button3.Text = "O"
ElseIf Button8.Text = "X" Then
Button2.Text = "O"
End If
End If
'player on edge, we selected 5 (centre)
If Button2.Text = "X" Then
If Button1.Text = "X" Then
Button3.Text = "O"
ElseIf Button3.Text = "X" Then
Button1.Text = "O"
ElseIf Button4.Text = "X" Then
Button1.Text = "O"
ElseIf Button6.Text = "X" Then
Button3.Text = "O"
ElseIf Button7.Text = "X" Then
Button1.Text = "O"
ElseIf Button8.Text = "X" Then
Button1.Text = "O"
ElseIf Button9.Text = "X" Then
Button3.Text = "O"
End If
ElseIf Button4.Text = "X" Then
If Button1.Text = "X" Then
Button7.Text = "O"
ElseIf Button2.Text = "X" Then
Button1.Text = "O"
ElseIf Button3.Text = "X" Then
Button1.Text = "O"
ElseIf Button6.Text = "X" Then
Button1.Text = "O"
ElseIf Button7.Text = "X" Then
Button1.Text = "O"
ElseIf Button8.Text = "X" Then
Button7.Text = "O"
ElseIf Button9.Text = "X" Then
Button1.Text = "O"
End If
ElseIf Button6.Text = "X" Then
If Button1.Text = "X" Then
Button3.Text = "O"
ElseIf Button2.Text = "X" Then
Button3.Text = "O"
ElseIf Button3.Text = "X" Then
Button9.Text = "O"
ElseIf Button4.Text = "X" Then
Button3.Text = "O"
ElseIf Button7.Text = "X" Then
Button3.Text = "O"
ElseIf Button8.Text = "X" Then
Button9.Text = "O"
ElseIf Button9.Text = "X" Then
Button3.Text = "O"
End If
ElseIf Button8.Text = "X" Then
If Button1.Text = "X" Then
Button7.Text = "O"
ElseIf Button2.Text = "X" Then
Button7.Text = "O"
ElseIf Button3.Text = "X" Then
Button7.Text = "O"
ElseIf Button4.Text = "X" Then
Button7.Text = "O"
ElseIf Button6.Text = "X" Then
Button9.Text = "O"
ElseIf Button7.Text = "X" Then
Button9.Text = "O"
ElseIf Button9.Text = "X" Then
Button7.Text = "O"
End If
End If
SkynetMoves = SkynetMoves + 1
TextBox2.Text = (SkynetMoves)
End If
If PlayerMoves = 3 Then
If Button5.Text = "X" Then 'middle, we select 9
If Button1.Text = "X" Then 'we select 3
If Button3.Text = "X" Then
Button7.Text = "O"
ElseIf Button4.Text = "X" Then

End If
ElseIf Button2.Text = "X" Then 'we select 8

ElseIf Button3.Text = "X" Then 'we select 7

ElseIf Button4.Text = "X" Then 'we select 6

ElseIf Button6.Text = "X" Then 'we select 4

ElseIf Button7.Text = "X" Then 'we select 3

ElseIf Button8.Text = "X" Then 'we select 2

End If
End If
End If

End Sub

Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


If Button1.Text = "O" Then
Button1.Text = "O"
ElseIf Button1.Text = "X" Then
Button1.Text = "X"
Else
Button1.Text = "X"
Call Form1()
End If
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click


If Button2.Text = "O" Then
Button2.Text = "O"
ElseIf Button2.Text = "X" Then
Button2.Text = "X"
Else
Button2.Text = "X"
Call Form1()
End If
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
If Button3.Text = "O" Then
Button3.Text = "O"
ElseIf Button3.Text = "X" Then
Button3.Text = "X"
Else
Button3.Text = "X"
Call Form1()
End If
End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click


If Button4.Text = "O" Then
Button4.Text = "O"
ElseIf Button4.Text = "X" Then
Button4.Text = "X"
Else
Button4.Text = "X"
Call Form1()
End If
End Sub

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click


If Button5.Text = "O" Then
Button5.Text = "O"
ElseIf Button5.Text = "X" Then
Button5.Text = "X"
Else
Button5.Text = "X"
Call Form1()
End If
End Sub

Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click


If Button6.Text = "O" Then
Button6.Text = "O"
ElseIf Button6.Text = "X" Then
Button6.Text = "X"
Else
Button6.Text = "X"
Call Form1()
End If
End Sub

Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click


If Button7.Text = "O" Then
Button7.Text = "O"
ElseIf Button7.Text = "X" Then
Button7.Text = "X"
Else
Button7.Text = "X"
Call Form1()
End If
End Sub

Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click


If Button8.Text = "O" Then
Button8.Text = "O"
ElseIf Button8.Text = "X" Then
Button8.Text = "X"
Else
Button8.Text = "X"
Call Form1()
End If
End Sub

Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click


If Button9.Text = "O" Then
Button9.Text = "O"
ElseIf Button9.text = "X" Then
Button9.Text = "X"
Else
Button9.Text = "X"
Call Form1()
End If
End Sub
Private Sub Button10_Click(sender As Object, e As EventArgs) Handles
Button10.Click
Dim frm = New Form1
frm.Show()
End Sub

You might also like