VB五子棋问题,请高手赐教

原创 2004年09月05日 16:00:00

近期做课程设计,做了个五子棋人机对战的程序,但是“悔棋”和“保存棋局”两个功能不会实现,请高手赐教
附源程序:

Option Explicit
Dim comable   As Boolean
Dim comturn   As Boolean
Dim blackturn   As Boolean
Dim whiteturn   As Boolean
Dim comcolor   As Long
Dim black   As Long
Dim white   As Long
Dim i   As Single
Dim j   As Single
Dim table(-5 To 20, -5 To 20)        As Integer '用此二维数组表示棋盘’

Private Sub restart()
Form_Paint
For i = 0 To 15
  For j = 0 To 15
  table(i, j) = 0
  Next j
Next i
black = RGB(0, 0, 0)
white = RGB(255, 255, 255)
If comturn = True Then Call goes(7, 7)
End Sub

Private Sub goes(i As Single, j As Single)         '电脑将子走到table(i,j)’
If comturn = True And table(i, j) = 0 Then
FillColor = comcolor
FillStyle = 0
Dim x   As Single
Dim y   As Single
x = i * 300 + 100
y = j * 300 + 100
Circle (x, y), 100
comturn = False
table(i, j) = 2
End If
End Sub

Private Sub about_Click()
frmAbout.Show
End Sub

Private Sub doubleman_Click()  '双人’
blackturn = True
whiteturn = False
comable = False
comturn = False
restart
End Sub

Private Sub 退出_Click()
Dim i As Integer
 i = MsgBox("你想退出游戏吗?", vbOKCancel + vbExclamation, "提示")
 If i = vbOK Then
  Unload Me
 End If
End Sub

Private Sub Form_Load()
Form_Paint
comturn = True
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)               '人走’
Dim a   As Single
Dim b   As Single
Dim m   As Single
Dim n   As Single
If (x - 100) Mod 300 < 150 Then
      a = x - (x - 100) Mod 300
      ElseIf (x - 100) Mod 300 > 150 Then
      a = x + 300 - (x - 100) Mod 300
End If
If (y - 100) Mod 300 < 150 Then
      b = y - (y - 100) Mod 300
      ElseIf (y - 100) Mod 300 > 150 Then
      b = y + 300 - (y - 100) Mod 300
End If

i = (a - 100) / 300
j = (b - 100) / 300
If (comturn = False) And (table(i, j) = 0) Then
If blackturn = True Then
  FillColor = black
  Else
FillColor = white
End If
FillStyle = 0
Circle (a, b), 100
table(i, j) = 1

If comable = False Then
blackturn = blackturn Xor True
End If   '双人

If comable = True Then
comturn = True
judgeman
comdo
judgecom
End If   '人机对战

End If
End Sub
Private Sub judgeman()  '判断人是否获胜’
  Dim i   As Single
  Dim j   As Single
  For i = 0 To 15
    For j = 0 To 15
    If table(i, j) * table(i, j + 1) * table(i, j + 2) * table(i, j + 3) * table(i, j + 4) = 1 Then
            MsgBox "你赢了,真棒!"
    ElseIf table(i, j) * table(i + 1, j) * table(i + 2, j) * table(i + 3, j) * table(i + 4, j) = 1 Then
            MsgBox "你赢了,真棒!"
    ElseIf table(i, j) * table(i + 1, j + 1) * table(i + 2, j + 2) * table(i + 3, j + 3) * table(i + 4, j + 4) = 1 Then
            MsgBox "你赢了,真棒!"
    ElseIf table(i, j) * table(i - 1, j + 1) * table(i - 2, j + 2) * table(i - 3, j + 3) * table(i - 4, j + 4) = 1 Then
            MsgBox "你赢了,真棒!"
    End If
  Next j
  Next i
End Sub
Private Sub judgecom()  '判断电脑是否获胜’
Dim i   As Single
Dim j   As Single
For i = 0 To 15
For j = 0 To 15
If table(i, j) * table(i, j + 1) * table(i, j + 2) * table(i, j + 3) * table(i, j + 4) = 32 Then
            MsgBox "你输了,继续努力哦!"
    ElseIf table(i, j) * table(i + 1, j) * table(i + 2, j) * table(i + 3, j) * table(i + 4, j) = 32 Then
            MsgBox "你输了,继续努力哦!"
    ElseIf table(i, j) * table(i + 1, j + 1) * table(i + 2, j + 2) * table(i + 3, j + 3) * table(i + 4, j + 4) = 32 Then
            MsgBox "你输了,继续努力哦!"
    ElseIf table(i, j) * table(i - 1, j + 1) * table(i - 2, j + 2) * table(i - 3, j + 3) * table(i - 4, j + 4) = 32 Then
            MsgBox "你输了,继续努力哦!"
