// has a rectangular window (visionW*visionH) // walking range per frame is a circle with radius "range" sclass G22Walker { int range; // how far we can walk in each frame double roundingPolicy = .9; // for making the range circle (between 0 and 1) int visionW, visionH; // window rectangle size (should be odd) Pt position; // current position (center), not null bool stuck; // can neither stay nor move anywhere for some reason int guessWork; // how many "optimal" new positions we chose from void move(BWImage image) { stuck = false; guessWork = 0; // How far can I move until I hit the image's borders Rect movement1 = rectFromPoints(visionW/2, visionH/2, image.getWidth()-(visionW+1)/2, (visionH+1)/2); // How far can I walk in one frame Rect movement2 = rectAroundPt(position, range*2+1); Rect movement = intersectRects(movement1, movement2); if (empty(movement)) ret with set stuck; printVars(+movement, +movement1, +movement2); Rect r = window_uncropped(); new MultiBest bestPositions; for (Pt newPos : allPointsInRect_virtual(movement)) bestPositions.put(newPos, scorePosition(newPos)); var best = bestPositions!; guessWork = l(best); position = random(best); } Rect window_uncropped(Pt center default position) { ret rectAroundPt(center, visionW, visionH); } }