50 likes | 190 Views
In this chapter, we'll explore how to create intelligent game objects using a rule-based AI system. You'll learn how to implement various functionalities, such as managing object behavior, generating random numbers for dynamic actions, and ensuring distinct operations for each intelligent entity. This guide covers the development of simple collision detection, managing object lifecycles during gameplay, and utilizing timers for AI decision-making. Additionally, examples will demonstrate how to predict object behaviors (e.g., a crow's movement) and manage their states effectively.
E N D
Chapter 6-6. Artificial Intelligence • Demo 06 실행 • Code file • Bmp.h Bmp.cpp, Timer.h, Timer.cpp • Defines.h, Bsprite.h, Bsprite.cpp, • objects.h, objects.cpp, Sbmp.h, Sbmp.cpp • Ddsetup.cpp, CSprite.h, Csprite.cpp, View.h(cpp) • Main.cpp, Objects.h, Objects.cpp • Objman.h(cpp), Random.h(cpp) : 수정 • Ai.h(cpp) : 추가 • Media file • Sprite.bmp,Bckgnd.bmp, Farm.bmp • Lib file • Ddraw.lib, Winmm.lib
Here’s what you’ll learn • Rule based system의 정의와 구현방법 • 사물 개체의 코드위에 개체 지능 구축하는 방법 • 타이머와 의사 랜덤 수 생성기를 사용하여 지능형 개체들이 동일하게 작동하지 못하게 하는 방법 • 게임중에 생성 및 소멸되는 개체 관리하는 방법 • 단순 형태의 충돌 감지 구현하는 방법
Artificial Intelligence • Rule based system을 이용한 인공지능구현 방법 • 까마귀의 동작을 예측하기 쉽지 않고, 보다 무질서한 개체구현
지능형 개체구현(1) • Cobject에서 CIntelligentObject 유도 • Simple Rule-based system을 이용하여 지능형 개체 구현 • CIntelligentObject의 특성 • 추적 : 까마귀 개체 달아남, 높이 변경 • 계속추적 시 : 지쳐서 속도를 낮춤 • 비행기속도를 낮춤 : 까마귀 무리 형성(비행기 앞, 뒤)
지능형 개체 구현(2) //defined in Ai.h(cpp) enum StateType{CRUISING_STATE,AVOIDING_STATE}; #include "objects.h" class CIntelligentObject: public CObject{ private: StateType m_eState; //state int m_nDesiredHeight; //desired altitude int m_nHeightTime; //time between height changes int m_nHeightDelayTime; //time to next height change int m_nSpeedVariationTime; //last time speed varied int m_nSpeedVariationDuration; //time to next speed vrn int m_nLastAiTime; //last time AI was used int m_nAiDelayTime; //time until AI next used int m_nDistance; //distance to plane int m_nVerticalDistance; //vertical distance from plane int m_nHorizontalDistance; //hor. distance from plane void ai(); //artificial intelligence void cruising_ai(); //ai for cruising along void avoiding_ai(); //ai for avoiding plane void set_state(StateType state); //change state public: CIntelligentObject(ObjectType object,int x,int y, int xspeed,int yspeed); //constructor virtual void move(); //move depending on time and speed void plane(int x,int y,int d); //relationship w/plane };