I have a program I am in the middle of writing that is meant to simulate bugs finding food. In brief i have a grid (a world) in which there are bugs, obstacles and food of different energy values. Each bug will look in every direction, get the closest food within its "seeing distance" and move one cell towards it otherwise moving in a random direction.
I have 3 clases:
ABug
AWorld
Main
ABug and AWorld obviously contain all the methods to populate a grid with food and obstacles, sense food, move a bug etc, and the Main class is the controller that creates a world, creates a number of bugs based on user input and adds them to the world.
My question is:
Is there a better way to make a bug know about a world it is in whilst a world also knows about the bugs in it other than passing a reference of the world into every function that needs it inside a bug?
I currently have an arraylist of bugs inside the world class and then pass the 2D array into the functions that need it in the bug class.
Sorry for the long explanation, wasnt sure how much detail people would want so I just put it all :)
Thanks for any suggestions