End If
Next j
Next i
End Sub

Private Function wantfive(i, j, k) As Boolean        '定式1’
If table(i, j) = 0 And (table(i - 4, j) * table(i - 3, j) * table(i - 2, j) * table(i - 1, j) = k * k * k * k _
                                            Or table(i - 4, j - 4) * table(i - 3, j - 3) * table(i - 2, j - 2) * table(i - 1, j - 1) = k * k * k * k _
                                            Or table(i, j - 4) * table(i, j - 3) * table(i, j - 2) * table(i, j - 1) = k * k * k * k _
                                            Or table(i + 1, j - 1) * table(i + 2, j - 2) * table(i + 3, j - 3) * table(i + 4, j - 4) = k * k * k * k _
                                            Or table(i + 1, j) * table(i + 2, j) * table(i + 3, j) * table(i + 4, j) = k * k * k * k _
                                            Or table(i + 1, j + 1) * table(i + 2, j + 2) * table(i + 3, j + 3) * table(i + 4, j + 4) = k * k * k * k _
                                            Or table(i, j + 1) * table(i, j + 2) * table(i, j + 3) * table(i, j + 4) = k * k * k * k _
                                            Or table(i - 1, j + 1) * table(i - 2, j + 2) * table(i - 3, j + 3) * table(i - 4, j + 4) = k * k * k * k _
                                            Or table(i - 3, i) * table(i - 2, j) * table(i - 1, j) * table(i + 1, j) = k * k * k * k _
                                            Or table(i - 3, j - 3) * table(i - 2, j - 2) * table(i - 1, j - 1) * table(i + 1, j + 1) = k * k * k * k _
                                            Or table(i, j - 3) * table(i, j - 2) * table(i, j - 1) * table(i, j + 1) = k * k * k * k _
                                            Or table(i + 1, j - 1) * table(i + 2, j - 2) * table(i + 3, j - 3) * table(i - 1, j + 1) = k * k * k * k _
                                            Or table(i + 1, j) * table(i + 2, j) * table(i + 3, j) * table(i - 1, j) = k * k * k * k _
                                            Or table(i + 1, j + 1) * table(i + 2, j + 2) * table(i + 3, j + 3) * table(i - 1, j - 1) = k * k * k * k _
                                            Or table(i, j + 1) * table(i, j + 2) * table(i, j + 3) * table(i, j - 1) = k * k * k * k _
                                            Or table(i - 1, j + 1) * table(i - 2, j + 2) * table(i - 3, j + 3) * table(i + 1, j - 1) = k * k * k * k _
                                            Or table(i - 2, j) * table(i - 1, j) * table(i + 1, j) * table(i + 2, j) = k * k * k * k _
                                            Or table(i - 1, j - 1) * table(i - 2, j - 2) * table(i + 1, j + 1) * table(i - 2, j - 2) = k * k * k * k _
                                            Or table(i, j - 2) * table(i, j - 1) * table(i, j + 1) * table(i, j + 2) = k * k * k * k _
                                            Or table(i + 1, j - 1) * table(i + 2, j - 2) * table(i - 1, j + 1) * table(i - 2, j + 2) = k * k * k * k _
                                        ) Then wantfive = True
                                       
