I'm using ECJ with Java. I have an army of individuals who I all want to have the same brain.
Basically, I'd like to evolve the brains using GP. I want things like "if-on-enemy-territory
" and "if-sense-target
" for if statements and "go-home
" or "move-randomly
" or "shoot
" for terminals.
However, these statements need to be full executable Java code. How can I do this with ECJ?
FOR EXAMPLE:
I wish to have a terminal named "moveRandom
". If I were to code this within my soldier class, it would look like:
private void moveRandomly(SoldierWorld world)
{
//..snip.
int newX = (int)(this.getLocation().x + speed * Math.cos(this.getDirection() * Math.PI / 180.0));
int newY = (int)(this.getLocation().y - speed * Math.sin(this.getDirection() * Math.PI / 180.0));
Point newPoint = new Point(newX, newY);
this.setLocation(newPoint);
}
Now how can I make a terminal that will perform this code?