Passing world data to AI entites

Started by
2 comments, last by slynk 13 years, 1 month ago
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.
Advertisement

If I pass by reference then I get into a terrible loop.


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 name='Shadowwoelf' timestamp='1298173783' post='4776553']
If I pass by reference then I get into a terrible loop.


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 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.


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.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.

This topic is closed to new replies.

Advertisement