End Function
Private Function wantfour(i, j, k) As Boolean      '定式2’
If table(i, j) = 0 And ((table(i - 3, j) = 0 And table(i + 2, j) = 0 And table(i - 2, j) * table(i - 1, j) * table(i + 1, j) = k * k * k) _
                                          Or (table(i - 3, j - 3) = 0 And table(i + 2, j + 2) = 0 And table(i - 2, j - 2) * table(i - 1, j - 1) * table(i + 1, j + 1) = k * k * k) _
                                          Or (table(i, j - 3) = 0 And table(i, j + 2) = 0 And table(i, j - 2) * table(i, j - 1) * table(i, j + 1) = k * k * k) _
                                          Or (table(i + 3, j - 3) = 0 And table(i - 2, j + 2) = 0 And table(i + 2, j - 2) * table(i + 1, j - 1) * table(i - 1, j + 1) = k * k * k) _
                                          Or (table(i + 3, j) = 0 And table(i - 2, j) = 0 And table(i + 2, j) * table(i + 1, j) * table(i - 1, j) = k * k * k) _
                                          Or (table(i + 3, j + 3) = 0 And table(i - 2, j - 2) = 0 And table(i + 2, j + 2) * table(i + 1, j + 1) * table(i - 1, j - 1) = k * k * k) _
                                          Or (table(i, j + 3) = 0 And table(i, j - 2) = 0 And table(i, j + 1) * table(i, j + 2) * table(i, j - 1) = k * k * k) _
                                          Or (table(i - 3, j + 3) = 0 And table(i + 2, j - 2) = 0 And table(i - 2, j + 2) * table(i - 1, j + 1) * table(i + 1, j - 1) = k * k * k) _
                                        ) Then wantfour = True
                                                                                     
  End Function
  Private Function wantfour1(i, j, k) As Boolean      '定式3’
  Dim a(0 To 7)     As Single
  Dim n   As Single
  a(0) = table(i - 3, j) * table(i - 2, j) * table(i - 1, j)
  a(1) = table(i - 3, j - 3) * table(i - 2, j - 2) * table(i - 1, j - 1)
  a(2) = table(i, j - 3) * table(i, j - 2) * table(i, j - 1)
  a(3) = table(i + 3, j - 3) * table(i + 2, j - 2) * table(i + 1, j - 1)
  a(4) = table(i + 3, j) * table(i + 2, j) * table(i + 1, j)
  a(5) = table(i + 1, j + 1) * table(i + 2, j + 2) * table(i + 3, j + 3)
  a(6) = table(i, j + 1) * table(i, j + 2) * table(i, j + 3)
  a(7) = table(i - 1, j + 1) * table(i - 2, j + 2) * table(i - 3, j + 3)
  Dim b(0 To 7)     As Single
  b(0) = table(i + 1, j)
  b(1) = table(i + 1, j + 1)
  b(2) = table(i, j + 1)
  b(3) = table(i - 1, j + 1)
  b(4) = table(i - 1, j)
  b(5) = table(i - 1, j - 1)
  b(6) = table(i, j - 1)
  b(7) = table(i + 1, j - 1)
  For n = 0 To 7
  If table(i, j) = 0 And b(n) = 0 And a(n) = k * k * k Then
    wantfour1 = True
  End If
  Next n
   
  End Function
