|
2 registered members (TipmyPip, izorro),
556
guests, and 2
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
[AI] : advice on FSM structure and transitions
#116210
03/09/07 22:09
03/09/07 22:09
|
Joined: Mar 2006
Posts: 752 Portugal
demiGod
OP
User
|
OP
User
Joined: Mar 2006
Posts: 752
Portugal
|
Hi, I need some advice here in a basic finite state machine architecture that i plan to execute and expand later. Now a little picture:  Well, i want to implement a hierarchical FSM where the teams have the ability to perform commands to their respective players defining the goals to be anchieved, considering the game circunstances like defending or attacking. Also, the players have their own states and i pretend to centralize the logic of the transitions between states embedded in the states themselves. If you see the picture, the animation states and steering behaviors are calculated / checked in the players states and not in the players action. In the other hand i need to implement two game modes: a player mode when the player controls the selected entity by the input (keyboard, gamepad, joystick), and a computer mode, when there is the AI that controls the movement and behavior of the entities. Well, i have some doubts about the good way / modular way to implement and join all this parts i mentioned in one functional architecture, so i am waitting some answers from people more experient in this matter, about these questions: 1) Is this a good way to anchieve what i want, or there is another better approach? 2) Should i handle the animation states in the player states logic or in the global players action, or it is the same? 3) If the transition logic its embedded in the states themselves, how can i prevent to duplicate constant if checking transitions in all states, i mean, there is another way to do that unless using if statements to define what transition should occour? This way i need to check every frame a "transition table" in all states, or not? 4) Where should be included the player and computer modes in the overall structure i am presenting, in an effective way? Ok, resuming i need some hints / guidelines from people who have done this already and know the problems of a FSM when handle many states, and its integration with animation, input, steering behaviors, etc. Thanks in advance and sorry for the long post.
|
|
|
Re: [AI] : advice on FSM structure and transitions
[Re: demiGod]
#116211
03/10/07 00:10
03/10/07 00:10
|
Joined: Feb 2004
Posts: 217 Wennigsen, Germany
Gordon_Shumway
Member
|
Member
Joined: Feb 2004
Posts: 217
Wennigsen, Germany
|
Hi DemiGod !!! First of all, what kind of game your planing to do ? In my opinion FSM is very powerfull and a good way to create AI for most of the games. A very, very important point, which is maybe missing in your picture, is the communication between the different machines. Just a simple example ....mmmh let me think .... ok: Jon can do a few things: working, go home, eat, sleep His wife can do: do housework(yesterday was the worlds-woman-day  ), cook, sleep After work before he gets a little bit sleep, he wants to eat a nice lunch. So, If they are not communicate with each other, the following will happen: Jon is working the whole day and when he finished he gets home and is very hungry, but his wife is doing housework until she gets to bed. Jon has to go to bed without eat anything. She will never cook for him. But if Jon is sending a message everything is fine and the situation is the following: Jon has finishing work and is sending the message "Honey, I'' be at home in 1 hour and I'm very hungry, please cook me a nice litte lunch". His wife receives the messages stopps what she was doing and starts to cook lunch. The he wents home, eats and then goes to bed. I hope, you understand that communication is very important in FSMs. Bye, G.S.
Last edited by Gordon_Shumway; 03/10/07 00:11.
|
|
|
Re: [AI] : advice on FSM structure and transitions
[Re: Gordon_Shumway]
#116214
03/10/07 14:09
03/10/07 14:09
|
Joined: Jan 2003
Posts: 4,305
Damocles
Expert
|
Expert
Joined: Jan 2003
Posts: 4,305
|
I could imagine for a message system, that every Entity has a message-que where messages and requests are stored by importance and expieration time.
Whenever the State Machine comes to deciding to switch to another state, it looks into the message-que and commits the most important orders stores there. (with some random variation)
This message-que can be accessed by other entities (nearby), a common controll AI, or simply be the entity itself (like the request to restore health or react to an attack)
So every time the statemachine checks for a statechange (either every frame, or whenever it finished its last action) it will switch to the corresponding state to fulfill the most important order.
Putting some random variation into the choise is important, to make the AI behave less predictable.
The message-que should expire old requests that are over time, and remove requests that where fulfilled.
---
Animation is not linked to the AIs decisionmaking, but a nice addon to its grafical apperance. So the animation should be seperated from the AI logic, as it does not belong there. The current state should just set the entities "animation-state" to the corresponding animationtype. The animation itself is run in a paralel function that reads out the animation-state.
|
|
|
Re: [AI] : advice on FSM structure and transitions
[Re: Damocles]
#116215
03/10/07 16:07
03/10/07 16:07
|
Joined: Mar 2006
Posts: 752 Portugal
demiGod
OP
User
|
OP
User
Joined: Mar 2006
Posts: 752
Portugal
|
@ Gordon: thanks for the advice, actually i already bought that book and read it and some concepts i mentioned its based on that, but translating c++ to c-script isnt so easy for me, so i will accept your offer and if i have specific questions i will ask you, if you dont mind..
About the master mind you are referring after scripting all FSMs.. its some kind of central CPU? i dont understood, you see, i am scripting all the transitions logic embedded in the transitions themselves, why should i need a central master mind with ifs and thens, thats what i want to avoid..
@ Damocles:
a) i understand the concept of message quering, but you see, i will implement a separate function for each message (msg_passToMe, msg_returnHomeRegion, etc.), and when an entity sends a message to another team mate, where should be made that quering? If i am centralizing the state transition logic in the states themselves, should be there or in a separate global / CPU function?
b) about the random variation i intend to implement also some kind of fuzzy logic in the states transition, but later;
c) about the animation, yes the animation handle its done with separate states / functions saved in a simple skill like my.animation_state. So you are saying that the animation states transition should be checked inside the players states transition logic, isnt it?
I have another problem, i dont very well how to integrate the computer and player modes, because the input its making some mess with concorrent states transitions..
|
|
|
Re: [AI] : advice on FSM structure and transitions
[Re: demiGod]
#116216
03/10/07 17:54
03/10/07 17:54
|
Joined: Jan 2003
Posts: 4,305
Damocles
Expert
|
Expert
Joined: Jan 2003
Posts: 4,305
|
There are so many ways to program the messaging or state-transotion logic, I can only tell you how I would approach it.
You could make all states for example as a seperate, looping function.
For example, a statefunction could look like this:
//the state is just an everlooping funtion, that will do the //current states tasks, and switch to another function if required
function state_a (this_state) { var new_state;
new_state=this_state; while(1) {
new_state=get_new_state(this_state); //get the required state from the logic
//either switch to a new state, or keep in this one if(new_state!=this_state) { //switch to new state if(new_state==statetype_b){state_b(new_state);} if(new_state==statetype_c){state_c(new_state);} if(new_state==statetype_d){state_d(new_state);} return; //terminate this state-loop }
//do the thinks to do for this state ...
wait(1); } }
function get_new_state(current_state) { //here is the logic that determines what state to take //this is the complicated logic to program
var priority; //the priority tells you, how important the current state is the bot is in
if(current_state==statetype_a){priority=10;} //low priority state, like patroling on a path if(current_state==statetype_b){priority=50;} //high priority state, like attacking an enemy if(current_state==statetype_c){priority=90;} //very high priority state, almost dead and looking for healthpickup if(current_state==statetype_d){priority=0;} //no priority state, waiting for example
//get a new state from the "normal" statechange if(need_statechange()){current_state=get_new_best_state();}
//overwrite the current state, if there is a hight priority state in the message stack if(message_stack_priority()>priority) //is the most important state in the list more important than what I do now? { current_state=get_state_from_messagestack(); //get the required new state from the messages }
return (current_state); //no changes required, just keep the old state }
.... And so on. The message list could be mode of arrays, that store requests by other bots, or the controller AI to change the bots state to something. -> like following the player or attacking a certain enemy. these requests get a priority (fixed value + a random value) and a time (so that like 20 seconds after the request, it is unimportant and gets erased)
This way the bot will react to important requests from the messagebox if they are more important than what the bot is doing now.
|
|
|
Re: [AI] : advice on FSM structure and transitions
[Re: demiGod]
#116219
03/10/07 19:36
03/10/07 19:36
|
Joined: Jan 2003
Posts: 4,305
Damocles
Expert
|
Expert
Joined: Jan 2003
Posts: 4,305
|
Quote:
But this way i need to check in every state transition logic which team and gameMode it belongs
Ok, this is a typical example of redundant code. Try to write a function that includes the part of code that is repeating, so you only have to write it at one place.
|
|
|
|