Java Game Development - robot virtual world- Finite State Machine

hey, i am looking some advise on buidling a Finite State Machine using java. I im about to start a project where i must create a "virtual robot world" which consists of a number of robot agents (simple filled rectangles). Each of these agent will have a number of states such as stopped, creeping, fleeing etc etc and there states will be triggered by actions of events by other agents. For exmaple for my first stage i want the following

2 agents, the prey and the predator. The predator moves towards the prey

in short spurts. Between movements the predator simply pauses. If the prey

does not move the predator will ultimately end up attacking the prey.

However, if at any stage the prey moves towards the predator the predator

will pause. If the prey does not move closer after a period, then the

predator will continue to move towards the prey. However, if the prey

moves towards the predator again the predator will pause again. Ultimately,

if the predator's number of pauses increases to a certain value, then if the prey moves towards the predator the predator will flee.

I would appreciate any advice on setting up a simple FSM in java that would satisfy the above states and actions

Cheers!

[1268 byte] By [dubaa] at [2007-11-26 23:06:57]
# 1

I would create an abstract class called "Entity" and have Prey and Predator extend it.

a couple methods of Entity might be something like:

void takeTurn(Environment e);

int getState();

where an Environment is a 2d array of squares/tiles which may or may not contain entities.

There would be some static variables in the Entity class like:

public static final int WANDERING = 0, SLEEPING = 1, STALKING = 2, etc...

So you have a timer which calls takeTurn(e) on all of your entities like every second or so. When the Prey's turn comes along, you can make it have a random chance of detecting the predator where the chance of detection is inversely proportional to the distance. You can also do other things like have the predator call getState() on the prey. If the prey is SLEEPING, then the predator would definitely move foward.

I hope this helps you.

Nethera at 2007-7-10 14:00:55 > top of Java-index,Other Topics,Java Game Development...