!7 !include #1006891 // AI Game & API p { instruction = "Close the window:"; pGame(); } ////////////////////////////////////// // Test AIs. Just add your own here // ////////////////////////////////////// AI > ClickAnyBLOB { static ImageSurface is; void go { L blobs = segment(image); is = showImage(is, "BLOBS", rgbMarkedRects(image, blobs)); submit(random(blobs)); } } AI > MemorizeBLOB { RGBImage blobImage; static ImageSurface is; void go { // guess L myRects = segment(image); Rect guess = null; if (blobImage != null) guess = rgbFindMostSimilarClip(image, blobImage, myRects, 0); // submit Rect solution = first(submit(guess)); // learn if (blobImage == null) { solution = autoCropOfRGBImage_blackBG(image, solution); Rect mine = smallestRectContaining(myRects, centerOfRect(solution)); if (mine != null) { blobImage = image.clip(mine); is = showZoomedImage(is, "Memorized BLOB", blobImage); } } } } static L segment(RGBImage img) { ret autoSegment_blackBG(new BWImage(img), 3); // 2 is too small } ////////////////// // PUZZLE MAKER // ////////////////// static L mainImages; static Puzzle makePuzzle() { if (mainImages == null) mainImages = loadImages(#1006879, #1006889); L solutions = ll( pointsRect(522, 162, 540, 179), pointsRect(449, 70, 466, 84)); // select image int i = random(l(mainImages)); RGBImage mainImage = mainImages.get(i); Rect solution = solutions.get(i); // select random portion Rect clip = selectRandomPartContaining(mainImage, solution, w, h); RGBImage img = mainImage.clip(clip); solution = translateRect(solution, -clip.x, -clip.y); // return puzzle ret new Puzzle(img, ll(solution)); }