大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> NET专区 -> VB.NET实现五子棋的人工智能(2)

VB.NET实现五子棋的人工智能(2)

时间: 2021-07-31 作者:daque

四,处置鼠标事变 '*****************************************************************************'** 模块称呼: themousedown'**'** 刻画: 此因变量重要举行以次功效:'** 1. 判决暂时游戏标记能否灵验。'** 2. 将本质坐标变化成假造坐标。'** 3. 绘制玩家的棋子。'** 4. 实行查看成功因变量。'** 5. 实行电脑算法因变量。'**'*****************************************************************************sub themousedown(byval x as integer, byval y as integer)if theplayflag = false thenexit subend if'查看游戏状况能否灵验dim i, j as integerdim zhx, zhy as integerzhx = int((x - 10) / 30)zhy = int((y - 10) / 30)for i = 0 to 9for j = 0 to 9if table(zhx, zhy) > 0 thenexit subend ifnextnext'查看暂时鼠圈点击的网格能否灵验dim mycolor as colordim g as system.drawing.graphicsg = picturebox1.creategraphicsmycolor = color.whitedim brush1 as system.drawing.brush = new solidbrush(mycolor)g.fillellipse(brush1, zhx * 30 + 10, zhy * 30 + 10, 30, 30)'绘制玩家的棋子table(zhx, zhy) = 2for i = 0 to 191if cwin(zhx, zhy, i) = true thencflag(i) = falseend ifnext'重设电脑的成功标记checkwin()'查看暂时玩家能否成功diannao()'挪用电脑算法end sub   五、成功查看算法。'*****************************************************************************'** 模块称呼: checkwin'**'** 刻画: 此模块实行以次功效:'** 1. 查看能否和棋。'** 2. 查看电脑能否成功。'** 3. 查看玩家能否成功。'**'*****************************************************************************sub checkwin()dim i, j, k, m, n as integerdim ca as integerdim pa as integerdim cnormal as integer = 0for i = 0 to 191if cflag(i) = false thencnormal = cnormal + 1end ifnextif cnormal = 190 thenlabel1.visible = truelabel1.text = "和棋,请从新发端!"picturebox1.refresh()theplayflag = falseexit subend if'设定和棋准则for i = 0 to 191if cflag(i) = true thenca = 0for j = 0 to 9for k = 0 to 9if table(j, k) = 1 thenif cwin(j, k, i) = true thenca = ca + 1end ifend ifnextnextif ca = 5 thenlabel1.visible = truelabel1.text = "电脑成功,请从新发端"picturebox1.refresh()theplayflag = falseexit subend ifend ifnext'查看电脑能否成功for i = 0 to 191if pflag(i) = true thenpa = 0for j = 0 to 9for k = 0 to 9if table(j, k) = 2 thenif pwin(j, k, i) = true thenpa = pa + 1end ifend ifnextnextif pa = 5 thenlabel1.visible = truelabel1.text = "玩家成功,请从新发端"picturebox1.refresh()theplayflag = falseexit subend ifend ifnext'查看玩家能否成功end sub  六、电脑算法'*****************************************************************************'** 模块称呼: diannao'**'** 刻画: 此步调重要实行以次功效:'** 1. 初始化赋值体例。'** 2. 赋值巩固算法。'** 3. 计划电脑和玩家的最好报复位。'** 4. 比拟电脑和玩家的最好报复位并确定电脑的最好战略。'** 5. 实行查看成功因变量。'**'*****************************************************************************sub diannao()dim i, j, k, m, n as integerdim dc as integerdim cab as integerdim pab as integerfor i = 0 to 9for j = 0 to 9pscore(i, j) = 0cscore(i, j) = 0nextnext'初始化赋值数组''' ******** 电脑巩固算法 ********for i = 0 to 191if cflag(i) = true thencab = 0for j = 0 to 9for k = 0 to 9if table(j, k) = 1 thenif cwin(j, k, i) = true thencab = cab + 1end ifend ifnextnextselect case cabcase 3for m = 0 to 9for n = 0 to 9if table(m, n) = 0 thenif cwin(m, n, i) = true thencscore(m, n) = cscore(m, n) + 5end ifend ifnextnextcase 4for m = 0 to 9for n = 0 to 9if table(m, n) = 0 thenif cwin(m, n, i) = true thenyuandian(m * 30 + 10, n * 30 + 10)table(m, n) = 1for dc = 0 to 191if pwin(m, n, dc) = true thenpflag(dc) = falsecheckwin()exit subend ifnextend ifend ifnextnextend selectend ifnextfor i = 0 to 191if pflag(i) = true thenpab = 0for j = 0 to 9for k = 0 to 9if table(j, k) = 2 thenif pwin(j, k, i) = true thenpab = pab + 1end ifend ifnextnextselect case pabcase 3for m = 0 to 9for n = 0 to 9if table(m, n) = 0 thenif pwin(m, n, i) = true thenpscore(m, n) = pscore(m, n) + 30end ifend ifnextnextcase 4for m = 0 to 9for n = 0 to 9if table(m, n) = 0 thenif pwin(m, n, i) = true thenyuandian(m * 30 + 10, n * 30 + 10)table(m, n) = 1for dc = 0 to 191if pwin(m, n, dc) = true thenpflag(dc) = falsecheckwin()exit subend ifnextend ifend ifnextnextend selectend ifnext''' ******** 电脑巩固算法中断 ********' ******** 赋值体例 ********for i = 0 to 191if cflag(i) = true thenfor j = 0 to 9for k = 0 to 9if table(j, k) = 0 thenif cwin(j, k, i) = true thenfor m = 0 to 9for n = 0 to 9if table(m, n) = 1 thenif cwin(m, n, i) = true thencscore(j, k) = cscore(j, k) + 1end ifend ifnextnextend ifend ifnextnextend ifnextfor i = 0 to 191if pflag(i) = true thenfor j = 0 to 9for k = 0 to 9if table(j, k) = 0 thenif pwin(j, k, i) = true thenfor m = 0 to 9for n = 0 to 9if table(m, n) = 2 thenif pwin(m, n, i) = true thenpscore(j, k) = pscore(j, k) + 1end ifend ifnextnextend ifend ifnextnextend ifnext''' ******** 赋值体例中断 ********''' ******** 分值比拟算法 ********dim a, b, c, d as integerdim cs as integer = 0dim ps as integer = 0for i = 0 to 9for j = 0 to 9if cscore(i, j) > cs thencs = cscore(i, j)a = ib = jend ifnextnextfor i = 0 to 9for j = 0 to 9if pscore(i, j) > ps thenps = pscore(i, j)c = id = jend ifnextnextif cs > ps thenyuandian(a * 30 + 10, b * 30 + 10)table(a, b) = 1for i = 0 to 191if pwin(a, b, i) = true thenpflag(i) = falseend ifnextelseyuandian(c * 30 + 10, d * 30 + 10)table(c, d) = 1for i = 0 to 191if pwin(c, d, i) = true thenpflag(i) = falseend ifnextend if''' ******** 分值比拟算法中断 ********checkwin()end sub   七、绘制棋子'*****************************************************************************'** 模块称呼: yuandian'**'** 刻画: 此因变量重要举行电脑棋子的绘制。'**'*****************************************************************************sub yuandian(byval x as integer, byval y as integer)dim mycolor as colordim g as system.drawing.graphicsg = picturebox1.creategraphicsdim zhx, zhy as integerzhx = int((x - 10) / 30)zhy = int((y - 10) / 30)mycolor = color.blackdim brush1 as system.drawing.brush = new solidbrush(mycolor)g.fillellipse(brush1, zhx * 30 + 10, zhy * 30 + 10, 30, 30)end

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.