I need to create application which would simulate predator-prey relationship. I can use some framework( ex. repast), but I am wondering about writing application from scratch.
The biggest problem for me is way of representing map with food sources, predators and prey.
Very simple model
I was thinking about two dimensional array of lets say Cell.
Cell would have boolean fields predator, food and prey and corresponded setters and getters. Predators and prey would wander around and observe cells in specific radius( range of sight).
If predator spots prey it moves toward it. If prey spots predator it moves in opposite direction. Not disturbed prey is wandering until it find source of food.
Moving/Wandering
In this example Animal is goes to Destination point.
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
0 |_|_|_|_|_|_| |_|_|_|_|_|_| |_|_|_|_|_|_|
1 |_|A|_|_|_|_| |_|_|_|_|_|_| |_|_|_|_|_|_|
2 |_|_|x|x|_|_| -> |_|_|A|x|_|_| . . . |_|_|_|_|_|_|
3 |_|_|_|_|x|_| |_|_|_|_|x|_| |_|_|_|_|_|_|
4 |_|_|_|_|_|D| |_|_|_|_|_|D| |_|_|_|_|_|D|
0 1 2 3 4 5
This walk consumes 5 moves and Animals will have some specific speed( 2 moves/second). In every move one Cell is setting predator to false, and another is setting it to true.
With programming it will looks like this( of course there would be method moveTo(x,y)):
Animal animal = new Animal(1,1);
animal.setPosition(2,2);
animal.setPosition(3,2);
animal.setPosition(4,3);
animal.setPosition(5,4);
Observing
Sample predator observation with max range of 3. I have marked observed cells by x. Observation is just simple checking if getPrey() returns true:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
0 |_|_|_|_|_|_|_| |_|_|_|_|_|_|_| |_|_|_|x|_|_|_|
1 |_|_|_|_|_|_|_| |_|_|_|x|_|_|_| |_|x|x|x|x|x|_|
2 |_|_|_|x|_|_|_| |_|_|x|x|x|_|_| |_|x|x|x|x|x|_|
3 |_|_|x|A|x|_|_| -> |_|x|x|A|x|x|_| -> |x|x|x|A|x|x|x|
4 |_|_|_|x|_|_|_| |_|_|x|x|x|_|_| |_|x|x|x|x|x|_|
5 |_|_|_|_|_|_|_| |_|_|_|x|_|_|_| |_|x|x|x|x|x|_|
6 |_|_|_|_|_|_|_| |_|_|_|_|_|_|_| |_|_|_|x|_|_|_|
0 1 2 3 4 5 6
The best way would be observing area around with every step( move) but it seems like a lot of computations( checking conditions). Am I correct at this point?
Is this good approach to hold most of data in two dimensional array? I will appreciate any constructive answers.
This is only sample example. In future I would like to add reproduction, mood, inteligence, etc.
Thanks.
EDIT
I forgot to mention scale of the problem.
I think that number of Predators and Prey would be less than 100. But it's only guess. Size of map would be 500x500 or even smaller.