Private Function want231(i, j, k) As Boolean      '定式4’
Dim a(0 To 7)     As Single
  a(0) = table(i - 2, j) * table(i - 1, j)
  a(1) = table(i - 2, j - 2) * table(i - 1, j - 1)
  a(2) = table(i, j - 2) * table(i, j - 1)
  a(3) = table(i + 2, j - 2) * table(i + 1, j - 1)
  a(4) = table(i + 1, j) * table(i + 2, j)
  a(5) = table(i + 1, j + 1) * table(i + 2, j + 2)
  a(6) = table(i, j + 1) * table(i, j + 2)
  a(7) = table(i - 1, j + 1) * table(i - 2, j + 2)

    If table(i, j) = 0 And ((table(i - 3, j) <> 3 - k And table(i - 3, j - 3) <> 3 - k And a(0) * a(1) = k * k * k * k) _
                                          Or (table(i - 3, j) <> 3 - k And table(i, j - 3) <> 3 - k And a(0) * a(2) = k * k * k * k) _
                                          Or (table(i - 3, j) <> 3 - k And table(i + 3, j - 3) <> 3 - k And a(0) * a(3) = k * k * k * k) _
                                          Or (table(i - 3, j) <> 3 - k And table(i + 3, j + 3) <> 3 - k And a(0) * a(5) = k * k * k * k) _
                                          Or (table(i - 3, j) <> 3 - k And table(i, j + 3) <> 3 - k And a(0) * a(6) = k * k * k * k) _
                                          Or (table(i - 3, j) <> 3 - k And table(i - 3, j + 3) <> 3 - k And a(0) * a(7) = k * k * k * k) _
                                          Or (table(i - 3, j - 3) <> 3 - k And table(i, j - 3) <> 3 - k And a(1) * a(2) = k * k * k * k) _
                                          Or (table(i - 3, j - 3) <> 3 - k And table(i + 3, j - 3) <> 3 - k And a(1) * a(3) = k * k * k * k) _
                                          Or (table(i - 3, j - 3) <> 3 - k And table(i + 3, j) <> 3 - k And a(1) * a(4) = k * k * k * k) _
                                          Or (table(i - 3, j - 3) <> 3 - k And table(i, j + 3) <> 3 - k And a(1) * a(6) = k * k * k * k) _
                                          Or (table(i - 3, j - 3) <> 3 - k And table(i - 3, j + 3) <> 3 - k And a(1) * a(7) = k * k * k * k) _
                                          Or (table(i, j - 3) <> 3 - k And table(i + 3, j - 3) <> 3 - k And a(2) * a(3) = k * k * k * k) _
                                          Or (table(i, j - 3) <> 3 - k And table(i + 3, j) <> 3 - k And a(2) * a(4) = k * k * k * k) _
                                          Or (table(i, j - 3) <> 3 - k And table(i + 3, j + 3) <> 3 - k And a(2) * a(5) = k * k * k * k) _
                                          Or (table(i, j - 3) <> 3 - k And table(i - 3, j + 3) <> 3 - k And a(2) * a(7) = k * k * k * k) _
                                          Or (table(i + 3, j - 3) <> 3 - k And table(i + 3, j) <> 3 - k And a(3) * a(4) = k * k * k * k) _
                                          Or (table(i + 3, j - 3) <> 3 - k And table(i + 3, j + 3) <> 3 - k And a(3) * a(5) = k * k * k * k) _
                                          Or (table(i + 3, j - 3) <> 3 - k And table(i, j + 3) <> 3 - k And a(3) * a(6) = k * k * k * k) _
                                          Or (table(i + 3, j) <> 3 - k And table(i + 3, j + 3) <> 3 - k And a(4) * a(5) = k * k * k * k) _
                                          Or (table(i + 3, j) <> 3 - k And table(i, j + 3) <> 3 - k And a(4) * a(6) = k * k * k * k) _
                                          Or (table(i + 3, j) <> 3 - k And table(i - 3, j + 3) <> 3 - k And a(4) * a(7) = k * k * k * k) _
                                          Or (table(i + 3, j + 3) <> 3 - k And table(i, j + 3) <> 3 - k And a(5) * a(6) = k * k * k * k) _
                                          Or (table(i + 3, j + 3) <> 3 - k And table(i - 3, j + 3) <> 3 - k And a(5) * a(7) = k * k * k * k) _
                                          Or (table(i, j + 3) <> 3 - k And table(i - 3, j + 3) <> 3 - k And a(6) * a(7) = k * k * k * k) _
                                          ) Then want231 = True
  End Function
  Private Function want232(i, j, k) As Boolean      '定式5’
  Dim b(0 To 3)     As Single
  b(0) = table(i - 1, j) * table(i + 1, j)
  b(1) = table(i - 1, j - 1) * table(i + 1, j + 1)
  b(2) = table(i, j - 1) * table(i, j + 1)
  b(3) = table(i + 1, j - 1) * table(i - 1, j + 1)
 
    If table(i, j) = 0 And ((table(i - 2, j) <> 3 - k And table(i + 2, j) <> 3 - k And table(i - 2, j - 2) <> 3 - k And table(i + 2, j + 2) <> 3 - k And b(0) * b(1) = k * k) _
                                        Or (table(i - 2, j) <> 3 - k And table(i + 2, j) <> 3 - k And table(i, j - 2) <> 3 - k And table(i, j + 2) <> 3 - k And b(0) * b(2) = k * k) _
                                        Or (table(i - 2, j) <> 3 - k And table(i + 2, j) <> 3 - k And table(i + 2, j - 2) <> 3 - k And table(i - 2, j + 2) <> 3 - k And b(0) * b(3) = k * k) _
                                        Or (table(i - 2, j - 2) <> 3 - k And table(i + 2, j + 2) <> 3 - k And table(i, j - 2) <> 3 - k And table(i, j + 2) <> 3 - k And b(1) * b(2) = k * k) _
                                        Or (table(i - 2, j - 2) <> 3 - k And table(i + 2, j + 2) <> 3 - k And table(i + 2, j - 2) <> 3 - k And table(i - 2, j + 2) <> 3 - k And b(1) * b(3) = k * k) _
                                        Or (table(i, j - 2) <> 3 - k And table(i, j + 2) <> 3 - k And table(i + 2, j - 2) <> 3 - k And table(i - 2, j + 2) <> 3 - k And b(2) * b(3) = k * k) _
  ) Then want232 = True
  End Function
