人工智能算法在游戏中演示

人工智能算法在游戏中演示

人工智能是一个非常具有潜力的分支,顾名思义,它可以通过计算机指令模拟人的行为,在游戏中的人工智能就非常地多样了。对于FPS、TAB、RPG、STG、ADV等游戏,有着不同的人工智能,但都基于几种理论:有限状态机、遗传算法、神经网络等。下面我就采用游戏中最基础也是最常用的人工智能算法来进行演示。
我的开发环境是:
Windows: WindowsXP(SP3) + MinGW4.4/MinGW4.7 + Qt4.8.3/Qt5.0.1 + QtCreator2.6/QtCreator2.7
Linux: Ubuntu12.10 + gcc4.7 + Qt4.8.1/Qt4.8.4/Qt5.0.1 + QtCreator2.6/QtCreator2.7
演示程序下载地址: 这里
源代码下载地址: 这里
注意:由于Qt5.0.1中一个未知的Bug,编译运行后角色无法移动,所以请使用Qt4.6+来进行编译。

程序截图如下所示:




通过子窗口的控制选项,我们可以设置我们的初音ミク、镜音リン和镜音レン的控制方法,可以选择人工控制也可以选择AI控制。如果选择人工控制,那么可以通过按下“上下左右”键控制角色的移动,如果选择AI控制,那么角色会沿着场景作顺时针移动。
整个项目的代码量较多,我将选择有关人工智能的内容进行讲解,也希望大家沿着我的思路思考下去。
首先如何让角色沿着窗口作顺时针旋转?一个简单的想法就是:当角色将要达到窗口顶端那么角色将往右移动;角色将要到达窗口右端那么角色将往下移动,以此类推。按照这样的思路,我写了这样的AI代码:
  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
======================================================================== 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. /////////////////////////////////////////////////////////////////////////////

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值