一个五子棋的框架(prg版)

这是一个五子其和小程序,代码中留下了写算法的接口,此代码目已经可完成基本功能,但存盘等功能尚未写代码,可按自己喜好写。

* 五子棋程序* Hunter 2001-11-08* Hunter 2001-06-11* Hunter 2001-06-08** 请自己定博弈算法,并在* _Form的Init     中相应处调用----Line 49* _QiPan的Go      中相应处调用----Line 157#Define Size_QiZi_Loc  30       && 棋子大小#Define Total_Line_Loc 15       && 棋盘线数#Define Renju_Loc      "五子棋"  && 表单标题#Define MsgTest_Loc    "此处已经有棋子了。"#Define MsgTitle_Loc   "不能落子"#Define Black_Loc      "黑棋"#Define White_Loc      "白棋"#Define Victory_Loc    "胜利"#Define ReSatrt_Loc    "重新开始吗?"Public poRenjupoRenju = Createobject("_Form")poRenju.Show(1)Read EventsClose AllRelease AllClear All*  Quit*类别列表:* _Form-------------表单>>>>DoComputer* _QiPan------------棋盘>>>>Go(),ReBew(),SaveLog(),LoadLog(),GoLog,QiZiCount[225]* _Container--------容器基类>>>>无边框,透明,高宽为棋子大小*  _B------------黑棋子*  _W------------白棋子*  _Hover--------光标标志>>>>随鼠标移动,>>>>Top_Assign(),Left_Assign(),X,Y*  _Line-------------线条基类>>>>鼠标事件由容器处理*  _LineX--------盘中竖线>>>>宽度为零*  _LineY--------盘中横线>>>>高度为零*   _LineHover----光标线>>>>蓝色*==========表单定义Define Class _Form As Form       AutoCenter = .T.       BorderStyle = 2       Caption = Renju_Loc       Desktop = .T.       MaxButton = .F.       ShowWindow = 2       WindowType = 1       DoComputer = "" && 电脑是否下棋----为空不下棋,"W"表示下白棋,"B"表示下黑棋       Add Object oQiPan As _QiPan With Top = 2,Left = 2 && 棋盘       Procedure Init               DoDefault()               * 表单比棋盘略大一些               This.Height = This.oQiPan.Height + 4               This.Width = This.oQiPan.Width + 4               If This.DoComputer = "B"                       && 请在此调用自己的博弈算法               Endif       Endproc       Procedure Destroy               && 在此退出               Clear Events       Endproc       Procedure KeyPress               Lparameters nKeyCode,nShift               If Isnull(Thisform.DoComputer)                       Do Case && 用键盘控制鼠标的移动,只要调用热点的相应方法即可.                               Case nKeyCode = 5 && 向上                                       This.oQiPan.Hover.MoveUp                               Case nKeyCode = 24 && 向下                                       This.oQiPan.Hover.MoveDown                               Case nKeyCode = 19 && 向左                                       This.oQiPan.Hover.MoveLeft                               Case nKeyCode = 4 && 向右                                       This.oQiPan.Hover.MoveRight                               Case nKeyCode = 13 Or nKeyCode = 32 && 空格及回车是落子.                                       This.oQiPan.Hover.Click                               Case nKeyCode = 27 && ESC 退出                                       Thisform.Destroy                               Otherwise                                       DoDefault()                       Endcase               Endif       EndprocEnddefine*==========棋盘定义Define Class _QiPan As Container       Start = .T.       BackColor = Rgb(255,128,0)       BorderWidth = 2       BorderColor = Rgb(0,0,255)       Height = Size_QiZi_Loc * Total_Line_Loc + 4       Width = Size_QiZi_Loc * Total_Line_Loc + 4       GoLog = "" && 落子记录,每一步用一字节记录,前四位记X值,       && 后四后记Y值,最长有225字节.通过它的长度可知该谁走棋       && 以下是棋盘中的线条       Add Object Protected Line01 As _LineX With Left = Size_QiZi_Loc *  0.5 + 2       Add Object Protected Line02 As _LineX With Left = Size_QiZi_Loc *  1.5 + 2       Add Object Protected Line03 As _LineX With Left = Size_QiZi_Loc *  2.5 + 2       Add Object Protected Line04 As _LineX With Left = Size_QiZi_Loc *  3.5 + 2       Add Object Protected Line05 As _LineX With Left = Size_QiZi_Loc *  4.5 + 2       Add Object Protected Line06 As _LineX With Left = Size_QiZi_Loc *  5.5 + 2       Add Object Protected Line07 As _LineX With Left = Size_QiZi_Loc *  6.5 + 2       Add Object Protected Line08 As _LineX With Left = Size_QiZi_Loc *  7.5 + 2       Add Object Protected Line09 As _LineX With Left = Size_QiZi_Loc *  8.5 + 2       Add Object Protected Line10 As _LineX With Left = Size_QiZi_Loc *  9.5 + 2       Add Object Protected Line11 As _LineX With Left = Size_QiZi_Loc * 10.5 + 2       Add Object Protected Line12 As _LineX With Left = Size_QiZi_Loc * 11.5 + 2       Add Object Protected Line13 As _LineX With Left = Size_QiZi_Loc * 12.5 + 2       Add Object Protected Line14 As _LineX With Left = Size_QiZi_Loc * 13.5 + 2       Add Object Protected Line15 As _LineX With Left = Size_QiZi_Loc * 14.5 + 2       Add Object Protected Line16 As _LineY With Top  = Size_QiZi_Loc *  0.5 + 2       Add Object Protected Line17 As _LineY With Top  = Size_QiZi_Loc *  1.5 + 2       Add Object Protected Line18 As _LineY With Top  = Size_QiZi_Loc *  2.5 + 2       Add Object Protected Line19 As _LineY With Top  = Size_QiZi_Loc *  3.5 + 2       Add Object Protected Line20 As _LineY With Top  = Size_QiZi_Loc *  4.5 + 2       Add Object Protected Line21 As _LineY With Top  = Size_QiZi_Loc *  5.5 + 2       Add Object Protected Line22 As _LineY With Top  = Size_QiZi_Loc *  6.5 + 2       Add Object Protected Line23 As _LineY With Top  = Size_QiZi_Loc *  7.5 + 2       Add Object Protected Line24 As _LineY With Top  = Size_QiZi_Loc *  8.5 + 2       Add Object Protected Line25 As _LineY With Top  = Size_QiZi_Loc *  9.5 + 2       Add Object Protected Line26 As _LineY With Top  = Size_QiZi_Loc * 10.5 + 2       Add Object Protected Line27 As _LineY With Top  = Size_QiZi_Loc * 11.5 + 2       Add Object Protected Line28 As _LineY With Top  = Size_QiZi_Loc * 12.5 + 2       Add Object Protected Line29 As _LineY With Top  = Size_QiZi_Loc * 13.5 + 2       Add Object Protected Line30 As _LineY With Top  = Size_QiZi_Loc * 14.5 + 2       && 以下是棋盘中的五个点       Add Object Protected Line31 As _LineHover  With BorderWidth = 8,Height = 0,Width = 0,;       Top = Size_QiZi_Loc *  3.5 + 2,Left = Size_QiZi_Loc *  3.5 + 2       Add Object Protected Line32 As _LineHover  With BorderWidth = 8,Height = 0,Width = 0,;       Top = Size_QiZi_Loc *  3.5 + 2,Left = Size_QiZi_Loc * 11.5 + 2       Add Object Protected Line33 As _LineHover  With BorderWidth = 8,Height = 0,Width = 0,;       Top = Size_QiZi_Loc *  7.5 + 2,Left = Size_QiZi_Loc *  7.5 + 2       Add Object Protected Line34 As _LineHover  With BorderWidth = 8,Height = 0,Width = 0,;       Top = Size_QiZi_Loc * 11.5 + 2,Left = Size_QiZi_Loc *  3.5 + 2       Add Object Protected Line35 As _LineHover  With BorderWidth = 8,Height = 0,Width = 0,;       Top = Size_QiZi_Loc * 11.5 + 2,Left = Size_QiZi_Loc * 11.5 + 2       && 以下是棋盘中用于标识光标的热点对象       Add Object Hover As _Hover       Procedure Init               This.AddProperty("QiZiCount[255]",.Null.) && 此属性用于保存棋盘中所下的棋子,因为动态添加的棋               && 子在清盘时要清掉,所以用此属性保存对它们的引用.               DoDefault()       Endproc       Procedure MouseMove               Lparameters nButton,nShift,nXCoord,nYCoord               && 鼠标移动时同步移动热点               This.Hover.Left = Int((nXCoord-2) / Size_QiZi_Loc) * Size_QiZi_Loc + 2               This.Hover.Top =  Int((nYCoord-2) / Size_QiZi_Loc) * Size_QiZi_Loc + 2       Endproc       Procedure MouseUp               Lparameters nButton,nShift,nXCoord,nYCoord       Endproc       Procedure Go &&落子               && 落子方法的参数说明:               && nTop 落子与棋盘上方的距离               && nLeft 落子与棋盘左边的距离               && nX 从左向右第几列(1---15)               && nY 从上向下第几行(1---15)               Lparameters nTop,nLeft,nXCoord,nYCoord               If This.Start = .F. && 这一局已经结束                       If Messagebox(ReSatrt_Loc,4,Renju_Loc) = 6                               This.ReNew()                       Endif                       Return               Endif               If At(Chr(nXCoord * 16 + nYCoord),This.GoLog) > 0 && 有棋子的地方不能落子                       Messagebox(MsgTest_Loc,0,Renju_Loc)                       Return               Endif               Local lnQiZiID               lnQiZiID = Len(This.GoLog)+1 && GoLog 中保存的是行棋的记录               && 先画一个棋子               This.AddObject("o_"+Alltrim(Str(lnQiZiID)),;                       Iif(Mod(Len(This.GoLog),2) = 0,"_B","_W"))               This.QiZiCount[lnQiZiID] = ;                       Evaluate("This.o_" + Alltrim(Str(lnQiZiID)))               This.QiZiCount[lnQiZiID].Top = nTop               This.QiZiCount[lnQiZiID].Left = nLeft               This.QiZiCount[lnQiZiID].Visible = .T.               && 更新行棋记录               This.GoLog = This.GoLog + Chr(nXCoord * 16 + nYCoord)               If IsVictory(This.GoLog)                       Messagebox(Iif(Mod(Len(This.GoLog),2) = 1,Black_Loc,White_Loc) + Victory_Loc,0,Renju_Loc)                       This.Start = .F.               Else                       && /////////////////////////////////////////////////////////////                       && 若该电脑走,则调用博弈算法                       && 请在此调用自已的博弈算法,并再调用此程序段下棋.                       && /////////////////////////////////////////////////////////////               Endif       Endproc       Procedure ReNew && 清盘               Local lnQiZiID               lnQiZiID = 1               Do While Not(Isnull(This.QiZiCount[lnQiZiID]))                       This.RemoveObject(This.QiZiCount[lnQiZiID].Name)                       This.QiZiCount[lnQiZiID] = .Null.                       lnQiZiID = lnQiZiID + 1               Enddo               This.GoLog = ""               This.Start = .T.       Endproc       Procedure SaveLog && 棋局存盘       Endproc       Procedure LoadLog && 读存盘文件       EndprocEnddefine*==========竖线定义Define Class _LineX As _LineHover       Height = Size_QiZi_Loc * (Total_Line_Loc - 1)+1       Width = 0       Top = Size_QiZi_Loc * 0.5+2Enddefine*==========横线定义Define Class _LineY As _LineHover       Width = Size_QiZi_Loc * (Total_Line_Loc - 1)+1       Height = 0       Left = Size_QiZi_Loc * 0.5+2Enddefine*==========黑棋子定义Define Class _B As _Container       Add Object Protected Shape1 As Shape With ;               Curvature=99,FillStyle=0,Top = 1,Left = 1,;               Height = Size_QiZi_Loc - 2,Width = Size_QiZi_Loc - 2Enddefine*==========白棋子定义Define Class _W As _Container       Add Object Protected Shape1 As Shape With ;               Curvature=99,FillStyle=0,Top = 1,Left = 1,;               Height = Size_QiZi_Loc - 2,Width = Size_QiZi_Loc - 2,;       BorderColor=Rgb(192,192,192),FillColor=Rgb(255,255,255)Enddefine*==========热点定义Define Class _Hover As _Container       X = 0       Y = 0       Add Object Protected Line10 As _LineHover With Width = 0,Height = Size_QiZi_Loc / 4,;       Left = 0,Top = 0       Add Object Protected Line20 As _LineHover With Height = 0,Width = Size_QiZi_Loc / 4,;       Top = 0,Left = 0       Add Object Protected Line30 As _LineHover With Width = 0,Height = Size_QiZi_Loc / 4,;       Left = 0,Top = Size_QiZi_Loc / 4 * 3 + 1       Add Object Protected Line4 As _LineHover With Height = 0,Width = Size_QiZi_Loc / 4,;       Top = 0,Left = Size_QiZi_Loc / 4 * 3 + 1       Add Object Protected Line5 As _LineHover With Width = 0,Height = Size_QiZi_Loc / 4,;       Left = Size_QiZi_Loc - 1,Top = 0       Add Object Protected Line6 As _LineHover With Height = 0,Width = Size_QiZi_Loc / 4,;       Top = Size_QiZi_Loc - 1,Left = 0       Add Object Protected Line7 As _LineHover With Width = 0,Height = Size_QiZi_Loc / 4,;       Left = Size_QiZi_Loc - 1,Top = Size_QiZi_Loc / 4 * 3 + 1       Add Object Protected Line8 As _LineHover With Height = 0,Width = Size_QiZi_Loc / 4,;       Top = Size_QiZi_Loc - 1,Left = Size_QiZi_Loc / 4 * 3 + 1       Procedure Click               This.Parent.Go(This.Top,This.Left,This.X,This.Y) && 落子----由棋盘完成       Endproc       Procedure Left_Assign               Lparameters vNewVal               This.Left = vNewVal               This.X = Int((This.Left - 2) / Size_QiZi_Loc) + 1       Endproc       Procedure Top_Assign               Lparameters vNewVal               This.Top = vNewVal               This.Y = Int((This.Top - 2) / Size_QiZi_Loc) + 1       Endproc       && 定义下面的四个方法是为了支持键盘操作       Procedure MoveUp && 上移               If This.Y > 1                       This.Top = This.Top - Size_QiZi_Loc               Endif       Endproc       Procedure MoveDown && 下移               If This.Y < Total_Line_Loc                       This.Top = This.Top + Size_QiZi_Loc               Endif       Endproc       Procedure MoveLeft && 左移               If This.X > 1                       This.Left = This.Left - Size_QiZi_Loc               Endif       Endproc       Procedure MoveRight && 右移               If This.X < Total_Line_Loc                       This.Left = This.Left + Size_QiZi_Loc               Endif       EndprocEnddefine*==========热点标识线条Define Class _LineHover As _LineHover       BorderColor = Rgb(0,0,255)Enddefine*==========容器基类Define Class _Container As Container       BackStyle = 0       BorderWidth = 0       Height = Size_QiZi_Loc       Width = Size_QiZi_LocEnddefine*==========线条基类Define Class _LineHover As Line       Procedure MouseMove && 不处理事件,全部传到容器中进行处理,但要重算坐标               Lparameters nButton,nShift,nXCoord,nYCoord               This.Parent.MouseMove(nButton,nShift,nXCoord,nYCoord)       Endproc       Procedure MouseDown               Lparameters nButton,nShift,nXCoord,nYCoord               This.Parent.MouseDown(nButton,nShift,nXCoord,nYCoord)       Endproc       Procedure MouseUp               Lparameters nButton,nShift,nXCoord,nYCoord               This.Parent.MouseUp(nButton,nShift,nXCoord,nYCoord)       Endproc       Procedure Click               This.Parent.Click       Endproc       Procedure DblClick               This.Parent.DblClick       EndprocEnddefine*====================================================================================Function IsVictory(GoLog) && 判断最后落子者是否构成五连       Local laGo[Total_Line_Loc,Total_Line_Loc] && 这是一张棋盘       Local N,lcEveryOne,lnX,lnY       && 生成棋盘       For N = Len(GoLog) To 1 Step -2 && 这张棋盘只需记录一种棋子即可               lcEveryOne = Subst(GoLog,N,1)               lnX = Int(Asc(lcEveryOne) / 16)               lnY = Mod(Asc(lcEveryOne),16)               laGo[lnX,lnY] = .T.       Endfor       Release N,lcEveryOne       lnX = Int(Asc(Right(GoLog,1)) / 16) && 最后落点 ,值为 1 ~ Total_Line_Loc       lnY = Mod(Asc(Right(GoLog,1)),16)       Local X,Y,Z && 是否在四个方向之一构成五连----构成五连则胜出       For X = Max(lnX - 4,1) To Min(lnX,Total_Line_Loc - 4) && Y 轴不变               If laGo[X,lnY] And ;                               laGo[X + 1,lnY] And ;                               laGo[X + 2,lnY] And ;                               laGo[X + 3,lnY] And ;                               laGo[X + 4,lnY]                       Return .T.               Endif       Endfor       For Y = Max(lnY - 4,1) To Min(lnY,Total_Line_Loc - 4) && X 轴不变               If laGo[lnX,Y] And ;                               laGo[lnX,Y + 1] And ;                               laGo[lnX,Y + 2] And ;                               laGo[lnX,Y + 3] And ;                               laGo[lnX,Y + 4]                       Return .T.               Endif       Endfor       For Z = 4 + Max(lnX,lnY) - Total_Line_Loc To Min(lnX - 1,lnY - 1,4) && XY 轴同步改变               If laGo[lnX - Z,lnY - Z] And ;                               laGo[lnX - Z + 1,lnY - Z + 1] And ;                               laGo[lnX - Z + 2,lnY - Z + 2] And ;                               laGo[lnX - Z + 3,lnY - Z + 3] And ;                               laGo[lnX - Z + 4,lnY - Z + 4]                       Return .T.               Endif       Endfor       For Z = Max(0,lnX + 4 - Total_Line_Loc,4 - lnY) ;               To Min(4,lnX - 1,Total_Line_Loc - lnY) && X 轴增加 Y 轴减少               If laGo[lnX - Z,lnY + Z] And ;                               laGo[lnX - Z + 1,lnY + Z - 1] And ;                               laGo[lnX - Z + 2,lnY + Z - 2] And ;                               laGo[lnX - Z + 3,lnY + Z - 3] And ;                               laGo[lnX - Z + 4,lnY + Z - 4]                       Return .T.               Endif       Endfor       Return .F.Endfunc

