Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411508 Posts in 69374 Topics- by 58430 Members - Latest Member: Jesse Webb

April 26, 2024, 09:55:24 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Fighting Game A.I. in C++
Pages: [1]
Print
Author Topic: Fighting Game A.I. in C++  (Read 998 times)
shinn497
Level 0
**


View Profile WWW
« on: March 02, 2015, 11:17:06 AM »

Hi guys!

I really need to program a fighting game AI and I cannot find any guide, even theoretical on how to do this. I've looked into implementing a Finite State machine but some of the examples seem complex to do in C++.

Currently I'm working on a system that I believe to be a basic interpretation of FSMs. I made an AI node class that holds a vector of pointers to other AI nodes. It will take inputs such as player position, enemy position, current player state, etc. etc. There will also be an AIhandler class that actually implements and delegates these nodes.

Is this the most ideal way of doing this or is there something more efficient?
Logged

I tweet things


Check out Araka:
Facebook | Twitter|DevLog|#ArakaRises
BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #1 on: March 03, 2015, 01:32:34 PM »

you don't need a network of nodes unless you want the AI to be configured at runtime. The more straightforward way of coding a FSM AI into a game is as follows:

Code:
enum State
{
WARY,
OFFSENSE,
DEFENSE,
MID_COMBO,
ETC,
}

State currentState;

void aiStep()
{
  // Randomly switch states to keep the player on their toes
  if(rand() < 0.01)
    currentState = rand() < AGGRESSIVENESS_CONSTANT ? OFFENSIVE : DEFENSIVE;
  // No matter what state, follow up combos if appropriate
  if(isMidCombo())
    currentState = MID_COMBO;
  switch(currentState)
  {
    case WARY:
      if(opponentIsNear(THRESHOLD_CONSTANT) && !oppenentIsBlocking())
      {
        currentState = DEFENSIVE;
        // Retry in new state
        aiStep();
        return;
      }
    case DEFENSIVE:
      block();
      return;
    case OFFENSIVE:
      //etc   
  }
}

No nodes or anything needed. Less flexible, but for a one man shop I think perfectly acceptable.

I've put a lot of non-FSM logic in as well to illustrate how it typically integrates - your textbook won't explain that part probably, but FSMs alone tend to give rather boring AIs. You can customize different characters by adding extra snippets of logic that only apply to them, and the various constants.
Logged
J-Snake
Level 10
*****


A fool with a tool is still a fool.


View Profile WWW
« Reply #2 on: March 03, 2015, 03:25:19 PM »

You can perfectly do it like Boris suggested, but add a memory model to the FSM (store some history in variables which influence the next state transition). Otherwise the amount of states would explode if you want to achieve more interesting AI.

I think it is fundamentally important to first work out a conceptual model of AI. And then you should think about how to implement/approximate that model. If you fail at modeling it in the first place then no implementation will help.
Logged

Independent game developer with an elaborate focus on interesting gameplay, rewarding depth of play and technical quality.<br /><br />Trap Them: http://store.steampowered.com/app/375930
shinn497
Level 0
**


View Profile WWW
« Reply #3 on: March 03, 2015, 04:20:31 PM »

TY! I like your responses this is SO MUCH BETTER!

Funny I read some papers on this and I didn't get it until you showed me that.

Thanks a lot! This will really help.
Logged

I tweet things


Check out Araka:
Facebook | Twitter|DevLog|#ArakaRises
shinn497
Level 0
**


View Profile WWW
« Reply #4 on: March 03, 2015, 04:21:08 PM »

I should say. It is hard to find a good resource that explains the ideal model for  a fighting game. But a Hierarchal FSM is what was recommended.
Logged

I tweet things


Check out Araka:
Facebook | Twitter|DevLog|#ArakaRises
Fallsburg
Level 10
*****


Fear the CircleCat


View Profile
« Reply #5 on: March 03, 2015, 09:41:21 PM »

You can perfectly do it like Boris suggested, but add a memory model to the FSM (store some history in variables which influence the next state transition). Otherwise the amount of states would explode if you want to achieve more interesting AI.

I think it is fundamentally important to first work out a conceptual model of AI. And then you should think about how to implement/approximate that model. If you fail at modeling it in the first place then no implementation will help.

On this note, I'd recommend looking into Behavior Trees or Goal Oriented Action Planning, as they do a much better job of handling the combinatorial state explosion that J Snake is talking about.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic