五子棋Java实验报告.docx

上传人:b****6 文档编号:6334717 上传时间:2023-01-05 格式:DOCX 页数:13 大小:141.58KB
下载 相关 举报
五子棋Java实验报告.docx_第1页
第1页 / 共13页
五子棋Java实验报告.docx_第2页
第2页 / 共13页
五子棋Java实验报告.docx_第3页
第3页 / 共13页
五子棋Java实验报告.docx_第4页
第4页 / 共13页
五子棋Java实验报告.docx_第5页
第5页 / 共13页
点击查看更多>>
下载资源
资源描述

五子棋Java实验报告.docx

《五子棋Java实验报告.docx》由会员分享,可在线阅读,更多相关《五子棋Java实验报告.docx(13页珍藏版)》请在冰豆网上搜索。

五子棋Java实验报告.docx

五子棋Java实验报告

五子棋Java实验报告

五子棋JAVA实验报告

一、实验目的和要求

1、能够用编程语言实现一个简单的五子棋程序

2、在实际系统中使用、实现人工智能的相关算法

3、进一步加深对人工智能算法的理解

二、五子棋的基本常识与原理

1、五子棋的起源

五子棋,是一种两人对弈的纯策略型棋类游戏,亦称“串珠”、“连五子”;是中国民间非常熟知的一个古老棋种。

相传,它起源于四千多年前的尧帝时期,比围棋的历史还要悠久。

亦有传说,五子棋最初流行于少数民族地区,以后渐渐演变成围棋并在炎黄子孙后代中遍及开来。

五子棋发展于日本,流行于欧美。

容易上手,老少皆宜,而且趣味横生,引人入胜;不仅能增强思维能力,提高智力,而且富含哲理,有助于修身养性。

传统五子棋的棋具与围棋相同,棋子分为黑白两色,棋盘为19X19,棋子放置于棋盘线交叉点上。

两人对局,各执一色,轮流下一子,先将横、竖或斜线的5个或5个以上同色棋子连成不间断的一排者为胜。

因为传统五子棋在落子后不能移动或拿掉,所以也可以用纸和笔来进行游戏。

2、五子棋的基本常识

与任何一种竞技棋一样,五子棋的每一局棋也分为三个阶段:

开局,中局和残局。

五子棋的开始阶段称为开局,或称布局。

其开局阶段是十分短暂的,大约在七着与十几着之间。

在这一阶段的争夺中,双方的布局,应对将对以后的胜负起着极为关键的作用。

在开局阶段取得的形势好坏,主动与被动,先手与后手的优劣程度,往往直接影响中局的战斗。

因此积极处理好开局和开局向中局的过渡十分重要。

五子棋是从一至五,逐渐布子,发展连系,同时运用限制和反限制的智慧,在连子的过程中为自己的棋子争得相对的主动权和优势,逐步扩展优势,或者从劣势转化为优势,击溃对方的防线,最后连五取胜或抓禁手取胜或迫使对方投子认负。

3、五子棋比赛的相关规定

(1)职业连珠规则

a.黑方先下子,白后下,从天元开始相互顺序落子。

b.最先在棋盘横向、竖向、斜向形成连续的相同色五个棋子的一方为胜。

c.黑棋禁手判负,白棋无禁手。

黑棋禁手包括“三三”(包括“四三三”)、“四四”(包括“四四三”)、“长连”。

即黑棋只能以“四三”取胜。

有关术语解释请见图示说明。

d.如分不出胜负,则定为平局。

对局中拔子、中途退场均判为负。

e.五连与禁手同时形成,判胜。

(2)比赛中的规定和特例

a.对局开始前,双方猜子,大数减小数,单数交换,偶数不换。

b.白棋第一手(即盘面第二着棋)应在天元为界自己一侧布子,主要以示尊重对方,之后rateislow,youshouldreplacethedrillingequipmentorimprovedrillingmethods.(3)inthecourseofdrilling,drillingwatercoresampling,boreholepressure,lengthandotherfactorsthatcanfullyreflectthecharacteristicsoftherockorconcretearemonitoredandrecordedandsubmittedtothesupervisor.(4)wewillaccordingtoinstructions,totestdrillcoreandconcrete-core,andtestrecordsandresultssubmittedtothesupervisor.(5)weshalleachboxortwocolorphotoforeachcoresample,andmadedetailedrecordsofthedrillingoperation,shouldbesubmittedtothesupervisor.(6)thesupervisorindicatingcorethatshouldbesaved,storedatthespecifiedlocationtopreventlossandmixed.11.3.4drillingprotectionconstructiondrawingsshowninalldrillholesshouldbeproperlyprotecteduntilacceptancesofar.11.4waterboreholeflushingandpressuretesting11.4.1Generalrequirements

