五子棋AI算法第三篇-Alpha Beta剪枝

剪枝是必须的

五子棋AI教程第二版发布啦,地址:https://github.com/lihongxun945/myblog/labels/%E4%BA%94%E5%AD%90%E6%A3%8BAI%E6%95%99%E7%A8%8B%E7%AC%AC%E4%BA%8C%E7%89%88

当前这个是旧版教程,强烈建议阅读新版教程。

上一篇讲了极大极小值搜索,其实单纯的极大极小值搜索算法并没有实际意义。

可以做一个简单的计算,平均一步考虑 50 种可能性的话,思考到第四层,那么搜索的节点数就是 50^4 = 6250000,在我的酷睿I7的电脑上一秒钟能计算的节点不超过 5W 个,那么 625W 个节点需要的时间在 100 秒以上。电脑一步思考 100秒肯定是不能接受的,实际上最好一步能控制在 5 秒 以内。

顺便说一下层数的问题,首先思考层数必须是偶数。因为奇数节点是AI,偶数节点是玩家,如果AI下一个子不考虑玩家防守一下,那么这个估分明显是有问题的。
然后,至少需要进行4层思考,如果连4四层都考虑不到,那就是只看眼前利益,那么棋力会非常非常弱。 如果能进行6层思考基本可以达到随便赢普通玩家的水平了(普通玩家是指没有专门研究过五子棋的玩家,棋力大约是4层的水平)。

Alpha Beta 剪枝原理

Alpha Beta

  • 28
    点赞
  • 145
    收藏
    觉得还不错? 一键收藏
  • 13
    评论
======================================================================== MICROSOFT FOUNDATION CLASS LIBRARY : fir ======================================================================== AppWizard has created this fir application for you. This application not only demonstrates the basics of using the Microsoft Foundation classes but is also a starting point for writing your application. This file contains a summary of what you will find in each of the files that make up your fir application. fir.dsp This file (the project file) contains information at the project level and is used to build a single project or subproject. Other users can share the project (.dsp) file, but they should export the makefiles locally. fir.h This is the main header file for the application. It includes other project specific headers (including Resource.h) and declares the CFirApp application class. fir.cpp This is the main application source file that contains the application class CFirApp. fir.rc This is a listing of all of the Microsoft Windows resources that the program uses. It includes the icons, bitmaps, and cursors that are stored in the RES subdirectory. This file can be directly edited in Microsoft Visual C++. fir.clw This file contains information used by ClassWizard to edit existing classes or add new classes. ClassWizard also uses this file to store information needed to create and edit message maps and dialog data maps and to create prototype member functions. res\fir.ico This is an icon file, which is used as the application's icon. This icon is included by the main resource file fir.rc. res\fir.rc2 This file contains resources that are not edited by Microsoft Visual C++. You should place all resources not editable by the resource editor in this file. ///////////////////////////////////////////////////////////////////////////// For the main frame window: MainFrm.h, MainFrm.cpp These files contain the frame class CMainFrame, which is derived from CFrameWnd and controls all SDI frame features. ///////////////////////////////////////////////////////////////////////////// AppWizard creates one document type and one view: firDoc.h, firDoc.cpp - the document These files contain your CFirDoc class. Edit these files to add your special document data and to implement file saving and loading (via CFirDoc::Serialize). firView.h, firView.cpp - the view of the document These files contain your CFirView class. CFirView objects are used to view CFirDoc objects. ///////////////////////////////////////////////////////////////////////////// Other standard files: StdAfx.h, StdAfx.cpp These files are used to build a precompiled header (PCH) file named fir.pch and a precompiled types file named StdAfx.obj. Resource.h This is the standard header file, which defines new resource IDs. Microsoft Visual C++ reads and updates this file. ///////////////////////////////////////////////////////////////////////////// Other notes: AppWizard uses "TODO:" to indicate parts of the source code you should add to or customize. If your application uses MFC in a shared DLL, and your application is in a language other than the operating system's current language, you will need to copy the corresponding localized resources MFC42XXX.DLL from the Microsoft Visual C++ CD-ROM onto the system or system32 directory, and rename it to be MFCLOC.DLL. ("XXX" stands for the language abbreviation. For example, MFC42DEU.DLL contains resources translated to German.) If you don't do this, some of the UI elements of your application will remain in the language of the operating system. /////////////////////////////////////////////////////////////////////////////
强化学习五子棋是指使用强化学习算法,通过与环境进行交互,自主学习并提高下棋技术的过程。在这个过程中,我们可以使用MATLAB作为实现工具。 首先,我们需要构建一个五子棋的环境模型。这个模型可以包含棋盘、棋子、规则、胜负判断等要素。可以通过MATLAB的图形界面设计棋盘并实现人机交互,也可以通过命令行编程实现。 然后,我们可以选择合适的强化学习算法来训练我们的五子棋AI。常用的算法包括Q-Learning、深度强化学习等。在MATLAB中,我们可以使用Deep Learning Toolbox或者Reinforcement Learning Toolbox来实现这些算法。 接下来,我们需要确定强化学习的状态、动作和奖励函数。状态可以定义为棋盘的状态,例如每个位置上是空、黑棋还是白棋。动作可以定义为下子的位置。奖励函数可以根据下棋的结果给予奖励或惩罚,例如赢了棋局可以给予正反馈,输了棋局可以给予负反馈。 在训练过程中,我们可以使用强化学习算法不断优化AI的策略。通过与环境的交互,AI会逐渐学习到最佳的下棋策略。我们可以使用MATLAB提供的实时可视化工具来观察AI的学习过程,例如绘制学习曲线、棋局展示等。 最后,我们可以通过保存和加载模型的方式,将训练好的AI应用到真实的五子棋对局中。AI可以与人类玩家对弈,也可以与其他AI进行对弈,检验其训练效果。 总之,使用MATLAB进行强化学习五子棋是一个有趣且有挑战性的任务。通过合适的环境模型、强化学习算法和训练过程,我们可以培养出一个具备高水平下棋技术的AI

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值