If pvp = False Then
If player1Turn = False Then
'If cpu can win
If Button1.Text = "O" And Button2.Text = "O" And Button3.Text = String.Empty Then
Button3.PerformClick()
ElseIf Button1.Text = "O" And Button4.Text = "O" And Button7.Text = String.Empty Then
Button7.PerformClick()
ElseIf Button1.Text = "O" And Button5.Text = "O" And Button9.Text = String.Empty Then
Button9.PerformClick()
ElseIf Button4.Text = "O" And Button5.Text = "O" And Button6.Text = String.Empty Then
Button6.PerformClick()
ElseIf Button2.Text = "O" And Button5.Text = "O" And Button8.Text = String.Empty Then
Button8.PerformClick()
ElseIf Button3.Text = "O" And Button5.Text = "O" And Button7.Text = String.Empty Then
Button7.PerformClick()
ElseIf Button7.Text = "O" And Button8.Text = "O" And Button9.Text = String.Empty Then
Button9.PerformClick()
ElseIf Button3.Text = "O" And Button6.Text = "O" And Button9.Text = String.Empty Then
Button9.PerformClick()
'Block wins
ElseIf Button1.Text = "X" And Button2.Text = "X" And Button3.Text = String.Empty Then
Button3.PerformClick()
ElseIf Button1.Text = "X" And Button4.Text = "X" And Button7.Text = String.Empty Then
Button7.PerformClick()
ElseIf Button1.Text = "X" And Button5.Text = "X" And Button9.Text = String.Empty Then
Button9.PerformClick()
ElseIf Button4.Text = "X" And Button5.Text = "X" And Button6.Text = String.Empty Then
Button6.PerformClick()
ElseIf Button2.Text = "X" And Button5.Text = "X" And Button8.Text = String.Empty Then
Button8.PerformClick()
ElseIf Button3.Text = "X" And Button5.Text = "X" And Button7.Text = String.Empty Then
Button7.PerformClick()
ElseIf Button7.Text = "X" And Button8.Text = "X" And Button9.Text = String.Empty Then
Button9.PerformClick()
ElseIf Button3.Text = "X" And Button6.Text = "X" And Button9.Text = String.Empty Then
Button9.PerformClick()
Else
'If there are no possibilities to win or block user's win
If Button1.Enabled = True Then
Button1.PerformClick()
ElseIf Button9.Enabled = True Then
Button9.PerformClick()
ElseIf Button2.Enabled = True Then
Button2.PerformClick()
ElseIf Button8.Enabled = True Then
Button8.PerformClick()
ElseIf Button3.Enabled = True Then
Button3.PerformClick()
ElseIf Button7.Enabled = True Then
Button7.PerformClick()
ElseIf Button4.Enabled = True Then
Button4.PerformClick()
ElseIf Button6.Enabled = True Then
Button6.PerformClick()
ElseIf Button5.Enabled = True Then
Button5.PerformClick()
End If
End If
End If
End If