Function want233(i, j, k) As Boolean     '定式6’
  Dim m   As Single
  Dim n   As Single
  Dim b(0 To 7)     As Single
  Dim b1(0 To 7)     As Single
  Dim a(0 To 7)     As Single
  Dim a1(0 To 7)     As Single
  b(0) = table(i - 1, j)
  b(1) = table(i - 1, j - 1)
  b(2) = table(i, j - 1)
  b(3) = table(i + 1, j - 1)
  b(4) = table(i + 1, j)
  b(5) = table(i + 1, j + 1)
  b(6) = table(i, j + 1)
  b(7) = table(i - 1, j + 1)
  b1(0) = table(i - 2, j)
  b1(1) = table(i - 2, j - 2)
  b1(2) = table(i, j - 2)
  b1(3) = table(i + 2, j - 2)
  b1(4) = table(i + 2, j)
  b1(5) = table(i + 2, j + 2)
  b1(6) = table(i, j + 2)
  b1(7) = table(i - 2, j + 2)
  a(0) = table(i - 2, j) * table(i - 1, j)
  a(1) = table(i - 2, j - 2) * table(i - 1, j - 1)
  a(2) = table(i, j - 2) * table(i, j - 1)
  a(3) = table(i + 1, j - 1) * table(i + 2, j - 2)
  a(4) = table(i + 1, j) * table(i + 2, j)
  a(5) = table(i + 1, j + 1) * table(i + 2, j + 2)
  a(6) = table(i, j + 1) * table(i, j + 2)
  a(7) = table(i - 1, j + 1) * table(i - 2, j + 2)
  a1(0) = table(i - 3, j)
  a1(1) = table(i - 3, j - 3)
  a1(2) = table(i, j - 3)
  a1(3) = table(i + 3, j - 3)
  a1(4) = table(i + 3, j)
  a1(5) = table(i + 3, j + 3)
  a1(6) = table(i, j + 3)
  a1(7) = table(i - 3, j + 3)
      For m = 0 To 3
      For n = 0 To 7
      If (b1(m) <> 3 - k And b1(m + 4) <> 3 - k And a1(n) <> 3 - k And b(m) * b(m + 4) = k * k) And n <> m And n <> m + 4 And a(n) = k * k Then
      want233 = True
      End If
      Next n
      Next m
 
End Function
Private Function wantthree(i As Single, j As Single, k As Single) As Boolean            '定式7’
Dim a(0 To 7)     As Single
Dim n   As Single
a(0) = table(i - 2, j) * table(i - 1, j)
  a(1) = table(i - 2, j - 2) * table(i - 1, j - 1)
  a(2) = table(i, j - 2) * table(i, j - 1)
  a(3) = table(i + 1, j - 1) * table(i + 2, j - 2)
  a(4) = table(i + 1, j) * table(i + 2, j)
  a(5) = table(i + 1, j + 1) * table(i + 2, j + 2)
  a(6) = table(i, j + 1) * table(i, j + 2)
  a(7) = table(i - 1, j + 1) * table(i - 2, j + 2)
For n = 0 To 7
  If table(i, j) = 0 And a(n) = k * k Then
    wantthree = True
    End If
  Next n
End Function


