C++/c++

Advertisement


Question
ya i think its great thanks,plz tell me the concept in detail.-------------------------
Followup To
Question -
i am an average c++ programmer n i have to do a minor project in my prefinal yr.plz suggest any project which must be interactive n also give a brief synopsis of it.
Answer -
Hello,

Why not program a finite state machine to simulate artificial intelligence. Its really not that hard and could "wow" your teacher or classmates. All you do is set up a couple of states like: attack, locate, flee... and do a switch statement on the current state. Have it so there is certain qualifications you need to achieve in order to flip the state to another one, maybe a key press or something. I think it sounds pretty cool.

I hope this information was helpful.

- Eddie

Answer
Hello,

Glad you liked it. Its really actually very easy. start of with something like:

enum ACTIONS {LOCATE, ATTACK};

ACTIONS currentAction.

Then in your main program loop, you just switch on the current action and apply a behavior.

// in init
currentAction = LOCATE;

// in main loop

this->Update();

switch(currentAction)
{
case LOCATE:

// example
if(player.x > this->x)
this->currentVector = 2;
else
this->currentVector = -2;
break;

case ATTACK:
SpawnProjectile();
break;
}

// example of determining to switch states.
if(player.x - this->x <= 5)
currentState = ATTACK;

Notice in the locate, it checks to see if the player is on the left or right of it, and starts moving in the direction the player is, assumming we update the x and y positions based on the currentVector.

I hope this information was helpful.

- Eddie  

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Eddie

Expertise

I can answer questions about the C++ language, object oriented design and architecture. I am knowledgable in a lot of the math that goes into programming, and am certified by ExpertRating.com. I also know a good deal about graphics via OpenGL, and GUIs.

Experience

I have completed numerous games and demos created with the C++ programming language. Currently employed as a software engineer in the modeling and simulation field. I have about 7 years experience.

©2016 About.com. All rights reserved.