展会信息港展会大全

vb6.0实现五子棋人工智能算法
来源:互联网   发布日期:2011-09-16 09:59:38   浏览:12488次  

导读: starwork 等 级:新手上路帖 子:15专家分:0注 册:2007-1-14 得分:0 五,获胜检查算法。 '***************************************************************************** '** 模块名称: checkwin '** '** 描述:此模块执行以下功能: '**1. 检查是否和棋...

starwork

等 级:新手上路 帖 子:15 专家分:0 注 册:2007-1-14

  得分:0 

vb6.0实现五子棋人工智能算法

五,获胜检查算法。
'*****************************************************************************
'** 模块名称: checkwin
'**
'** 描述: 此模块执行以下功能:
'** 1. 检查是否和棋。
'** 2. 检查电脑是否获胜。
'** 3. 检查玩家是否获胜。
'**
'*****************************************************************************
Sub checkwin()
Dim i, j, k, m, n As Integer
Dim ca As Integer
Dim pa As Integer
Dim cnormal As Integer = 0
For i = 0 To 191
If cflag(i) = False Then
cnormal = cnormal + 1
End If
Next
If cnormal = 190 Then
Label1.Visible = True
Label1.Text = "和棋,请重新开始!"
PictureBox1.Refresh()
theplayflag = False
Exit Sub
End If
'设定和棋规则
For i = 0 To 191
If cflag(i) = True Then
ca = 0
For j = 0 To 9
For k = 0 To 9
If table(j, k) = 1 Then
If cwin(j, k, i) = True Then
ca = ca + 1
End If
End If
Next
Next
If ca = 5 Then
Label1.Visible = True
Label1.Text = "电脑获胜,请重新开始"
PictureBox1.Refresh()
theplayflag = False
Exit Sub
End If
End If
Next
'检查电脑是否获胜
For i = 0 To 191
If pflag(i) = True Then
pa = 0
For j = 0 To 9
For k = 0 To 9
If table(j, k) = 2 Then
If pwin(j, k, i) = True Then
pa = pa + 1
End If
End If
Next
Next
If pa = 5 Then
Label1.Visible = True
Label1.Text = "玩家获胜,请重新开始"
PictureBox1.Refresh()
theplayflag = False
Exit Sub
End If
End If
Next
'检查玩家是否获胜
End Sub
六电脑算法(2)
''' ******** 赋值系统 ********
For i = 0 To 191
If cflag(i) = True Then
For j = 0 To 9
For k = 0 To 9
If table(j, k) = 0 Then
If cwin(j, k, i) = True Then
For m = 0 To 9
For n = 0 To 9
If table(m, n) = 1 Then
If cwin(m, n, i) = True Then
cscore(j, k) = cscore(j, k) + 1
End If
End If
Next
Next
End If
End If
Next
Next
End If
Next
For i = 0 To 191
If pflag(i) = True Then
For j = 0 To 9
For k = 0 To 9
If table(j, k) = 0 Then
If pwin(j, k, i) = True Then
For m = 0 To 9
For n = 0 To 9
If table(m, n) = 2 Then
If pwin(m, n, i) = True Then
pscore(j, k) = pscore(j, k) + 1
End If
End If
Next
Next
End If
End If
Next
Next
End If
Next
''' ******** 赋值系统结束 ********
''' ******** 分值比较算法 ********
Dim a, b, c, d As Integer
Dim cs As Integer = 0
Dim ps As Integer = 0
For i = 0 To 9
For j = 0 To 9
If cscore(i, j) > cs Then
cs = cscore(i, j)
a = i
b = j
End If
Next
Next
For i = 0 To 9
For j = 0 To 9
If pscore(i, j) > ps Then
ps = pscore(i, j)
c = i
d = j
End If
Next
Next
If cs > ps Then
yuandian(a * 30 + 10, b * 30 + 10)
table(a, b) = 1
For i = 0 To 191
If pwin(a, b, i) = True Then
pflag(i) = False
End If
Next
Else
yuandian(c * 30 + 10, d * 30 + 10)
table(c, d) = 1
For i = 0 To 191
If pwin(c, d, i) = True Then
pflag(i) = False
End If
Next
End If
''' ******** 分值比较算法结束 ********
checkwin()
End Sub

七,绘制棋子

'*****************************************************************************
'** 模块名称: yuandian
'**
'** 描述: 此函数主要进行电脑棋子的绘制。
'**
'*****************************************************************************

Sub yuandian(ByVal x As Integer, ByVal y As Integer)
Dim mycolor As Color
Dim g As System.Drawing.Graphics
g = PictureBox1.CreateGraphics
Dim zhx, zhy As Integer
zhx = Int((x - 10) / 30)
zhy = Int((y - 10) / 30)
mycolor = Color.Black
Dim brush1 As System.Drawing.Brush = New SolidBrush(mycolor)
g.FillEllipse(brush1, zhx * 30 + 10, zhy * 30 + 10, 30, 30)
End Sub

赞助本站

相关热词: vb6.0 实现 棋人 工智 能算

AiLab云推荐
推荐内容
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港