Private Sub comdo()
Dim a   As Single
Dim b   As Single
For a = -5 To 20
For b = -5 To 20
If (a < 0) Or (b < 0) Or (a > 15) Or (b > 15) Then
table(a, b) = 10
End If
  Next b
  Next a
 
    For i = 0 To 15
    For j = 0 To 15
      If comturn = True And wantfive(i, j, 2) = True Then
          Call goes(i, j)
        End If
    Next j
    Next i   '连五子
   
    For i = 0 To 15
      For j = 0 To 15
        If comturn = True And wantfive(i, j, 1) = True Then
        Call goes(i, j)
        End If
      Next j
      Next i   '阻止对方连五子
     
  For i = 0 To 15
  For j = 0 To 15
    If comturn = True And table(i, j) * table(i, j + 1) * table(i, j + 2) = 8 And (table(i, j - 1) = 0 And table(i, j + 3) = 0) Then
          If table(i, j - 2) = 2 Or table(i - 1, j - 1) = 2 Or table(i - 1, j) = 2 Or table(i - 1, j + 1) = 2 Or table(i + 1, j - 1) = 2 Or table(i + 1, j) = 2 Or table(i + 1, j + 1) = 2 Then
        Call goes(i, j - 1)
        Else
        Call goes(i, j + 3)
        End If
  ElseIf comturn = True And table(i, j) * table(i + 1, j) * table(i + 2, j) = 8 And (table(i - 1, j) = 0 And table(i + 3, j)) = 0 Then
        If table(i - 2, j) = 2 Or table(i - 1, j - 1) = 2 Or table(i, j - 1) = 2 Or table(i + 1, j - 1) = 2 Or table(i - 1, j + 1) = 2 Or table(i, j + 1) = 2 Or table(i + 1, j + 1) = 2 Then
        Call goes(i - 1, j)
        Else
        Call goes(i + 3, j)
        End If
  ElseIf comturn = True And table(i, j) * table(i + 1, j + 1) * table(i + 2, j + 2) = 8 And (table(i - 1, j - 1) = 0 And table(i + 3, j + 3) = 0) Then
    If table(i - 2, j - 2) = 2 Or table(i - 1, j) = 2 Or table(i - 1, j + 1) = 2 Or table(i, j - 1) = 2 Or table(i, j + 1) = 2 Or table(i + 1, j - 1) = 2 Or table(i + 1, j) = 2 Then
    Call goes(i - 1, j - 1)
    Else
    Call goes(i + 3, j + 3)
    End If
  ElseIf comturn = True And table(i, j) * table(i - 1, j + 1) * table(i - 2, j + 2) = 8 And (table(i + 1, j - 1) = 0 And table(i - 3, j + 3) = 0) Then
    If table(i + 2, j - 2) = 2 Or table(i - 1, j - 1) = 2 Or table(i, j - 1) = 2 Or table(i - 1, j) = 2 Or table(i + 1, j) = 2 Or table(i + 1, j + 1) = 2 Or table(i, j + 1) = 2 Then
    Call goes(i + 1, j - 1)
    Else
    Call goes(i - 3, j + 3)
    End If
    End If
    Next j
    Next i   '将自己连成四点一线
   
    For i = 0 To 15
    For j = 0 To 15
      If comturn = True And wantfour(i, j, 2) = True Then
      Call goes(i, j)
      End If
    Next j
    Next i   '将自己连成四点一线
   
    For i = 0 To 15
        For j = 0 To 15
        If comturn = True And wantfour1(i, j, 2) = True Then
        Call goes(i, j)
        End If
        Next j
        Next i   '叫吃
       
    For i = 0 To 15
    For j = 0 To 15
      If comturn = True And table(i, j) * table(i, j + 1) * table(i, j + 2) = 1 And (table(i, j - 1) = 0 And table(i, j + 3) = 0) Then
      If table(i, j - 2) = 1 Or table(i - 1, j - 1) = 1 Or table(i - 1, j) = 1 Or table(i - 1, j + 1) = 1 Or table(i + 1, j - 1) = 1 Or table(i + 1, j) = 1 Or table(i + 1, j + 1) = 1 Then
        Call goes(i, j - 1)
        Else
        Call goes(i, j + 3)
        End If
  ElseIf comturn = True And table(i, j) * table(i + 1, j) * table(i + 2, j) = 1 And (table(i - 1, j) = 0 And table(i + 3, j) = 0) Then
    If table(i - 2, j) = 1 Or table(i - 1, j - 1) = 1 Or table(i, j - 1) = 1 Or table(i + 1, j - 1) = 1 Or table(i - 1, j + 1) = 1 Or table(i, j + 1) = 1 Or table(i + 1, j + 1) = 1 Then
        Call goes(i - 1, j)
        Else
        Call goes(i + 3, j)
        End If
    ElseIf comturn = True And table(i, j) * table(i + 1, j + 1) * table(i + 2, j + 2) = 1 And (table(i - 1, j - 1) = 0 And table(i + 3, j + 3) = 0) Then
    If table(i - 2, j - 2) = 1 Or table(i - 1, j) = 1 Or table(i - 1, j + 1) = 1 Or table(i, j - 1) = 1 Or table(i, j + 1) = 1 Or table(i + 1, j - 1) = 1 Or table(i + 1, j) = 1 Then
    Call goes(i - 1, j - 1)
    Else
    Call goes(i + 3, j + 3)
    End If
    ElseIf comturn = True And table(i, j) * table(i - 1, j + 1) * table(i - 2, j + 2) = 1 And (table(i + 1, j - 1) = 0 And table(i - 3, j + 3) = 0) Then
    If table(i + 2, j - 2) = 1 Or table(i - 1, j - 1) = 1 Or table(i, j - 1) = 1 Or table(i - 1, j) = 1 Or table(i + 1, j) = 1 Or table(i + 1, j + 1) = 1 Or table(i, j + 1) = 1 Then
    Call goes(i + 1, j - 1)
    Else
    Call goes(i - 3, j + 3)
    End If
    End If
    Next j
    Next i   '阻止对方四点一线
         
    For i = 0 To 15
    For j = 0 To 15
    If comturn = True And wantfour(i, j, 1) = True Then
    Call goes(i, j)
    End If
    Next j
    Next i   '阻止对方四点一线
   
    For i = 0 To 15
    For j = 0 To 15
    If comturn = True And (want231(i, j, 1) = True _
                                              Or want232(i, j, 1) = True _
                                              Or want233(i, j, 1) = True) Then
    Call goes(i, j)
    End If
    Next j
    Next i   '阻止对方走双飞燕
   
    For i = 0 To 15
    For j = 0 To 15
    If comturn = True And (want231(i, j, 2) = True _
                                                  Or want232(i, j, 2) = True _
                                                  Or want233(i, j, 2) = True) Then
    Call goes(i, j)
    End If
    Next j
    Next i   '走双飞燕
   
       
       
        For i = 0 To 15
        For j = 0 To 15
        If comturn = True And wantfour1(i, j, 1) = True Then
        Call goes(i, j)
        End If
        Next j
        Next i   '防止叫吃
         
  For i = 0 To 15
  For j = 0 To 15
  If comturn = True And wantthree(i, j, 1) = True Then
  Call goes(i, j)
  End If
  Next j
  Next i   '挡对方两子一线的
 
  For i = 0 To 15
  For j = 0 To 15
  If comturn = True And wantthree(i, j, 2) = True Then
  Call goes(i, j)
  End If
  Next j
  Next i   '连自己两点一线的
 
  For i = 0 To 15
  For j = 0 To 15
  If comturn = True And table(i, j) = 0 And (table(i - 1, j) * table(i + 1, j) = 1 _
                                                                              Or table(i - 1, j + 1) * table(i + 1, j + 1) = 1 _
                                                                              Or table(i, j - 1) * table(i, j + 1) = 1 _
                                                                              Or table(i + 1, j - 1) * table(i - 1, j + 1) = 1 _
                                                                              ) Then
                                                                              Call goes(i, j)
  End If
  Next j
  Next i   '断
 
 
  For i = 0 To 15
  For j = 0 To 15
  If comturn = True And table(i, j) = 0 And (table(i - 1, j) * table(i + 1, j) = 4 _
                                                                              Or table(i - 1, j + 1) * table(i + 1, j + 1) = 4 _
                                                                              Or table(i, j - 1) * table(i, j + 1) = 4 _
                                                                              Or table(i + 1, j - 1) * table(i - 1, j + 1) = 4 _
                                                                              ) Then
                                                                              Call goes(i, j)
  End If
  Next j
  Next i   '粘
 
  For i = 0 To 15
  For j = 0 To 15
      If comturn = True And table(i, j) = 1 And (table(i - 1, j - 1) = 0 Or table(i, j - 1) = 0 Or table(i + 1, j - 1) = 0 Or table(i - 1, j) = 0 Or table(i + 1, j) = 0 Or table(i - 1, j + 1) = 0 Or table(i, j + 1) = 0 Or table(i + 1, j + 1) = 0) Then
      If table(i - 1, j - 1) = 0 Then
          Call goes(i - 1, j - 1)
          ElseIf table(i + 1, j + 1) = 0 Then
          Call goes(i + 1, j + 1)
          ElseIf table(i, j - 1) = 0 Then
          Call goes(i, j - 1)
          ElseIf table(i, j + 1) = 0 Then
          Call goes(i, j + 1)
          ElseIf table(i + 1, j - 1) = 0 Then
          Call goes(i + 1, j - 1)
          ElseIf table(i - 1, j + 1) = 0 Then
          Call goes(i - 1, j + 1)
          ElseIf table(i - 1, j) = 0 Then
          Call goes(i - 1, j)
          ElseIf table(i + 1, j) = 0 Then
          Call goes(i + 1, j)
          End If
  End If
  Next j
  Next i   '随意走一步
