Sign in to follow this  
Shadowwoelf

Passing world data to AI entites

Recommended Posts

I am working on a bug simulation game and was wondering how do I effectively pass world data to the individual bugs.

I have 5 classes. World, Squares, Bug(Abstract), Ant(extended from Bug), Spider (extended from Bug).

World contains an 2d array of squares.

Squares contains an ArrayList of Bugs.

So I am wondering how do I convey the world to the bugs? If I pass by reference then I get into a terrible loop.

Share this post


Link to post
Share on other sites
[quote name='Shadowwoelf' timestamp='1298173783' post='4776553']
If I pass by reference then I get into a terrible loop.
[/quote]

Could you describe more of what the problem is? Typically you would have something like ant.update(world), and the ant would figure out what it wants to do then performs that action. Where are you running into a loop?

Share this post


Link to post
Share on other sites
[quote name='EricTheRed' timestamp='1298178793' post='4776569']
[quote name='Shadowwoelf' timestamp='1298173783' post='4776553']
If I pass by reference then I get into a terrible loop.
[/quote]

Could you describe more of what the problem is? Typically you would have something like ant.update(world), and the ant would figure out what it wants to do then performs that action. Where are you running into a loop?
[/quote]

Well this is how I have it so far.

World.update(turn, board, width) which calls Square.update(turn, board, width) which then calls Ant.update(turn, board, width).

Since this is Java I can't make it constant which prevents me from limiting the Ants interaction, unless I make all of the Square methods private and thus immutable...

I am just getting confused as to how in simulations and games how different classes work and update.

Share this post


Link to post
Share on other sites
[quote name='Shadowwoelf' timestamp='1298179266' post='4776573']
[quote name='EricTheRed' timestamp='1298178793' post='4776569']
[quote name='Shadowwoelf' timestamp='1298173783' post='4776553']
If I pass by reference then I get into a terrible loop.
[/quote]

Could you describe more of what the problem is? Typically you would have something like ant.update(world), and the ant would figure out what it wants to do then performs that action. Where are you running into a loop?
[/quote]

Well this is how I have it so far.

World.update(turn, board, width) which calls Square.update(turn, board, width) which then calls Ant.update(turn, board, width).

Since this is Java I can't make it constant which prevents me from limiting the Ants interaction, unless I make all of the Square methods private and thus immutable...

I am just getting confused as to how in simulations and games how different classes work and update.
[/quote]

What's so bad about this? Assuming World.update() has things to accomplish to change World, Square.update() has things to change Square, and Ant.update() changes Ant, it's just separated well.

If Square.update() does nothing but call the update method for each bug, then delete the update method from square and call the bug updates in World:

for..i...i<amount.of.squares...i++
for..j...j<squares.bugsarray.length...j++
{
squares[i].bugsarray[j].update(turn, board, width);
}

If it's about exposing a member of World to a Bug... you gotta pass a variable. Or make it global but globals should be avoided whenever possible.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this