(1)priortotheGrouting,allgrouthole(above)fissurecleaningandwaterpressuretest.

(2)faults,fracturesandotherareaswithcomplexgeologicalconditions,itscrackwashingthegrouthole,shouldbedirectedbythesupervisororbyfieldtestmethod.11.4.2flushing

(1)holeshouldbeflush.WeshallbeusingFengShuiasdirectedbysupervisorjointflushorcathetersintothetraffic

双方可任意行子。

c.对局中双方应遵守“职业连珠五子棋规则”,如出现争议,应由裁判判定。

d.对局中掉子(棋子掉落在棋盘上)的一方判负。

如遇推子或蹭子,以盘面第一落点为准。

用手将棋子扶正不算违规。

e.对局中应礼貌行棋,防止不正常声音、动作影响对方思考。

f..比赛结束后,双方应将各自棋子放回原处。

g.对局中如黑方出现禁手,白方应立即指出禁手点,黑方即负。

如白方在黑方出现禁手后,又下一步白子,黑棋禁手则不成立了。

h.比赛对局时间,双方分别为15分钟、1小时、2小时、5小时四个等级标准,超时判负。

(3)特殊规定

职业五子棋虽然对黑棋采取了种种限制,但黑子先行的优势依然很大。

因此,在高段位的职业比赛中,又出现了三种特殊的规定。

a.指定打法:

是指比赛双方按照约定好的开局进行对弈,由白棋先行。

b.三手可交换:

是指黑棋下盘面第3手棋后,白方在下第四手之前,如感觉黑方棋形不利于己方,可提出交换,即执白棋一方变为执黑棋一方,而黑方不可以不换。

c.五手两打法:

是指黑棋在下盘面上关键的第5手棋时,必须下两步棋,让白棋在这两步棋中拿掉一粒棋子,然后再继续对弈。

一般说来,白棋肯定拿掉对白方不利的一点,而保留对黑方较为不利的那点让黑方行棋。

三、五子棋的系统设计

1、系统用例模型设计

五子棋系统应该具有选择玩家先落子还是电脑先落子的功能,应该具有开始游戏和重新开始的功能,当然了,必须具有在玩家指定位置落子的功能。

以上描述,用用例图在图1中做进一步描述。

这部分功能,主要通过界面与系统的交互来实现。

落子

选择玩家先落子开始游戏

玩家

选择电脑先落子重新开始

图1五子棋系统的玩家用例图

各个用例,简单描述如下:

rateislow,youshouldreplacethedrillingequipmentorimprovedrillingmethods.(3)inthecourseofdrilling,drillingwatercoresampling,boreholepressure,lengthandotherfactorsthatcanfullyreflectthecharacteristicsoftherockorconcretearemonitoredandrecordedandsubmittedtothesupervisor.(4)wewillaccordingtoinstructions,totestdrillcoreandconcrete-core,andtestrecordsandresultssubmittedtothesupervisor.(5)weshalleachboxortwocolorphotoforeachcoresample,andmadedetailedrecordsofthedrillingoperation,shouldbesubmittedtothesupervisor.(6)thesupervisorindicatingcorethatshouldbesaved,storedatthespecifiedlocationtopreventlossandmixed.11.3.4drillingprotectionconstructiondrawingsshowninalldrillholesshouldbeproperlyprotecteduntilacceptancesofar.11.4waterboreholeflushingandpressuretesting11.4.1Generalrequirements

(1)priortotheGrouting,allgrouthole(above)fissurecleaningandwaterpressuretest.

(2)faults,fracturesandotherareaswithcomplexgeologicalconditions,itscrackwashingthegrouthole,shouldbedirectedbythesupervisororbyfieldtestmethod.11.4.2flushing

(1)holeshouldbeflush.WeshallbeusingFengShuiasdirectedbysupervisorjointflushorcathetersintothetraffic

选择电脑先落子:

选择后,在游戏过程中,由电脑执黑子,先落子;玩家执白子,

于电脑后落子;

选择玩家先落子:

选择后,在游戏过程中,由玩家执黑子,先落子;电脑执白子,

于玩家后落子;

落子:

原则上说,只要不违反禁手规则,在玩家鼠标点击最近的落子点落子,但是

在本系统中,简单起见,没有考虑禁手规则;

开始游戏:

选择后,根据设定的电脑还是玩家先落子,开始游戏;,重新开始:

在游戏途中,可以选择重新开始,中断游戏并重新开始游戏。

同时,五子棋系统本身应该具有棋盘绘制、棋势扫描、棋势排序、棋势评估、择位落子,

以及胜负判定的功能,尤其是对于棋势排序、棋势评估和择位落子,这里是体现五子棋系统

人工智能(AI)的关键之处。

以上描述,用用例图在图2中进一步描述。

棋势排序

棋势扫描棋势评估

五子棋系统

棋盘绘制择位落子

胜负判定

图2五子棋系统的系统用例图

各个用例,简单描述如下:

棋盘绘制:

绘制19*19的棋盘及相关按钮和选项,并负责电脑、玩家落子后棋子的

具体绘制;

棋势扫描:

扫描目前棋盘上的所有八个方向上的落子情况,获取整个对弈双方的棋

势;

棋势排序:

对获取的八个方向的棋势(实际上下合一,左右合一,左下右上合一,

坐上右下合一,为四个方向),进行排序,便于进行棋势评估;,棋势评估:

分别对电脑和玩家的棋势进行评估,量化棋势;

择位落子:

比较电脑和玩家的棋势,若有利于玩家,则采取“守、堵”的策略,若

有利于电脑,则采取“攻、走”的策略;

胜负判定:

每次电脑或是玩家落子后,判断胜负情况,若出现“五子连珠”,则“连

珠”一方取胜,另一方失败,游戏结束。

2、系统界面设计

为了实现玩家的用例所需要的功能,同时又便于使用,五子棋系统的界面设计得比较简

单,如图3所示。

rateislow,youshouldreplacethedrillingequipmentorimprovedrillingmethods.(3)inthecourseofdrilling,drillingwatercoresampling,boreholepressure,lengthandotherfactorsthatcanfullyreflectthecharacteristicsoftherockorconcretearemonitoredandrecordedandsubmittedtothesupervisor.(4)wewillaccordingtoinstructions,totestdrillcoreandconcrete-core,andtestrecordsandresultssubmittedtothesupervisor.(5)weshalleachboxortwocolorphotoforeachcoresample,andmadedetailedrecordsofthedrillingoperation,shouldbesubmittedtothesupervisor.(6)thesupervisorindicatingcorethatshouldbesaved,storedatthespecifiedlocationtopreventlossandmixed.11.3.4drillingprotectionconstructiondrawingsshowninalldrillholesshouldbeproperlyprotecteduntilacceptancesofar.11.4waterboreholeflushingandpressuretesting11.4.1Generalrequirements

(1)priortotheGrouting,allgrouthole(above)fissurecleaningandwaterpressuretest.

(2)faults,fracturesandotherareaswithcomplexgeologicalconditions,itscrackwashingthegrouthole,shouldbedirectedbythesupervisororbyfieldtestmethod.11.4.2flushing

(1)holeshouldbeflush.WeshallbeusingFengShuiasdirectedbysupervisorjointflushorcathetersintothetraffic

整体界面为一个19*19的棋盘,在f-06、f-14、j-10、n-06、n-14这五个位置画了一个小方块,以提醒玩家棋盘的中央位置,便于把握有利位置落子。

在棋盘的右侧是一些控制和提醒选项、按钮和对弈状态标签。

其中,选项有“我是老大我先来”和“让让电脑也无妨”两个。

选择前者,则玩家先落子;选择后者,则电脑先落子。

按钮有“人机对战,快冲啊”和“不行了,那重来吧”两个。

单击前者,则游戏开始;单击后者,则中断游戏,重新开始。

标签有“就不告诉你是谁赢了”和“就不告诉你这是第几步”两个。

