public void fillPath(DirectionRobot robot, int endX, int endY) {
        int width = robot.getX() - endX;
        int height = robot.getY() - endY;
        //todo refactor logic
        //select direction
        AbstractRobot.Direction abstractDirection = robot.getDirection();
        System.out.println("first!");
        if (width < 0) {
            //start on the left side
            switch (abstractDirection) {
                case UP: {
                    this.addComand(new RotateRightComand(robot));
                }
                break;
                case LEFT: {
                    this.addComand(new RotateRightComand(robot));
                    this.addComand(new RotateRightComand(robot));
                }
                break;
                case DOWN: {
                    this.addComand(new RotateLeftComand(robot));
                }
                break;
            }
            abstractDirection = AbstractRobot.Direction.RIGHT;
        }
        if (width > 0) {
            //start on the right side
            switch (abstractDirection) {
                case UP: {
                    this.addComand(new RotateLeftComand(robot));
                }
                break;
                case DOWN: {
                    this.addComand(new RotateRightComand(robot));
                }
                break;
                case RIGHT: {
                    this.addComand(new RotateLeftComand(robot));
                    this.addComand(new RotateLeftComand(robot));
                }
                break;
            }
            abstractDirection = AbstractRobot.Direction.LEFT;
        }
        //move X
        System.out.println(width);
        for (int i = 0; i < abs(width); i++) {
            this.addComand(new MoveForwardComand(robot));
        }
        //select direction again
        if (height < 0) {
            //if start above end
            switch (abstractDirection) {
                case LEFT: {
                    this.addComand(new RotateLeftComand(robot));
                }
                break;
                case RIGHT: {
                    this.addComand(new RotateRightComand(robot));
                }
                break;
            }
//            abstractDirection = AbstractRobot.Direction.DOWN;
        }
        if (height > 0) {
            //if start below end
            switch (abstractDirection) {
                case LEFT: {
                    this.addComand(new RotateRightComand(robot));
                }
                break;
                case RIGHT: {
                    this.addComand(new RotateLeftComand(robot)); //done
                }
                break;
            }
//            abstractDirection = AbstractRobot.Direction.UP;
        }
        //move Y
        System.out.println(height);
        for (int i = 0; i < abs(height); i++) {
            this.addComand(new MoveForwardComand(robot));
        }
    }
public void fillPath(DirectionRobot robot, int endX, int endY) {
        int width = robot.getX() - endX;
        int height = robot.getY() - endY;
       
       
        AbstractRobot.Direction abstractDirection = robot.getDirection();
        System.out.println("first!");
        if (width < 0) {
           
            switch (abstractDirection) {
                case UP: {
                    this.addComand(new RotateRightComand(robot));
                }
                break;
                case LEFT: {
                    this.addComand(new RotateRightComand(robot));
                    this.addComand(new RotateRightComand(robot));
                }
                break;
                case DOWN: {
                    this.addComand(new RotateLeftComand(robot));
                }
                break;
            }
            abstractDirection = AbstractRobot.Direction.RIGHT;
        }
        if (width > 0) {
           
            switch (abstractDirection) {
                case UP: {
                    this.addComand(new RotateLeftComand(robot));
                }
                break;
                case DOWN: {
                    this.addComand(new RotateRightComand(robot));
                }
                break;
                case RIGHT: {
                    this.addComand(new RotateLeftComand(robot));
                    this.addComand(new RotateLeftComand(robot));
                }
                break;
            }
            abstractDirection = AbstractRobot.Direction.LEFT;
        }
       
        System.out.println(width);
        for (int i = 0; i < abs(width); i++) {
            this.addComand(new MoveForwardComand(robot));
        }
       
        if (height < 0) {
           
            switch (abstractDirection) {
                case LEFT: {
                    this.addComand(new RotateLeftComand(robot));
                }
                break;
                case RIGHT: {
                    this.addComand(new RotateRightComand(robot));
                }
                break;
            }
        }
        if (height > 0) {
           
            switch (abstractDirection) {
                case LEFT: {
                    this.addComand(new RotateRightComand(robot));
                }
                break;
                case RIGHT: {
                    this.addComand(new RotateLeftComand(robot));
                }
                break;
            }
        }
       
        System.out.println(height);
        for (int i = 0; i < abs(height); i++) {
            this.addComand(new MoveForwardComand(robot));
        }
    }
public void fillpath(directionrobot robot, int endx, int endy) { int width = robot.getx() - endx; int height = robot.gety() - endy; abstractrobot.direction abstractdirection = robot.getdirection(); system.out.println("first!"); if (width < 0) { switch (abstractdirection) { case up: { this.addcomand(new rotaterightcomand(robot)); } break; case left: { this.addcomand(new rotaterightcomand(robot)); this.addcomand(new rotaterightcomand(robot)); } break; case down: { this.addcomand(new rotateleftcomand(robot)); } break; } abstractdirection = abstractrobot.direction.right; } if (width > 0) { switch (abstractdirection) { case up: { this.addcomand(new rotateleftcomand(robot)); } break; case down: { this.addcomand(new rotaterightcomand(robot)); } break; case right: { this.addcomand(new rotateleftcomand(robot)); this.addcomand(new rotateleftcomand(robot)); } break; } abstractdirection = abstractrobot.direction.left; } system.out.println(width); for (int i = 0; i < abs(width); i++) { this.addcomand(new moveforwardcomand(robot)); } if (height < 0) { switch (abstractdirection) { case left: { this.addcomand(new rotateleftcomand(robot)); } break; case right: { this.addcomand(new rotaterightcomand(robot)); } break; } } if (height > 0) { switch (abstractdirection) { case left: { this.addcomand(new rotaterightcomand(robot)); } break; case right: { this.addcomand(new rotateleftcomand(robot)); } break; } } system.out.println(height); for (int i = 0; i < abs(height); i++) { this.addcomand(new moveforwardcomand(robot)); } }