Help required with Java Bot "ShootCommand"


I am a Java novice and I am struggling with the “ShootCommand” and the related “Direction” Enum that is part of the Java Starter Bot. Actually more the ResolveDirection code that is part of the Starter Bot…

I am hoping some kindhearted soul will help!

Basically I am calling the same piece of code in the Java Starter Bot …just in a different context.

The code complies, but when I run it through the game runner I get…


//Determine which direction, I need to fire in//
// This code calls the resolveDirection class below, providing currentWorm pos and Target Cell Pos…basically I want to determine which fire direction the Target Cell is//

Direction direction = resolveDirection(currentWorm.position,TargetPosition);
return new ShootCommand(direction);

private Direction resolveDirection(Position a, Position b) {
StringBuilder builder = new StringBuilder();

    int verticalComponent = b.y - a.y;
    int horizontalComponent = b.x - a.x;

    if (verticalComponent < 0) {
    } else if (verticalComponent > 0) {

    if (horizontalComponent < 0) {
    } else if (horizontalComponent > 0) {

    return Direction.valueOf(builder.toString());



What if both is zero?

Target cell and current cell will never be the same…so I dont think you will ever get that situation? Unless I am not following…

Hi @Grizzly21,

Have you changed the logic for the direction resolution in your bot?

1 Like

Thanks All, I came right. It is now working!

1 Like