End Sub

Private Sub Form_Paint()  '以(100,100)为左上角坐标画一个16*16,每格边长为300的棋盘’
Cls
Dim x   As Single
Dim y   As Single
x = 100
y = 100
While x < 4300
  x = x + 300
  Line (x, 100)-(x, 4600)
Wend
While y < 4300
  y = y + 300
  Line (100, y)-(4600, y)
Wend
Line (50, 50)-(50, 4650)
Line (50, 50)-(4650, 50)
Line (50, 4650)-(4650, 4650)
Line (4650, 50)-(4650, 4650)
Line (100, 100)-(4600, 100)
Line (100, 100)-(100, 4600)
Line (4600, 100)-(4600, 4600)
Line (100, 4600)-(4600, 4600)
End Sub

Private Sub 规则_Click()
MsgBox "双方轮流出子,最先五子连成一线者胜"
End Sub

Private Sub 人先_Click()
blackturn = True
whiteturn = False
comable = True
comturn = False
comcolor = RGB(255, 255, 255)
restart
End Sub

Private Sub 机先_Click()
blackturn = False
whiteturn = True
comable = True
comturn = True
comcolor = RGB(0, 0, 0)
restart
End Sub

 

初学者,请大家赐教

题目:品尝饮料 一、    要求1. 使用命令行参数(饮料类型),输出该饮料类型的味道,如:当命令行参数为1时,结果如下:E:\>java testExam 1咖啡:苦2.     如果没有该种饮料...
  • hardjx123
  • hardjx123
  • 2018年01月09日 13:34
  • 11