猫猫的心里话

加菲猫的VFP|狐友会社群接收投稿啦

加菲猫的VFP,用VFP不局限VFP,用VFP混合一切。无论是VFP,还是JS,还是C,只要能混合起来,都可以发表。

商业模式,销售技巧、需求规划、产品设计的知识通通可以发表。

暂定千字50元红包,,优秀的文章红包更大,一经发表,红包到手。

如何帮助使用VFP的人?

用VFP的人,有专业的,有非专业了,很多人其实是小白,问出的问题是小白,如果问题不对,我们引导他们问正确的问题。无论如何请不要嘲笑他们说帮助都不看,这么简单的问题都不会,嘲笑别人不行,而无法提出建设性答案,是很low的。

我们无论工作需要,还是有自己的软件,都是是需要真正的知识,如何让更多人学习真正的VFP知识呢,只需要点赞,在看,能转发朋友圈就更好了。

加菲猫的vfp倡导用"VFP极简混合开发,少写代码、快速出活,用VFP,但不局限于VFP,各种语言混合开发"

我已经带领一百多名会员成功掌到VFP的黑科技,进入了移动互联网时代,接下来我们要进入物联网领域。

2025年狐友会社群会员继续招募中

社群会员获取的权益有:

祺佑三层开发框架商业版(猫框),终身免费升级,终身技术支持。

开放的录播课程有:

微信小程序,微信公众号开发,H5 APP开发,Extjs BS开发,VFP面向对象进阶,VFP中间层开发。

源码类资源有:

支付组件源码,短信源码,权限组件源码,一些完整系统的源码。这个可以单独出售的,需要的可以联系我。

会员也可以实现群内资源对接,可以接分包,合作等各项商业或技术业务

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值