C++/c++
Expert: Eddie - 9/6/2004
Questionya 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
AnswerHello,
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