连珠五子棋的编程与制作(编辑修改稿)内容摘要:
flag++。 break。 } } n=weight(value,flag)。 if(weightBoard[i][j]n){ weightBoard[i][j]=n。 } } // 左下到右上方向 for(i=RectX2,j=RectY1。 i=RectX1。 i,j++){ if([i][j]!=0){ continue。 } value=0。 flag=0。 for(k=1。 i+k=RectX2 amp。 amp。 k5。 k++){ if([i+k][jk]==tcolor){ value++。 continue。 } if([i+k][jk]==0){ flag++。 break。 } } for(k=1。 ik=RectX1 amp。 amp。 k5。 k++){ if([ik][j+k]==tcolor){ value++。 } if([ik][j+k]==0){ flag++。 break。 } } n=weight(value,flag)。 if(weightBoard[i][j]n){ weightBoard[i][j]=n。 } } } /** * 返回棋子的权重 */ 连珠五子棋的编程与制作 共 31 页,第 13 页 private int weight(int count, int flag) { int weight=0。 switch(count){ case 0:{ if(flag0) weight=200。 else weight=0。 break。 } case 1:{ if(flag0) weight=1000。 else weight=0。 break。 } case 2:{ if(flag0) weight=5000。 else weight=0。 break。 } case 3:{ if(flag0) weight=8000。 else weight=0。 break。 } case 4:{ if(flag0) weight=10000。 else weight=0。 break。 } } return weight。 } /** * 在棋盘中找到最优的位置 */ private void getBetter(int count){ int [][] better = new int [count][2]。 int [][] tempArray = new int [15][15]。 for(int i=0。 i15。 i++){ for(int j=0。 j15。 j++){ tempArray[i][j]=weightBoard[i][j]。 } } for(int i=0。 icount。 i++){ 连珠五子棋的编程与制作 共 31 页,第 14 页 getBiggest(tempArray,better[i][0],better[i][1])。 } bestX=better[0][0]。 bestY=better[0][1]。 } /** *得到权重最大值 */ private void getBiggest(int [][] arr,int x,int y){ int [] temp=new int[2]。 int swt=arr[0][0],tmp=0。 for(int i=0。 i15。 i++){ for(int j=0。 j15。 j++){ if(arr[i][j]swt){ temp[0]=i。 temp[1]=j。 swt=arr[i][j]。 } } } x=temp[0]。 y=temp[1]。 arr[x][y]=0。 } } 、人工智能模块 有了上面填写的两张棋型表,现在要做的就是让电脑知道在哪一点下子。 其中最简单的方法就是便利棋型表 Computer[15][15][4]和 Player[15][15][4],找出其中数值最大的一点,在该点下子即可。 但是这种算法的弱点非常明显,只顾眼前的利益,不能顾全大局。 为了解决这个问题这里引入了“今后几步预测法”具体方法是这样的。 让电脑分析一个可能的弱点,如果在某个位置下子将会形成对手不得不防守的棋型(例如:“冲四”、“活三”):那么下一步对手就必须照你的思路下子防守,如此便完成了第一步的预测。 重新调用棋型表填写算法对预测后的棋进行盘面分析,如果出现了“四三”、“双三”或“双四”等制胜点,那么己方就可以获胜了;否则按照同样的方法向下分析,就可以预测出第二步、 第三步等。 但是要是盘面上没有没有对手防的棋型,那该怎么办呢。 进攻不成不成就得考虑防守,将自己和对手调换位置,然后用上面的方法来预测对手的棋。 这样既可以防守住对方巧妙地攻击,又能待机发动反击。 具体代码 : Analyse(int chessc[][]){ int i, j。 连珠五子棋的编程与制作 共 31 页,第 15 页 chessBoard = new int[17][17]。 for (i = 0。 i = 16。 i++) { for (j = 0。 j = 16。 j++) { if (i == 0 || j == 0 || i == 16 || j == 16) { chessBoard[i][j] = 4。 } else { chessBoard[i][j] = chessc[i 1][j 1]。 } } } } private long pow(int base, int pow){ int i。 long result=1。 for(i=1。 i=pow。 i++){ result*=base。 } return result。 } /** *判断上下位置 */ private long analyseUd(int x, int y, int side){ int tt[][] = new int[17][17]。 int i, j。 int tempx, tempy。 long mark = 0。 int base = BASE。 int uppersign = 0。 int downsign = 0。 int c_count = 1。 for (i = 0。 i 17。 i++) { for (j = 0。 j 17。 j++) { tt[i][j] = chessBoard[i][j]。 } } tt[y][x] = side。 tempx = x。 tempy = y。 if (tt[tempy 1][tempx] != side) { if (tt[tempy 1][tempx] == 0) { uppersign = 1。 } 连珠五子棋的编程与制作 共 31 页,第 16 页 if (tt[tempy 1][tempx] != 0) { uppersign = 0。 } } else { tempy = 1。 while (tt[tempy][tempx] == side) { c_count += 1。 tempy。 } if (tt[tempy][tempx] == 0) { uppersign = 1。 } if (tt[tempy][tempx] != 0) { uppersign = 0。 } } tempx = x。 tempy = y。 if (tt[tempy + 1][tempx] != side) { if (tt[tempy + 1][tempx] == 0) { downsign = 1。 } if (tt[tempy + 1][tempx] != 0) { downsign = 0。 } } else { tempy += 1。 while (tt[tempy][tempx] == side) { c_count += 1。 tempy++。 } if (tt[tempy][tempx] == 0) { downsign = 1。 } if (tt[tempy][tempx] != 0) { downsign = 0。 } } mark += pow(base, c_count)。 if ( (upp。连珠五子棋的编程与制作(编辑修改稿)
相关推荐
长足的发展, 日本便利店是 20 世纪60 年代末才从美国引进的,当时,由于迅速增长的就业妇女、迅速增长的单身家庭、越来越多的家庭妇女在餐桌上使用预煮食品、经济收入的提高以及娱乐活动的增加等诸多因素,使得人们更加追求购物的便利性,从而为便利店的快速发展创造了有利的客观条件。 日本第一家便利店成立于 1969 年,是由日本橘高糕点批发公司按美国模式建立的沃玛特便利连锁集团。 尽管 20 世纪 90
婕达传媒有限公司商业计划书 0创业计划书项目名称:大连婕达传媒有限公司姓 名:王平毕业学校:大连商务职业学院所属院系:信息技术与艺术设计学院电 话:189042682101婕达传媒有限公司商业计划书执行总结传播媒体或称“传媒” 、 “媒体”或“媒介” ,指传播信息资讯的载体,即信息传播过程中从传播者到接受者之间携带和传递信息的一切形式的物质工具;1943
from manufacturing to nonmanufacturing and service industries, we are talking about the car manufacturer belonging to the manufacturing industry, However, the services sector including cleaning,
材料(一般为条料或带料)在控制送进距离机构的控制下,经逐个工位冲制后,便得到一个完整的冲压零件(或半成品)。 这样,一个比较复杂的冲压零件,用一 副多工位级进模即可冲制完成。 在一副多工位级进模中,可以连续完成冲裁、弯曲、拉深、成型等工序。 一般地说,无论冲压零件的形状怎样复杂,冲压工序怎样多,均可用一副多工位级进模冲制完成。 多工位级进模的结构比较复杂,模具制造精度高
} 仓库( 仓库编号 ,仓库名称,仓库内存量,仓库电话,仓库面积,仓库地址) 此为仓库实体对应的关系模式 仓库信息表的数据依赖: {仓库编号 — >仓库名称 } 订货表( 订货编号 ,商品名称,订货价格,订货数量,供应商,订货日期,订购人员) 此为订货表实体对 应的关系模式 订货信息表的数据依赖 {订货编号 — >商品名称 } 进货表( 进货编号 ,商品名称,进货成本,销售价格,进货数量,供应商
,本行已准备好的数据打入并行锁存器进行显示时,串行移位寄存器就可以准备下一行的列数据,而不会影响本行的显示。 LED 点阵显示模块进行的 方法有两种: ( 1)水平方向( X 方向)扫描,即逐列扫描的方式(简称列扫描方式):此时用一个 P口输出列码决定哪一列能亮(相当于位码),用另一个 P 口输出行码(列数据),决定该行上 7 那哪个 LED 亮(相当于段码)。 能亮的列从左到右扫描完 16