Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm working on a turn based game in Unity. I need to perform field/grid analysis(2D grid) when i'm iterating trough each unit "entity". The A.I. should be able to plan ahead and therefor needs to consider the components each unit have. Not every unit will have the same ability. These abilities are defined as components.

I want to make it flexible in the sense that I can plug in new abilities and my A.I. will take it into consideration.

While user control is somewhat implemented, A.I. hasn't even been written. So I'm open to any suggestion.

Q : What is a way for the A.I. system to collect all abilities of one unit and make decisions depending on each component?

edit: I know there is the "null" checking method to see if the gameobject contains a component. But this is highly inflexible because you are hard coding a stack of if else. Something I want to prevent.

share|improve this question
    
One approach could be to simulate the game in advance trying out different decisions and rating the outcome. That's (overly simplified) how AIs for games like chess work. –  Philipp Apr 9 '13 at 7:24
    
@Philipp I came to that conclusion myself. But that's not what I asked though =). –  Sidar Apr 9 '13 at 7:25
    
Answering the "how to put it into components" question first without even knowing anything about the AI system is shooting in the dark. Tell us more about your AI system, the answer depends on it. –  Maik Semder Apr 9 '13 at 7:49
    
@MaikSemder Im not asking how to put it in components. I'm asking how I could setup my A.I. system in such a way it knows what Components my gameobjec contains. And make decisions based on that. I Don't have a A.I. system yet because I'm trying to understand how I could make it work best in combination with components. –  Sidar Apr 9 '13 at 7:56
    
What is common between abilities in a way your AI handles them? Can't you just make them implement common interface? –  Den Apr 9 '13 at 12:01

1 Answer 1

up vote 1 down vote accepted

http://en.wikipedia.org/wiki/Polymorphism_(computer_science)

Polymorphism is probably one of the primary solutions to component based algorithms. I do not know how well unity can handle this sort of thing but this is likely going to lead you in the direction you are looking for.

The idea is each ability a unit has is derived from a basic ability class, and added into an ability list, then the AI can look at each ability in the list and determine how to handle the ability.

Your best bet is to have a function in said ability that returns a data structure to the AI that contains analysis data the AI can use to learn about the ability.

share|improve this answer
    
Thanks for your input. Unity does handle Interfaces pretty well. You can request the components implementing the interface by passing the interface type just like you would pass the component type (gameObject.GetComponent<MyInterface>() ). While some stuff is bound to be "hardcoded" it feels like most of my A.I. is going to be hardcoded and hardly flexible in the end. I just don't have a clue on how to make the A.I. "understand" what an Attack component should represent opposed to a Walk component. –  Sidar Apr 9 '13 at 18:20
    
I don't know the specifics of how you want your AI to behave, but in most cases, AI do not need to know all the complexities of each ability that may be coming at them (or do they?). If you spend too much time analyzing every action made by the enemy then you risk bogging down the game or having an AI be "too intelligent." –  UnderscoreZero Apr 9 '13 at 20:35
    
Well, you can always dumb down the A.I. . Since it's a turn based mechanic risking to bog it down seems fairly slim. I'm still looking into it. I'll leave the question open for now. But ill try to work it out with a polymorphic approach. –  Sidar Apr 10 '13 at 7:30
    
I think I have an idea. Have some points! –  Sidar Apr 10 '13 at 7:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.