Warning: session_start(): open(/var/lib/php/sessions/sess_s9laqethshu4mhpba120g56ovd, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
// has a rectangular window (visionW*visionH)
// walking range per frame is a circle with radius "range"
sclass G22Walker {
int range = 1; // how far we can walk in each frame
double roundingPolicy = .9; // for making the range circle (between 0 and 1)
int visionW = 3, visionH = 3; // window rectangle size (both should be odd)
Pt position; // current position (center), not null
byte[] rememberedImage; // size visionW*visionH
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);
if (rememberedImage == null)
ret with rememberImage(image);
Rect r = window_uncropped();
new MultiBest bestPositions;
int mx1 = movement.x1(), mx2 = movement.x2();
int my1 = movement.y1(), my2 = movement.y2();
for (int y = my1; y < my2; y++)
for (int x = mx1; x < mx2; x++) {
var newPos = pt(x, y);
bestPositions.put(newPos, scorePosition(newPos, image));
}
var best = bestPositions!;
guessWork = l(best);
position = random(best);
// It's actually a question how often we grab a fresh image.
// For now, every time.
rememberImage(image);
}
// only works when we already have a rememberedImage
double scorePosition(Pt pos, BWImage image) {
int vx = pos.x-visionW, vy = pos.y-visionH, i = 0;
int diff = 0;
for y to visionH:
for x to visionW:
diff += abs(ubyteToInt(rememberedImage[i++])-image.getInt(vx+x, vy+y));
ret -diff;
}
void rememberImage(BWImage image) {
if (rememberedImage == null)
rememberedImage = new byte[visionW*visionH];
int vx = visionX1(), vy = visionY1(), i = 0;
for y to visionH:
for x to visionW:
rememberedImage[i++] = image.getByte(vx+x, vy+y);
}
int visionX1() { ret position.x-visionW; }
int visionY1() { ret position.y-visionH; }
Rect window_uncropped(Pt center default position) {
ret rectAroundPt(center, visionW, visionH);
}
}