五子棋过程中用到的知识【flash as3 】

flash as3编写的五子棋小游戏
  • u010955640
  • u010955640
  • 2015年05月02日 18:09
  • 445

五子棋(人机)-alpha-beta剪枝

alpha:表示目前为止找到的最小数 beta:表示目前为止找到的最大数 1.极大层的上一层是极小层。一方面极大层找的是自己的子节点中的最大值,另一方面极大层的上一层找的是极大层们提供的节点中的最小一...
  • ChinaJane163
  • ChinaJane163
  • 2016年09月21日 18:36
  • 1703

教你怎样成为C++高手

1.把C++当成一门新的语言学习(和C没啥关系!真的。); 2.看《Thinking In C++》,不要看《C++变成死相》(C++编程思想,翻译的非常差); 3.看《The C++ Program...
  • hellokandy
  • hellokandy
  • 2016年10月24日 11:07
  • 488

【C++】实现图形界面五子棋

图形界面的五子棋就是在普通“黑框框”下面实现五子棋的基础上引用了图形库,本文不在这里介绍相应的图形库。 下面给出代码: #include #include #include #inc...
  • ArchyLi
  • ArchyLi
  • 2017年04月22日 15:44
  • 2205

【五子棋AI循序渐进】发布一个完整的有一定棋力的版本(含源码)

本博文来自于:http://www.cnblogs.com/zcsor/archive/2012/12/25/2832820.html       经过这半年左右的学习和探索,现在对五子棋A...
  • cjianwyr
  • cjianwyr
  • 2017年02月07日 16:32
  • 1326

java-----五子棋小游戏(四)-----解决闪烁问题(双缓冲)

一、双缓冲        当数据量很大时,绘图可能需要几秒钟甚至更长的时间,而且有时还会出现闪烁现象,为了解决这些问题,可采用双缓冲技术来绘图。...
  • u011459278
  • u011459278
  • 2014年04月14日 22:44
  • 1439

请高手个忙可以

Android知识库 只有对系统持续运行指标有明确要求的系统才需要进行这种类型的测试现在运行看看,这样我们可以知道提前升的天数 SpringSide .学习策略是指学习过程中系统所采用的推理策略你计...
  • gongyanli2797
  • gongyanli2797
  • 2017年01月26日 17:01
  • 124

单机版五子棋【JAVA】

单机版五子棋 功能实现: 1、设计主框架,界面。 2、利用ActionListener接口实现按钮事件的监听。 3、重新开始功能的实现。 4、悔棋功能的实现。 5、退出功能的实现。 6、棋盘中棋子点...
  • lin14543
  • lin14543
  • 2016年07月10日 09:10
  • 6986

用javascript实现五子棋(一)

大学毕业进了公司学了几个月的web开发,只会用jquery做事,但是又不甘心,又想要深入的学习一下js,但是无论怎么学都感觉自己抓不到要领。于是决定通过写js游戏来锻炼一下自己。 一、游戏背景画面 既...
  • show_me_the_world
  • show_me_the_world
  • 2015年10月04日 00:50
  • 9910
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:VB五子棋问题,请高手赐教
举报原因:
原因补充:

(最多只允许输入30个字)