基于IOS平台的游戏五子棋设计与实现好命题方向,来吧这里给你本回答由网友推荐山东信息网
#include <iostream>#include <conio.h>#include <windows.h>#include <stdlib.h>#include <stdio.h>using namespace std;int ChessData[15][15] ={0};int GuangbiaoData[2]={8,8};int ChessStepData[255][2]={0};void gotoxy(int x, int y) //gotoxy在TC中是在system.h库文件里的一个函数,但是在VC中没有这个函数,所以在网上找到了这个函数以实现同样的功能。//只有这一个函数是网上找的,别的全部我自己写的。{ COORD c; c.X=x-1; c.Y=y-1; SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c); }void GotoChess(int x,int y){x=3*x-2;y=2*y-1;gotoxy(x,y);}void Move(int MoveData) //输入参数为用户输入的方向(1表示上,2表示下,3表示左,4表示右){switch (MoveData){case 1:GuangbiaoData[1]-=1;break;case 2:GuangbiaoData[1]+=1;break;case 3:GuangbiaoData[0]-=1;break;case 4:GuangbiaoData[0]+=1;break;default:cout<<"Move函数出错"<<endl;}GotoChess(GuangbiaoData[0],GuangbiaoData[1]);}int Get(int *data) //该函数的功能是用户的按键,并转化为01234567(0表示输入错误,1表示上,2表示下,3表示左,4表示右,5表示落子,6表示悔棋,7表示退出。){ //并返回输入的用户号码(共同键返回3),错误则返回0int temp;temp=getch();if (temp==224) { temp=getch(); switch (temp) { case 72:*data=1;break; case 80:*data=2;break; case 75:*data=3;break; case 77:*data=4;break; default:printf("Get函数出错"); } return 2;}else { switch (temp) { case 'w': case 'W':*data=1;return 1;break; case 's': case 'S':*data=2;return 1;break; case 'a': case 'A':*data=3;return 1;break; case 'd': case 'D':*data=4;return 1;break; case 13 :*data=5;return 2;break; case 32 :*data=5;return 1;break; case 8 :*data=6;break; case 27 :*data=7;break; default:*data=0 ;return 0;break; } return 3;}}void MoveToEnd(){gotoxy(1,30);}int LogicBeOut(int a,int b){if (a==-1||a==15||b==-1||b==15) return 1;else return 0;}int win(int v){int i=1,j=1,a=0,b=0;while (ChessData[a=GuangbiaoData[0]-i-1][b=GuangbiaoData[1]-i-1]==v*2&&!LogicBeOut(a,b)) i++;while (ChessData[a=GuangbiaoData[0]+j-1][b=GuangbiaoData[1]+j-1]==v*2&&!LogicBeOut(a,b)) j++;if (i+j-1>=5) return 1;i=1,j=1,a=0,b=0;while (ChessData[a=GuangbiaoData[0]+i-1][b=GuangbiaoData[1]-i-1]==v*2&&!LogicBeOut(a,b)) i++;while (ChessData[a=GuangbiaoData[0]-j-1][b=GuangbiaoData[1]+j-1]==v*2&&!LogicBeOut(a,b)) j++;if (i+j-1>=5) return 1;i=1,j=1,a=0,b=0;while (ChessData[a=GuangbiaoData[0]-i-1][b=GuangbiaoData[1]-1]==v*2&&!LogicBeOut(a,b)) i++;while (ChessData[a=GuangbiaoData[0]+j-1][b=GuangbiaoData[1]-1]==v*2&&!LogicBeOut(a,b)) j++;if (i+j-1>=5) return 1;i=1,j=1,a=0,b=0;while (ChessData[a=GuangbiaoData[0]-1][b=GuangbiaoData[1]-i-1]==v*2&&!LogicBeOut(a,b)) i++;while (ChessData[a=GuangbiaoData[0]-1][b=GuangbiaoData[1]+j-1]==v*2&&!LogicBeOut(a,b)) j++;if (i+j-1>=5) return 1;return 0;}void NewShow() //新棋局的开始{int i,j;for (i=0;i<15;i++) for (j=0;j<15;j++) ChessData[i][j]=0;system("cls");for (i=1;i<=29;i++){ for (j=1;j<=43;j++) if(i%2==1) cout<<'-'; else if (j%3==1) cout<<'|'; else cout<<' '; cout<<endl;}GuangbiaoData[0]=8;GuangbiaoData[1]=8;MoveToEnd();cout<<"现在请用户1下棋 "<<endl;cout<<"用户1使用 w,s,a,d移动光标,空格键落子"<<endl;cout<<"用户2使用各方向键移动光标,回车键落子"<<endl;cout<<"按下Backspace键悔棋,按下esc返回主菜单"<<endl;GotoChess(8,8);}int BeOut(int data){int Xiuzheng[2],New[2];switch (data){case 1:Xiuzheng[0]=0;Xiuzheng[1]=-1 ;break;case 2:Xiuzheng[0]=0;Xiuzheng[1]=1;break;case 3:Xiuzheng[0]=-1;Xiuzheng[1]=0;break;case 4:Xiuzheng[0]=1;Xiuzheng[1]=0 ;break;case 5:Xiuzheng[0]=0;Xiuzheng[1]=0 ;break;default:printf("BeOut函数出错");}New[0]=GuangbiaoData[0]+Xiuzheng[0];New[1]=GuangbiaoData[1]+Xiuzheng[1];if (New[0]>15||New[0]<1||New[1]>15||New[1]<1) return 1;else return 0; }void UserChoose(int * choice){ system("cls");printf("________________________________________________________________________________");printf("________________________________________________________________________________");printf(" $1.单人游戏 ");printf(" 2.双人游戏 ");printf(" 3.退出游戏 ");printf(" 4.游戏帮助 ");printf("________________________________________________________________________________");printf("________________________________________________________________________________");printf(" ");printf(" 开心五子棋 ");printf(" ");printf(" 出品人:张云聪 ");printf(" 学号:067108034 ");printf(" 指导老师:邵艳玲 ");printf(" ");printf(" ");printf(" 温馨提示,游戏时请把窗口最大化,以达到最佳效果 ");printf("________________________________________________________________________________");int temp=0,i=0;do{ if ((temp=getch())==224) { temp=getch(); if (temp==72&&i!=0) { gotoxy(34,3+i); printf(" "); i--; gotoxy(34,3+i); printf("$"); gotoxy(0,0); } else if(temp==80&&i!=3) { gotoxy(34,3+i); printf(" "); i++; gotoxy(34,3+i); printf("$"); gotoxy(0,0); } } else if (temp==13) {*choice=i+1;return;} else if (temp==27) exit(1); else if (temp=='1'||temp=='2'||temp=='3'||temp=='4') {*choice=temp-48;return;}}while(1);}int CannotDo(int v1,int v2,int MoveData,int choice) //第一个输入值为按键的用户号,第二个是本应该按键的用户号,第三个为按下键的对应值,第四个键代表游戏模式。{if (v1==3) return 0; //如果用户输入的为共用按键,则CannotDo为假else if (v1==0) return 1;//如果用户输入错误,则CannotDo为真else if (v1!=v2&&choice==2) return 1; //如果不该此用户输入,而用户进行了输入,则CannotDo为真if (BeOut(MoveData)) return 1; //如果移动出边界则CannotDo为真return 0;}int CannotLuozi() //判断是否可以落子。{if (ChessData[GuangbiaoData[0]-1][GuangbiaoData[1]-1]) return 1;else return 0;}int luozi(int v) //玩家v落子。{ ChessData[GuangbiaoData[0]-1][GuangbiaoData[1]-1]+=v*2;if (v==1) cout<<'O';else if (v==2) cout<<'X';else cout<<"luozi函数出错";if (win(v)) {MoveToEnd();printf("玩家%d获得了胜利! \n",v);for (int i=1;i<=240;i++) cout<<' ';GotoChess(GuangbiaoData[0],GuangbiaoData[1]);getch();return 1;}MoveToEnd();cout<<"现在请用户"<<v%2+1<<"下棋 ";GotoChess(GuangbiaoData[0],GuangbiaoData[1]);return 0;}void HuiQi(int step) //输入的是当前的要悔的棋是第几步{GuangbiaoData[0]=ChessStepData[step-1][0];GuangbiaoData[1]=ChessStepData[step-1][1];ChessData[GuangbiaoData[0]-1][GuangbiaoData[1]-1]=0;GotoChess(GuangbiaoData[0],GuangbiaoData[1]);printf("-");MoveToEnd();cout<<"现在请用户"<<(step+1)%2+1<<"下棋 ";GotoChess(GuangbiaoData[0],GuangbiaoData[1]);}int DataGetAndChoose(int choice) { int MoveData=0,i=0,temp; //MoveData 0表示不可移动,1表示上,2表示下,3表示左,4表示右,5表示落子,6表示悔棋,7表示退出。while(1){loop: while (temp=Get(&MoveData),CannotDo(temp,i%2+1,MoveData,choice)); switch (MoveData) { case 1: case 2: case 3: case 4:Move(MoveData);break; case 7:return 0; case 6: if (i==0) {MoveToEnd();printf("现在无法悔棋 ");GotoChess(GuangbiaoData[0],GuangbiaoData[1]);} else HuiQi(i--); break; case 5: if (CannotLuozi()) goto loop; if(luozi(i%2+1)) return 0; ChessStepData[i][0]=GuangbiaoData[0]; ChessStepData[i][1]=GuangbiaoData[1]; i++; break; default:printf("DataGetAndChoose函数出错");break; }}return 1; }void ShowHelp(){system("cls");printf("********************************************************************************");printf("********************************************************************************");printf("****** 单人游戏供用户一个人自己与自己下棋研究棋局之用 ******");printf("****** 双人游戏中,用户1使用wsad控制方向,按空格落子 ******");printf("****** 用户2按方向键控制方向,回车键落子 ******");printf("****** 游戏过程中按esc返回主菜单 ******");printf("****** 游戏过程中退格键悔棋 ******");printf("****** 双人模式中某人下棋时,另一个用户无法控制光标与落子 ******");printf("****** ******"); printf("****** 帮助 ******"); printf("****** 按任意键返回 ******"); printf("********************************************************************************"); printf("********************************************************************************");getch();}int main(){int choice=0;system("color 5b");choose: UserChoose(&choice);if (choice<1||choice>4) goto choose;if (choice==3) {printf("\n谢谢您的使用,再见 "); getch();return 0;}if (choice==4) {ShowHelp(); goto choose;}NewShow();DataGetAndChoose(choice);main();return 0;}//这段代码已经实现了悔棋。
五子棋的AI构想 有句话叫“当局者迷,旁观者清。”,但这句话在由AI所控制的计算机玩家上是不成立的,因为计算机必须知道有那些获胜方式,并计算出每下一步棋到棋盘上任一格子的获胜几率,也就是说,一个完整的五子棋的AI构想必须: 1、能够知道所有的获胜组合; 2、建立和使用获胜表; 3、设定获胜的分数; 4、使电脑具有攻击和防守的能力; 一、求五子棋的获胜组合 在一场五子棋的游戏中,计算机必须要知道有那些的获胜组合,因此我们必须求得获胜组合的总数。我们假定当前的棋盘为10*10。 (1)计算水平方向的获胜组合数,每一列的获胜组合是:6,共10列,所以水平方向的获胜组合数为:6*10=60 (2)计算垂直方向的获胜组合总数,每一行的获胜组合是:6,共10行,则垂直方向的获胜组合数为:6*10=60 (3)计算正对角线方向的获胜组合总数,正对角线上的获胜组合总数为6+(5+4+3+2+1)*2=36 (4)计算反对角线方向的获胜组合总数,反对角线上的获胜组合总数为6+(5+4+3+2+1)*2=36 ,这样所有的获胜组合数为:60+60+36+36=192 二、建立和使用获胜表 我们已经计算出了一个10*10的五子棋盘会有192种获胜方式,这样我们可以利用数组建立获胜表,获胜表的主要作用是:1,判断当前的获胜方式是否有效;2,判断当前的获胜方式中到底有多少子落入该获胜组合中。详细的使用您将在后面的程序中可以看出。 三,分数的设定 在游戏中为了让计算机能够决定下一步最佳的走法,必须先计算出计算机下到棋盘上任一空格的分数,而其中最高分数便是计算机下一步的最佳走法。 原理:我们判定当前讨论的空格与当前讨论的点有几种获胜的方式,有几种该空格就加几分。这种原理初听起来似乎是无法入手,没关系,当您了解我们后面的程序后您就会明白这种决策原理了。 这种决策有一些缺陷,因为如果只根据这个模型设计,就有可能出现电脑或玩家有三个子连成一线的时候,计算机却判断不出,它认为其他某些空格是当前的获胜的最佳位置而不去攻击或防守。没关系我们完全可以通过一个加强算法来改变当前的分值情况,也就是说当电脑或玩家有三个子或四个子连成一线时,我们通过加强算法将当前与三个子或四个子有关的空格的分值提高,从而可以弥补这一缺憾。 四、攻击与防守 以上的方式,事实上计算机只是计算出了最佳的攻击位置,为了防守我们还应计算当前玩家的最佳的攻击位置。这样有什么用呢?道理很简单,如果玩家最佳攻击位置的分数大于计算机最佳攻击位置上的分数,那么计算机就将下一步的棋子摆在玩家的最佳攻击位上以阻止玩家的进攻,否则计算机便将棋子下在自己的最佳攻击位置上进行攻击。 事实上,这个AI构想是很强大的如果你不是很厉害的五子棋高手的话,可能很快会被计算机打败。我在联众上可是中级棋手啊,跟这种构想打的时候胜率也不是很高。 使用vb.net编写五子棋 一、编写前的准备: 1、用计算机的思想描述整个下棋的过程 考虑步骤: (1)为了简便我们可以先让电脑先走第一步棋,电脑每走一步就会封掉许多玩家的获胜可能情况。 (2)当玩家走棋的时候我们首先应该考虑玩家走棋的合法性。 (3)如果合法,那么玩家也会封掉许多电脑的获胜的可能情况。 (4)电脑的思考路径:首先判断当前玩家和电脑的所有获胜组合是否需要进行加强赋值, 是进行加强赋值,否则进行普通的赋值。 (5)比较当前玩家和电脑谁的分值最大。将分值最大的点作为电脑的下一步走法。 2、利用vb.net窗体和图形工具建立五子棋的棋盘界面 (1)添加一个picturebox控件 作用:使用picturebox控件绘制棋子和棋盘 (2)添加一个label控件 作用:显示当前的获胜标志,也就是当某一方获胜或和棋时显示此标签。 (3)添加一个mainmenu控件 作用:控制游戏的开始或结束 (4)添加一个mediaplay组件 作用:使程序可以播放音乐。 3、设置整体框价 我们采取10*10的棋盘,为主要的平台。利用数组定义整个棋盘桌面,利用数组定义获胜组合以及获胜标志等。 二,声明全局数组和变量 定义虚拟桌面: Dim table(9, 9) As Integer 定义当前玩家桌面空格的分数: Dim pscore(9, 9) As Integer 定义当前电脑桌面空格的分数: Dim cscore(9, 9) As Integer 定义玩家的获胜组合: Dim pwin(9, 9, 191) As Boolean 定义电脑的获胜组合: Dim cwin(9, 9, 191) As Boolean 定义玩家的获胜组合标志: Dim pflag(191) As Boolean 定义电脑的获胜组合标志: Dim cflag(191) As Boolean 定义游戏有效标志: Dim theplayflag As Boolean 三、初始化游戏 '***************************************************************************** '** 模块名称: initplayenvironment '** '** 描述: 此函数主要功能如下: '** 1. 设置背景音乐。 '** 2. 设置游戏状态有效。 '** 3. 初始化游戏状态标签。 '** 4. 直接指定电脑的第一步走法。 '** 5. 初始化基本得分桌面。 '** 6. 电脑和玩家获胜标志初始化。 '** 7. 初始化所有获胜组合。 '** 8. 重新设定玩家的获胜标志。 '** '***************************************************************************** Sub initplayenvironment() player.FileName = ".\music\zhyu01.mid" player.Play() theplayflag = True '游戏有效 Label1.Visible = False '游戏状态标签不显示 PictureBox1.Refresh() '清空picturebox1的内容 yuandian(130, 130) '调用绘图函数绘制当前电脑先走的位置 Dim i, j, m, n As Integer For i = 0 To 9 For j = 0 To 9 table(i, j) = 0 Next Next '桌面初始化 For i = 0 To 191 pflag(i) = True cflag(i) = True Next '获胜标志初始化 table(4, 4) = 1 '由于我们设定电脑先手,并下了4,4位所以将其值设为1 ''' ******** 初始化获胜组合 ******** n = 0 For i = 0 To 9 For j = 0 To 5 For m = 0 To 4 pwin(j + m, i, n) = True cwin(j + m, i, n) = True Next n = n + 1 Next Next For i = 0 To 9 For j = 0 To 5 For m = 0 To 4 pwin(i, j + m, n) = True cwin(i, j + m, n) = True Next n = n + 1 Next Next For i = 0 To 5 For j = 0 To 5 For m = 0 To 4 pwin(j + m, i + m, n) = True cwin(j + m, i + m, n) = True Next n = n + 1 Next Next For i = 0 To 5 For j = 9 To 4 Step -1 For m = 0 To 4 pwin(j - m, i + m, n) = True cwin(j - m, i + m, n) = True Next n = n + 1 Next Next ''' ******** 初始化获胜组合结束 ******** For i = 0 To 191 If pwin(4, 4, i) = True Then pflag(i) = False End If Next '由于电脑已下了4,4位所以我们需要重新设定玩家的获胜标志 End Sub 四,处理鼠标事件 '***************************************************************************** '** 模块名称: themousedown '** '** 描述: 此函数主要实行以下功能: '** 1. 判定当前游戏标志是否有效。 '** 2. 将实际坐标转化成虚拟坐标。 '** 3. 绘制玩家的棋子。 '** 4. 执行检查获胜函数。 '** 5. 执行电脑算法函数。 '** '***************************************************************************** Sub themousedown(ByVal x As Integer, ByVal y As Integer) If theplayflag = False Then Exit Sub End If '检查游戏状态是否有效 Dim i, j As Integer Dim zhx, zhy As Integer zhx = Int((x - 10) / 30) zhy = Int((y - 10) / 30) For i = 0 To 9 For j = 0 To 9 If table(zhx, zhy) > 0 Then Exit Sub End If Next Next '检查当前鼠标点击的格子是否有效 Dim mycolor As Color Dim g As System.Drawing.Graphics g = PictureBox1.CreateGraphics mycolor = Color.White Dim brush1 As System.Drawing.Brush = New SolidBrush(mycolor) g.FillEllipse(brush1, zhx * 30 + 10, zhy * 30 + 10, 30, 30) '绘制玩家的棋子 table(zhx, zhy) = 2 For i = 0 To 191 If cwin(zhx, zhy, i) = True Then cflag(i) = False End If Next '重设电脑的获胜标志 checkwin() '检查当前玩家是否获胜 diannao() '调用电脑算法 End Sub 五、获胜检查算法。 '***************************************************************************** '** 模块名称: 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 六、电脑算法 '***************************************************************************** '** 模块名称: diannao '** '** 描述: 此程序主要执行以下功能: '** 1. 初始化赋值系统。 '** 2. 赋值加强算法。 '** 3. 计算电脑和玩家的最佳攻击位。 '** 4. 比较电脑和玩家的最佳攻击位并决定电脑的最佳策略。 '** 5. 执行检查获胜函数。 '** '***************************************************************************** Sub diannao() Dim i, j, k, m, n As Integer Dim dc As Integer Dim cab As Integer Dim pab As Integer For i = 0 To 9 For j = 0 To 9 pscore(i, j) = 0 cscore(i, j) = 0 Next Next '初始化赋值数组 ''' ******** 电脑加强算法 ******** For i = 0 To 191 If cflag(i) = True Then cab = 0 For j = 0 To 9 For k = 0 To 9 If table(j, k) = 1 Then If cwin(j, k, i) = True Then cab = cab + 1 End If End If Next Next Select Case cab Case 3 For m = 0 To 9 For n = 0 To 9 If table(m, n) = 0 Then If cwin(m, n, i) = True Then cscore(m, n) = cscore(m, n) + 5 End If End If Next Next Case 4 For m = 0 To 9 For n = 0 To 9 If table(m, n) = 0 Then If cwin(m, n, i) = True Then yuandian(m * 30 + 10, n * 30 + 10) table(m, n) = 1 For dc = 0 To 191 If pwin(m, n, dc) = True Then pflag(dc) = False checkwin() Exit Sub End If Next End If End If Next Next End Select End If Next For i = 0 To 191 If pflag(i) = True Then pab = 0 For j = 0 To 9 For k = 0 To 9 If table(j, k) = 2 Then If pwin(j, k, i) = True Then pab = pab + 1 End If End If Next Next Select Case pab Case 3 For m = 0 To 9 For n = 0 To 9 If table(m, n) = 0 Then If pwin(m, n, i) = True Then pscore(m, n) = pscore(m, n) + 30 End If End If Next Next Case 4 For m = 0 To 9 For n = 0 To 9 If table(m, n) = 0 Then If pwin(m, n, i) = True Then yuandian(m * 30 + 10, n * 30 + 10) table(m, n) = 1 For dc = 0 To 191 If pwin(m, n, dc) = True Then pflag(dc) = False checkwin() Exit Sub End If Next End If End If Next Next End Select End If Next ''' ******** 电脑加强算法结束 ******** ' ******** 赋值系统 ******** 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《问檤 外传》不错
呵呵 很久很久以前了 自己写过一个五子棋 不过我用的是j2ee 当时还在上学 是为了玩写的因为通过网页实现的 所以变量和你的有冲突 一个标示该谁下棋的 标志 下棋事件 传送一个坐标 给后台 后台响应之后更新棋子和标志位 并下达消息到另外一方 同事在另外一方棋盘上显示对方下棋的位置输赢是在每次点下的时候做判断的 主要的判断方法是根据当前坐标 八方向判断是否够五个子比较乱 希望能给你带来帮助
我再补充一点,这个论文的格式很重要,我给你说啊。这个自然段为什么要空两个字,为什么不空三个字和四个字呢?因为它是几千年来古人留下来的,它非常标准,非常完美!好吧,你写份1000字的心得,明天交给我!我是侯宗浩别挣扎了,你是成都东软软测的同学吧?我是侯宗浩,我出的题是没的答案的
这个要专业知识,我要查书才能做出来!没有分,因该不会有人帮忙吧!
希望对你有帮助************************************************************** C++语言五子棋源程序 ************************************************************* #include <graphics.h> #include <stdio.h> #include <stdlib.h> #include <dos.h> #define backcolor CYAN #define defaultcolor BLACK #define linecolor MAGENTA #define player1_color RED #define player2_color WHITE #define error_color RED #define winner_color RED const int left=40; const int top=390; const int d=30; const int line_num=9; const int turn=0; const int r=d/3; const int j=10; int x,y,k=1,step=(line_num+1)*(line_num+1); union REGS regs1,regs2; class player1; class player2; class qipan{ public: qipan(); ~qipan(){}; void init_qipan(); friend void fall(player1 &num1,player2 &num2,qipan &num); friend void input(player1 &num1,player2 &num2,qipan &num); private: int point[line_num+1][line_num+1]; }; class player1{ public: player1(); ~player1(){}; friend void fall(player1 &num1,player2 &num2,qipan &num); friend void input(player1 &num1,player2 &num2); friend int judge_winner(player1 &num1,player2 &num2); private: int point1[line_num+1][line_num+1]; }; class player2{ public: player2(); ~player2(){}; friend void fall(player1 &num1,player2 &num2,qipan &num); friend void input(player1 &num1,player2 &num2,qipan &num); friend int judge_winner(player1 &num1,player2 &num2); private: int point2[line_num+1][line_num+1]; }; void input(player1 &num1,player2 &num2); void fall(player1 &num1,player2 &num2,qipan &num); int judge_winner(qipan &num,player1 &num1,player2 &num2); void inputerror(); void display_winner(int); void main() { int driver=DETECT,mode; initgraph(&driver,&mode,"e:\tc30\bgi"); qipan num; player1 num1; player2 num2; while(step--) { input(num1,num2,num); fall(num1,num2,num); if(judge_winner(num1,num2)) { display_winner(k); } } // getchar(); } qipan::qipan(void) { int j,i; char ch[2]="0"; setbkcolor(backcolor); setcolor(linecolor); for(i=0;i<=line_num;i++) { line(left,top-i*d,left+line_num*d,top-i*d); } for(i=0;i<=line_num;i++) { line(left+i*d,top,left+i*d,top-line_num*d); } for(i=0;i<=line_num;i++) { if(*ch=='9'+1) *ch='a'; settextstyle(DEFAULT_FONT,HORIZ_DIR,1); outtextxy(left+i*d-2,top+r+3,ch); (*ch)=(*ch)+1; } *ch='0'; for(i=0;i<=line_num;i++) {if(*ch=='9'+1) *ch='a'; settextstyle(DEFAULT_FONT,HORIZ_DIR,1); outtextxy(left-r-10,top-d*i-3,ch); (*ch)=(*ch)+1; } setcolor(defaultcolor); for(i=0;i<=line_num;i++) { for(j=0;j<=line_num;j++) point[i][j]=0; } } void fall(player1 &num1,player2 &num2,qipan &num) { int flag=k%2; if(flag) { setcolor(player2_color); num2.point2[x][y]=1; num.point[x][y]=2; circle(left+d*x,top-d*y,r); setfillstyle(1,player2_color); floodfill(left+d*x,top-d*y,player2_color); } else { num1.point1[x][y]=1; num.point[x][y]=1; setcolor(player1_color); circle(left+d*x,top-d*y,r); setfillstyle(1,player1_color); floodfill(left+d*x,top-d*y,player1_color); } setcolor(defaultcolor); } void input(player1 &num1,player2 &num2,qipan &num) { char xx,yy; k++; while(1) { regs1.h.ah=0; xx=int86(22,®s1,®s1)-'0'; if(xx==('q'-'0')||xx==('Q'-'0')) { step=0; return; } regs1.h.ah=0; yy=int86(22,®s1,®s1)-'0'; if(yy==('q'-'0')||yy==('Q'-'0')) { step=0; return ; } if(xx<0||xx>line_num) { inputerror(); continue; } if(yy<0||yy>line_num) {inputerror(); continue; } if(num.point[xx][yy]==0) { break; } else { inputerror(); continue; } } x=(int)xx; y=(int)yy; setcolor(backcolor); settextstyle(DEFAULT_FONT,HORIZ_DIR,1); outtextxy(left+d*line_num/3,top+d*2,"Input error"); setcolor(defaultcolor); } player1::player1() { int i,j; for(i=0;i<=line_num;i++) { for(j=0;j<=line_num;j++) point1[i][j]=0; } } player2::player2() { int i,j; for(i=0;i<=line_num;i++) { for(j=0;j<=line_num;j++) point2[i][j]=0; } } void inputerror(void) { setcolor(error_color); settextstyle(DEFAULT_FONT,HORIZ_DIR,1); outtextxy(left+d*line_num/3,top+d*2,"Input error"); setcolor(defaultcolor); } int judge_winner(player1 &num1,player2 &num2) { int count=0,m=0,n=0,a=0,b=0,xx0,yy0; int flag=k%2; xx0=x; yy0=y; if(!flag) { //left <-------> right while(xx0>=1&&m<4) {xx0--;m++;} while(n<9&&xx0<=line_num) { if(num1.point1[xx0][y]==1) { count++; if(count==5) return 1; } else { count=0; } n++; xx0++; } //up <------> down count=0; xx0=x; m=0; n=0; while(yy0>=1&&m<4){yy0--;m++;} while(n<9&&yy0<=line_num) { if(num1.point1[x][yy0]==1) { count++; if(count==5) return 1; } else { count=0; } n++; yy0++; } //left up ----- right down xx0=x; yy0=y; m=0; n=0; count=0; while(xx0>=1&&m<4){ xx0--; a++; m++;} m=0; while(yy0<=line_num&&m<4){ yy0++; b++; m++;} if(a<=b) { xx0=x-a; yy0=y+a; } else { xx0=x-b; yy0=y+b; } while(xx0<=line_num&&yy0>=0&&n<9) { if(num1.point1[xx0][yy0]==1) { count++; if(count==5) return 1; } else { count=0; } xx0++; yy0--; n++; } //right up <-----> left down count=0; a=0; b=0; n=0; m=0; xx0=x; yy0=y; while(xx0<line_num&&m<4){ xx0++; m++; a++;} m=0; while(yy0<line_num&&m<4){ yy0--; m++; b++; } if(a<=b) { xx0=x+a; yy0=y+a; } else { xx0=x+b; yy0=y+b; } while(xx0>=0&&yy0>=0&&n<9) { if(num1.point1[xx0][yy0]==1) { count++; if(count==5) return 1; } else count=0; xx0--; yy0--; n++; } //no winer return 0; } else { //left <-------> right while(xx0>=1&&m<4) {xx0--;m++;} while(n<9&&xx0<=line_num) { if(num1.point1[xx0][y]==1) { count++; if(count==5) return 1; } else { count=0; } n++; xx0++; } //up <------> down count=0; xx0=x; m=0; n=0; while(yy0>=1&&m<4){yy0--;m++;} while(n<9&&yy0<=line_num) { if(num2.point2[x][yy0]==1) { count++; if(count==5) return 1; } else { count=0; } n++; yy0++; } //left up ----- right down xx0=x; yy0=y; m=0; n=0; count=0; while(xx0>=1&&m<4){ xx0--; a++; m++;} m=0; while(yy0<=line_num&&m<4){ yy0++; b++; m++;} if(a<=b) { xx0=x-a; yy0=y+a; } else { xx0=x-b; yy0=y+b; } while(xx0<=line_num&&yy0>=0&&n<9) { if(num2.point2[xx0][yy0]==1) { count++; if(count==5) return 1; } else { count=0; } xx0++; yy0--; n++; } //right up <-----> left down count=0; a=0; b=0; n=0; m=0; xx0=x; yy0=y; while(xx0<line_num&&m<4){ xx0++; m++; a++;} m=0; while(yy0<line_num&&m<4){ yy0--; m++; b++; } if(a<=b) { xx0=x+a; yy0=y+a; } else { xx0=x+b; yy0=y+b; } while(xx0>=0&&yy0>=0&&n<9) { if(num2.point2[xx0][yy0]==1) { count++; if(count==5) return 1; } else count=0; xx0--; yy0--; n++; } //no winer return 0; } } void display_winner(int k) { int flag=k%2; if(!flag) { setcolor(winner_color); settextstyle(DEFAULT_FONT,HORIZ_DIR,2); outtextxy(left+d*2,top+40,"Red is winner"); setcolor(defaultcolor); step=0; getchar(); } else { setcolor(winner_color); settextstyle(DEFAULT_FONT,HORIZ_DIR,2); outtextxy(left+2*d,top+40,"White is winner"); setcolor(defaultcolor); step=0; } }本回答被网友采纳
文献综述就是用资料,只不多有一个比较固定的格式。
主要是,关于你的论文主题,国内外学者提出多点看法和主张。某某学者在某某文章中,就你的论文主题,提出看法认为如何如何
都是这样的语句,写出来就ok了。需要大概七八篇文章的论述,最好是高级的人物写的文章,发表在高级期刊上的。
知网搜索文章,搜出来的文章,看看摘要就能写进综述里了,不用下载,中国知网,搜索
合适采纳啊
不懂可以追问
给你一个
供参考
可行性就是你的论文设计能研究出来,要人有人,要资料有资料,要时间有时间之类的
我给你一个c++五子棋的程序mian.cpp#include <cstdio>#include <string>#include <cstdlib>#include <ctime>#include <Windows.h>#include "pl.h"using namespace std;pl game;pl game2;void srandput(int &x,int &y) { srand(time(NULL)); do { x = rand() % 20; y = rand() % 20; } while (!game.isok(x,y));}void scanfput(int &x,int &y) { do { scanf("%d %d",&x,&y); } while (!game.isok(x,y));}int main() { int x,y; char who = com; x = y = -1; do { if (who == com) who = me; else who = com; if (who == me) { game.getxy(x,y); printf("Com put chess in (%d,%d)\n",x,y); game.printmap(); if (game.isend(x,y,com)) { who = com; break; } game.sendxy(x,y); printf("I put chess in (%d,%d)\n",x,y); game.printmap(); if (game.isend(x,y,me)) break; //system("pause"); } else { //srandput(x,y); scanfput(x,y); //game2.getxy(x,y); //game2.sendxy(x,y); } } while (true); if (who == me) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),dwMe); puts("You Win, Computer Lose."); } else { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),dwCom); puts("Computer Win, You Lose."); } printf("Use %d Steps\n",game.getstep()); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),dwWhite);} pi.hconst DWORD dwWhite = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN;const DWORD dwMe = FOREGROUND_GREEN;const DWORD dwCom = FOREGROUND_RED;//■□○●char rec1[] = {-95,-10,0};char rec2[] = {-95,-11,0};char cir1[] = {-95,-16,0};char cir2[] = {-95,-15,0};////////////////////////////////////////////////////////////////////////////class pl//////////////////////////////////////////////////////////////////////////const int NMAX = 20;const int MAX = 1200;const char blank = '0';const char me = '1';const char com = '2';class pl {public: void sendxy(int &,int &); void getxy(int,int); void initscore(); void refreshscore(char,int,int); void calscore(char); void solve(int &,int &); void printmap(); bool isok(int,int); bool isend(int,int,char); int getstep(); pl();private: int usestep; int wincount; char chess[NMAX][NMAX]; int win[2][MAX]; //ps,pt -> me //cs,ct -> com int ps[NMAX][NMAX], cs[NMAX][NMAX]; bool pt[NMAX][NMAX][MAX], ct[NMAX][NMAX][MAX];};pl::pl() { memset(chess,blank,sizeof(chess)); memset(pt,false,sizeof(pt)); memset(ct,false,sizeof(ct)); memset(win,0,sizeof(win)); wincount = 0; usestep = 0; initscore();}void pl::printmap() { int i,j; for (i=0;i<NMAX;i++) { printf("\t\t\t%d\t",i); for (j=0;j<NMAX;j++) { if (chess[i][j] == me) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),dwMe); printf("%s",cir2); } else if (chess[i][j] == com) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),dwCom); printf("%s",cir2); } else printf("%s",rec2); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),dwWhite); } putchar('\n'); } printf("\n\t\t\t\t"); for (i=0;i<NMAX;i++) printf("%2d",i); putchar('\n');}void pl::getxy(int x,int y) { if (x==-1 && y==-1) return; refreshscore(com,x,y);}bool pl::isok(int x,int y) { return (chess[x][y] == blank);}bool pl::isend(int x,int y,char who) { int i,j; int l,r,u,d,c1,c2,c3,c4; if (x==-1 && y==-1) return false; l = r = u = d = 0; c1 = c2 = c3 = c4 = 0; for (i=1;i<5 && x+i < NMAX;i++) { if (who == chess[x+i][y]) u ++; else break; } for (i=1;i<5 && x-i >= 0;i++) { if (who == chess[x-i][y]) d ++; else break; } for (i=1;i<5 && y+i < NMAX;i++) { if (who == chess[x][y+i]) r ++; else break; } for (i=1;i<5 && y-i >= 0;i++) { if (who == chess[x][y-i]) l ++; else break; } for (i=1;i<5 && x+i < NMAX && y+i < NMAX;i++) { if (who == chess[x+i][y+i]) c1 ++; else break; } for (i=1;i<5 && x+i < NMAX && y-i >= 0;i++) { if (who == chess[x+i][y-i]) c2 ++; else break; } for (i=1;i<5 && x-i >= 0 && y-i >= 0;i++) { if (who == chess[x-i][y-i]) c3 ++; else break; } for (i=1;i<5 && x-i >= 0 && y+i < NMAX;i++) { if (who == chess[x-i][y+i]) c4 ++; else break; } return ( (u+1+d)>=5 || (l+1+r)>=5 || (c1+1+c3)>=5 || (c2+1+c4)>=5 );}void pl::sendxy(int &x, int &y) { solve(x,y); usestep ++;}//枚举赢的局面void pl::initscore() { int i,j,k; //竖 for (i=0;i<NMAX;i++) { for (j=0;j<NMAX-4;j++) { for (k=0;k<5;k++) pt[j+k][i][wincount] = ct[j+k][i][wincount] = true; wincount ++; } } //横 for (i=0;i<NMAX;i++) { for (j=0;j<NMAX-4;j++) { for (k=0;k<5;k++) pt[i][j+k][wincount] = ct[i][j+k][wincount] = true; wincount ++; } } //斜1 for (i=0;i<NMAX-4;i++) { for (j=0;j<NMAX-4;j++) { for (k=0;k<5;k++) pt[j+k][i+k][wincount] = ct[j+k][i+k][wincount] = true; wincount ++; } } //斜2 for (i=0;i<NMAX-4;i++) { for (j=NMAX-1;j>=4;j--) { for (k=0;k<5;k++) pt[j-k][i+k][wincount] = ct[j-k][i+k][wincount] = true; wincount ++; } }}//计算全局位置的分值void pl::calscore(char who) { bool (*table)[NMAX][MAX]; int (*score)[NMAX]; int iwho; if (who == me) { table = pt; score = ps; iwho = 1; } else { table = ct; score = cs; iwho = 0; } srand(time(NULL)); int i,j,k; for (i=0;i<NMAX;i++) { for (j=0;j<NMAX;j++) { score[i][j] = 0; if (chess[i][j] == blank) { for (k=0;k<wincount;k++) { if (!table[i][j][k]) continue; //分值的大小影响棋子位置的选择 srand(rand()); switch (win[iwho][k]) { case 1: score[i][j] += 1; break; case 2: score[i][j] += 10; break; case 3: score[i][j] += 100; break; case 4: score[i][j] += 1000; } } } } }}void pl::solve(int &x, int &y) { calscore(me); calscore(com); int i,j; int me_score,com_score; int me_x,me_y,com_x,com_y; me_score = com_score = -1; //选取我方或对方得分最大值 for (i=0;i<NMAX;i++) { for (j=0;j<NMAX;j++) { if (chess[i][j] == blank) { if (me_score < ps[i][j]) { me_score = ps[i][j]; me_x = i; me_y = j; } if (com_score < cs[i][j]) { com_score = cs[i][j]; com_x = i; com_y = j; } } } } if (me_score > com_score) { x = me_x; y = me_y; } else { x = com_x; y = com_y; } refreshscore(me,x,y);}//更新分数void pl::refreshscore(char who,int x,int y) { bool (*table)[NMAX][MAX]; bool (*antitable)[NMAX][MAX]; int iwho; if (who == me) { table = pt; antitable = ct; iwho = 1; } else { table = ct; antitable = pt; iwho = 0; } chess[x][y] = who; for (int i=0;i<wincount;i++) { //一方位置能胜利次数 if (table[x][y][i] && win[iwho][i] < INT_MAX) win[iwho][i] ++; if (antitable[x][y][i]) { //另一方无法放置 antitable[x][y][i] = false; win[1-iwho][i] = INT_MAX; } }}int pl::getstep() { return usestep;}本回答由网友推荐
组合 玩家 电脑 五子 函数 用户 落子