前者是在游戏分出胜负后,显示是黑方取胜还是白方取胜;后者是在游戏过程中,不论是电脑落子还是玩家落子,都提示现在是第几步落子。

图3五子棋系统界面

3、系统模块设计

为了实现五子棋系统本身具有的功能,将系统分为这几个模块:

五子棋主模块、棋势扫描模块、棋势排序模块、棋势评估模块以及随机落子模块。

其中,五子棋主模块实现棋盘绘制、胜负判定的功能,以及对弈过程中对比双方棋势的择位落子模块。

棋势扫描模块、棋势排序模块、棋势评估模块分别实现棋势扫描、棋势排序、棋势评估的功能;而随机落子模块则实现在前两步棋势尚未形成时,电脑紧邻玩家落子位置随机择位落子的功能,是用例图中择位落子功能的一部分。

对应的,系统一共有五个类,分别对应五个模块;分别为:

五子棋主模块Gobang类、棋势扫描StatusScan类、棋势排序StatusSort类、棋势评估StatusEvaluation类,以及随机落子RandomPlay类。

类图如图4所示。

其中Gobang类中的属性和方法并没有完全列出,只列出了主要的属性和方法;其余类rateislow,youshouldreplacethedrillingequipmentorimprovedrillingmethods.(3)inthecourseofdrilling,drillingwatercoresampling,boreholepressure,lengthandotherfactorsthatcanfullyreflectthecharacteristicsoftherockorconcretearemonitoredandrecordedandsubmittedtothesupervisor.(4)wewillaccordingtoinstructions,totestdrillcoreandconcrete-core,andtestrecordsandresultssubmittedtothesupervisor.(5)weshalleachboxortwocolorphotoforeachcoresample,andmadedetailedrecordsofthedrillingoperation,shouldbesubmittedtothesupervisor.(6)thesupervisorindicatingcorethatshouldbesaved,storedatthespecifiedlocationtopreventlossandmixed.11.3.4drillingprotectionconstructiondrawingsshowninalldrillholesshouldbeproperlyprotecteduntilacceptancesofar.11.4waterboreholeflushingandpressuretesting11.4.1Generalrequirements

(1)priortotheGrouting,allgrouthole(above)fissurecleaningandwaterpressuretest.

(2)faults,fracturesandotherareaswithcomplexgeologicalconditions,itscrackwashingthegrouthole,shouldbedirectedbythesupervisororbyfieldtestmethod.11.4.2flushing

(1)holeshouldbeflush.WeshallbeusingFengShuiasdirectedbysupervisorjointflushorcathetersintothetraffic

基本列出了所有的属性和方法。

具体细节将在第四部分“五子棋的实现与测试”一节讨论,这里不再赘述。

图4五子棋系统的类图

四、五子棋的实现与测试

1、Gobang类的实现

Gobang类是五子棋的核心类,棋盘绘制、棋子落子,响应事件的处理,游戏的控制和模式设置,胜负判定,以及对棋势扫描、排序、评估等的调用都在这里实现。

Gobang类的类图如图5所示。

图5Gobang类类图

rateislow,youshouldreplacethedrillingequipmentorimprovedrillingmethods.(3)inthecourseofdrilling,drillingwatercoresampling,boreholepressure,lengthandotherfactorsthatcanfullyreflectthecharacteristicsoftherockorconcretearemonitoredandrecordedandsubmittedtothesupervisor.(4)wewillaccordingtoinstructions,totestdrillcoreandconcrete-core,andtestrecordsandresultssubmittedtothesupervisor.(5)weshalleachboxortwocolorphotoforeachcoresample,andmadedetailedrecordsofthedrillingoperation,shouldbesubmittedtothesupervisor.(6)thesupervisorindicatingcorethatshouldbesaved,storedatthespecifiedlocationtopreventlossandmixed.11.3.4drillingprotectionconstructiondrawingsshowninalldrillholesshouldbeproperlyprotecteduntilacceptancesofar.11.4waterboreholeflushingandpressuretesting11.4.1Generalrequirements

(1)priortotheGrouting,allgrouthole(above)fissurecleaningandwaterpressuretest.

(2)faults,fracturesandotherareaswithcomplexgeologicalcondition

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 党团工作 > 入党转正申请

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1