⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vbwuziqi.txt

📁 ① 能实现五子棋下棋的智能算法; ② 能按照五子棋的行走规则进行游戏
💻 TXT
📖 第 1 页 / 共 2 页
字号:
  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

 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -