| 订阅 | 在线投稿
分享
 
 
 

使用vb.net实现五子棋的人工智能5电脑算法2

来源:互联网网民  宽屏版  评论
2006-12-17 09:28:19

使用vb.net实现五子棋的人工智能5电脑算法2

使用vb.net实现五子棋的人工智能5电脑算法2

五子棋的人工智能

———— 利用策略类AI和vb.net实现五子棋

作者:张宇

六电脑算法(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

 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
使用vb.net实现五子棋的人工智能5电脑算法2 使用vb.net实现五子棋的人工智能5电脑算法2 五子棋的人工智能 ———— 利用策略类AI和vb.net实现五子棋 作者:张宇 六电脑算法(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 完
󰈣󰈤
 
 
 
>>返回首页<<
 
 热帖排行
 
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
©2005- 王朝网络 版权所有