Kara walks from left to right and from right to left, alternatively, and "inverts" the current row of the image. The main program is the following:
boolean walkingLeft2Right = true; while (!( kara.treeFront() && (kara.treeLeft() || kara.treeRight()) )) { if (walkingLeft2Right) { left2right(); } else { right2left(); } walkingLeft2Right = !walkingLeft2Right; }