本科毕业设计网络五子棋.docx
- 文档编号:5364805
- 上传时间:2022-12-15
- 格式:DOCX
- 页数:36
- 大小:765.91KB
本科毕业设计网络五子棋.docx
《本科毕业设计网络五子棋.docx》由会员分享,可在线阅读,更多相关《本科毕业设计网络五子棋.docx(36页珍藏版)》请在冰豆网上搜索。
本科毕业设计网络五子棋
Abstract
Withtherapiddevelopmentofrecentcomputer,avarietyofboardgamesareoneafteranothersignofthecomputer,sothosewholovechess,theyoftensufferfromrivalchessfanwhohasnotbeenenoughtokeepchessaddiction.Andhighlevelsofallsuchsoftware,agreatrivalandthetendencyofthehumanbrain.Whichhaddefeatedworldchampionchess-GarryKasparov's"DeepBlue"isthemostconvincingrepresentatives;otherliketheGo"lighthand"chess"tofamily"andalsoforitsexcellentdeepartificialintelligencebychessfanfavorite;andwewilltellyouisthatbackgammonalgorithm.
Inordertomakethereaderhaveabackgammonsearchcomplexityimageunderstanding,tociteaChinesechesswithbackgammoncomparisonsearches.CanseethatcomparedwithChinesechess,backgammoncoefficientofmulti-branch,andtheoutcomeofconditionalalsocomplicated.Significantfactorinthebranch,thesearchproceduretoincreasethemaximumsearchdepthof1level,costofcomputationtimewillincreasesignificantly.Therefore,todesignanefficientsearchalgorithmisveryimportant.
Keywords:
backgammon,HumanVersus,Algorithm.
前言
五子棋是起源于中国古代的传统黑白棋种之一。
现代五子棋日文称之为“連珠”,英译为“Renju”,英文称之为“Gobang”或“FIR”(FiveinaRow的缩写),亦有“连五子”、“五子连”、“串珠”、“五目”、“五目碰”、“五格”等多种称谓。
五子棋不仅能增强思维能力,提高智力,而且富含哲理,有助于修身养性。
五子棋既有现代休闲的明显特征“短、平、快”,又有古典哲学的高深学问“阴阳易理”;它既有简单易学的特性,为人民群众所喜闻乐见,又有深奥的技巧和高水平的国际性比赛;它的棋文化源渊流长,具有东方的神秘和西方的直观;既有“场”的概念,亦有“点”的连接。
它是中西文化的交流点,是古今哲理的结晶。
1.系统概述
1.1 开发背景
当前网络上流传的五子棋游戏功能并不尽善尽美,其中最主要的问题就是人机对战和网络对战不能够一起实现,所以我决定开发[1]一个既能够人机对战,又能够进行网络对战的五子棋系统。
1.2研究意义
近来随着计算机的快速发展,各种各样的游戏层出不穷,使得人们能有更多的娱乐项目,而棋类游戏能起到锻炼人的思维和修身养性的作用,而且棋类游戏水平颇高,大有与人脑分庭抗礼之势。
现在的五子棋游戏软件基本上可以分为两类:
一类是网络五子棋游戏软件,另一类是单机版五子棋游戏软件。
为了满足五子棋玩家人群的需求,作者设计了这款电脑版的五子棋游戏软件,可以供人们闲暇时间随时随地地进行娱乐提高自己的五子棋水平,实用性强。
1.3需求分析
多五子棋主要功能如下:
(1)选择不同模式的游戏
本游戏提供单机模式和网络模式。
(2)单机模式下的人机对战
人与电脑玩。
(3)单机模式下的双人对战
人与人之间使用同一台电脑下棋。
(4)网络对战
可以联机对战且可以聊天。
(5)声音设置
自己播放背景音乐
1.4可行性分析
1.4.1技术可行性
为实现本软件的程序设计,开发该软件采用MicrosoftWindowsXP作为操作平台实现与软件用户的交互工作,同时使用主流的C#面向对象的编程语言和MicrosoftVisualStudio2005开发工具开发该软件,在技术上是可行的。
1.4.2操作可行性
现今社会,电脑的普及应用已为广大用户所接受,而C#是面向对象的主流编程语言,MicrosoftVisualStudio2005开发环境,是目前最流行的Windows平台应用程序开发环境,而且开发的系统界面简单易操作,初学者几乎不用经过培训就能操作,因此该系统是具有操作可行性。
2.总体设计
2.1系统的总体功能模块
本设计由单机模式、网络模式两大功能模块构成:
(1)单机模块
在同一台电脑上玩五子棋
(2)网络模块
不在同一台电脑上进行对弈。
五子棋游戏
图2-1系统的总体功能图
2.2系统调用图
图2-2系统调用图
3.具体系统实现功能介绍
图3系统实现功能图
3.1人机对战模块
图3-1人机对战运行时的图
人机对战主要代码如下:
privatevoidForm1_MouseDown(objectsender,System.Windows.Forms.MouseEventArgse)//实现鼠标操作的函数
{
//游戏运行核心,分别完成人机对战
//完成下棋点的确定,界面信息的更新,发送网络对战信息
if((!
win0)&&(!
win1)&&(!
nowin))
{
//当未有一方取胜时
if(!
over)
//尚未结束
if(!
wplayers)
{
//不是网络对战状态
if(player1)
{
//该白棋走
if(x<600&&y<600)
{
//取下棋点
m=(int)Math.Floor((double)x/40);
n=(int)Math.Floor((double)y/40);
if(shifouxiazi[m,n]==2)
{
this.textBox1.Text=textBox1.Text+"白棋:
"+"X"+m+"Y"+n+"\t";
if(label12.Text=="白棋")
{
huihe++;
label9.Text=""+huihe;
}
else
if(label12.Text=="待定")
{
label12.Text="白棋";
huihe++;
label9.Text=""+huihe;
}
//回合数调整,先手显示
shifouxiazi[m,n]=0;
//表示该位已存白子
player1sum++;
//白子总数加1
if(((player2sum==112)&&(player1sum==113))||((player2sum==113)&&(player1sum==112)))
{
//如果出现平局
nowin=true;
over=true;
}
for(i=0;i<572;i++)
{
//对每种获胜情况的ifwin[0,i]进行计算,可能满足的情况ifwin[0,i]++
//不能满足的情况ifwin[0,i]置7(表无效)
if(tableplayer1[m,n,i]&&ifwin[0,i]!
=7)
ifwin[0,i]++;
if(tableplayer2[m,n,i])
{
tableplayer2[m,n,i]=false;
ifwin[1,i]=7;
}
}
player1=false;
player2=true;
//交换下棋方
}
}
}
3.2双人对战模块
图3-2双人对战运行时图
单机模式中双人对战模块,两个玩家同时用同一部电脑和鼠标对弈,代码如下:
if(nplayers)
{
//双人对战模式下
if(player2)
if(x<600&&y<600)
{
//黑棋走
m=(int)Math.Floor((double)x/40);
n=(int)Math.Floor((double)y/40);
//取下棋点
if(shifouxiazi[m,n]==2)
{
this.textBox1.Text=textBox1.Text+"黑棋:
"+"X"+m+"Y"+n+"\t";
//加入历史记录
if(label12.Text=="黑棋")
{
huihe++;
label9.Text=""+huihe;
}
else
if(label12.Text=="待定")
{
label12.Text="黑棋";
huihe++;
label9.Text=""+huihe;
}
//回合数调整,先手显示
shifouxiazi[m,n]=1;
//表示该位已存黑子
player2sum++;
//黑子总数加1
if(((player2sum==112)&&(player1sum==113))||((player2sum==113)&&(player1sum==112)))
{
nowin=true;
over=true;
}
for(i=0;i<572;i++)
{
//对每种获胜情况的ifwin[0,i]进行计算,可能满足的情况ifwin[0,i]++
//不能满足的情况ifwin[0,i]置7(表无效)
if(tableplayer2[m,n,i]&&ifwin[1,i]!
=7)
ifwin[1,i]++;
if(tableplayer1[m,n,i])
{
tableplayer1[m,n,i]=false;
ifwin[0,i]=7;
}
}
player1=true;
player2=false;
//交换下棋权利
}
}
}
}
3.3Playingtable模块
图3-3Playingtable运行时图
Playingtable模块属于网络对战模式,显示用户进入房间后看到的界面,并根据收发的信息作对应处理还有聊天的功能,代码如下:
//设置Label控件的文本信息
///
privatevoidSetLabel(Labellabel,stringstr)
{
if(label.InvokeRequired==true)
{
this.Invoke(labelDelegate,label,str);
}
else
{
label.Text=str;
}
}
///
///设置应该谁落子的提示信息
///
publicvoidSetLabelGo(stringstr,intdownIndex)
{
SetLabel(labelGo,str);
this.downIndex=downIndex;
}
///
///设置开始游戏标志
///
publicvoidStart(boolisStart)
{
isPlaying=isStart;
}
publicvoidAskTie(stringstr)
{
if(str!
=side.ToString())
{
stringreply="False";
stringsideString=str=="0"?
"黑方":
"白方";
if(MessageBox.Show(sideString+"请求和棋,同意吗?
","",
MessageBoxButtons.YesNo,MessageBoxIcon.Question)==DialogResult.Yes)
{
reply="True";
}
SendToServer(string.Format("Reply,{0},{1},{2}",
tableIndex,side,reply));
}
}
publicvoidReplyTie(stringaskSide,stringstr)
{
if(str=="True")
{
Restart("");
}
else
{
if(askSide!
=side.ToString())
{
stringsideString=askSide=="0"?
"黑方":
"白方";
MessageBox.Show(sideString+"不同意和棋!
");
}
}
}
privatevoidSetButton(Buttonbutton,boolflag)
{
if(button.InvokeRequired==true)
{
this.Invoke(buttonDelegate,button,flag);
}
else
{
button.Enabled=flag;
if(flag==true)
{
button.ForeColor=Color.Black;
}
}
}
publicvoidSetPictureBoxImage(PictureBoxpictureBox,Imageimage)
{
if(pictureBox.InvokeRequired==true)
{
this.Invoke(setPictureBoxDelegate,pictureBox,image);
}
else
{
pictureBox.Image=image;
}
}
///
///向棋盘上放置棋子
///
publicvoidSetChess(inti,intj,intChessColor)
{
//--------此句仅用于观察接收的信息,需要观察时可以去掉注释-------------//
AddToRichTextBox(string.Format("{0}:
{1},{2}",ChessColor,j,i));
//---------------------------------------------------------------------//
grid[i,j]=ChessColor;
pictureBoxBoard.Invalidate();
}
publicvoidRestart(stringstr)
{
if(str!
="")
{
MessageBox.Show(str,"",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
ResetGrid();
if(side!
=2)
{
SetButton(buttonStart,true);
}
}
privatevoidResetGrid()
{
for(inti=0;i<=grid.GetUpperBound(0);i++)
{
for(intj=0;j<=grid.GetUpperBound
(1);j++)
{
grid[i,j]=ChessColor.None;
}
}
pictureBoxBoard.Invalidate();
}
///
///初始化棋盘上各棋子的位置
///
///
publicvoidInitializeGrid(stringstr)
{
string[]splitString=str.Split('/');
intk=0;
for(inti=0;i<=grid.GetUpperBound(0);i++)
{
for(intj=0;j<=grid.GetUpperBound
(1);j++)
{
grid[i,j]=int.Parse(splitString[k]);
k++;
}
}
pictureBoxBoard.Invalidate();
}
///
///Paint事件
///
privatevoidpictureBoxBoard_Paint(objectsender,PaintEventArgse)
{
Graphicsg=e.Graphics;
for(inti=0;i<=grid.GetUpperBound(0);i++)
{
for(intj=0;j<=grid.GetUpperBound
(1);j++)
{
if(grid[i,j]!
=ChessColor.None)
{
if(grid[i,j]==ChessColor.Black)
{
g.DrawImage(blackBitmap,(i+1)*20,(j+1)*20);
}
else
{
g.DrawImage(whiteBitmap,(i+1)*20,(j+1)*20);
}
}
}
}
}
///
///单击发送按钮触发的事件
///
privatevoidbuttonSend_Click(objectsender,EventArgse)
{
//字符串格式:
Talk,桌号,对话内容
SendToServer(string.Format("Talk,{0},{1}",tableIndex,textBox1.Text));
textBox1.Clear();
}
///
///对话内容改变时触发的事件
///
privatevoidtextBox1_KeyPress(objectsender,KeyPressEventArgse)
{
if(e.KeyChar==(char)Keys.Enter)
{
//字符串格式:
Talk,桌号,对话内容
SendToServer(string.Format("Talk,{0},{1}",tableIndex,textBox1.Text));
textBox1.Clear();
}
}
///
///单击开始按钮触发的事件
///
privatevoidbuttonStart_Click(objectsender,EventArgse)
{
SendToServer(string.Format("Start,{0},{1}",tableIndex,side));
buttonStart.ForeColor=SystemColors.GrayText;
buttonStart.Enabled=false;
}
///
///单击求和按钮触发的事件
///
privatevoidbuttonAskTie_Click(objectsender,EventArgse)
{
SendToServer(string.Format("AskTie,{0},{1}",tableIndex,side));
}
///
///在棋盘上按下鼠标左键时触发的事件
///
privatevoidpictureBoxBoard_MouseDown(objectsender,MouseEventArgse)
{
if(isPlaying==true)
{
intx=e.X/20-1;
inty=e.Y/20-1;
if(!
(x<0||x>14||y<0||y>14))
{
if(grid[x,y]==ChessColor.None&&downIndex==side)
{
//发送格式:
UnsetDot,桌号,座位号,行,列,颜色
SendToServer(string.Format(
"SetChess,{0},{1},{2},{3},{4}",tableIndex,side,x,y,side));
if(radioButtonSound.Checked==true)
{
chessSound.Play();
}
}
}
}
}
///
///设置用户进入房间看到的信息
///
///
///
黑方名/白方名/旁观名)
publicvoidS
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 本科 毕业设计 网络 五子棋
![提示](https://static.bdocx.com/images/bang_tan.gif)