I have no experience here, but my first idea would be the use of the method "getStringBounds" that gives you a Rectangle2D that you can use together with a left margin, to calculate the width of a text in pixels.
The robot can move up if there is nothing above it, or if there is a block above, when that block can move up. And when can a block move up? Do I smell recursion? Se the code I gave. I refactored it while pasting, never a good thing to do, but you may get an idea.
Liutauras Vilda wrote:Resolved part 1, but part 2 looks nasty at this point.
moving left and right are no problem, I showed the routine that I have, but moving up and down is not so easy. I used a pretty laborious method in my Blok-class (int row, int cl // column left, int cr // column right)
and I call this method from a method in my robot-class
But then there is a small chance that one or more of these spoil your christmas tree. My more than 8000 forward steps took just a fraction of a second, so backwards is fast enough.
It returns an empty list if there are no bloks on the left side. But a blok.moveLeft does nothing if the blok cannot move. That list is sorted, so the bloks can be moved starting from the left.
This part B took me a midday and part of my nightrest.... I was expecting to see the start of the christmastree appearing within the first 30 lines, but whatever I tried to look for: nope. Only just printing out the full lot. Miserable exercise.