|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
以下是引用xiaog在2003-7-28 23:28:00的发言:
[quote]以下是引用doyyi在2003-7-28 11:51:00的发言:
人机对战能在EXCEL中实现吗?
应该可以,附算法公式:
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 '随意走一步
[/quote]
谢了 |
|