!7 !include #1006891 // Click AI Include static int spacing = 10; // space between the two images p { w = h = 150; imageZoom = 1; pGame(); } extend AI { Rect leftRect() { ret main.leftRect(image); } Rect rightRect() { ret main.rightRect(image); } L clickLeft() { ret submit(leftRect()); } L clickRight() { ret submit(rightRect()); } L clickLeftIf(bool b) { ret b ? clickLeft() : clickRight(); } L clickRightIf(bool b) { ret b ? clickRight() : clickLeft(); } RGBImage leftImage() { ret image.clip(leftRect()); } RGBImage rightImage() { ret image.clip(rightRect()); } } static int singleImageWidth(RGBImage img) { ret (img.w()-spacing)/2; } static Rect leftRect(RGBImage img) { int iw = singleImageWidth(img); ret new Rect(0, 0, iw, h); } static Rect rightRect(RGBImage img) { int iw = singleImageWidth(img); ret new Rect(iw+spacing, 0, iw, h); } ////////////////////////////////////// // Test AIs. Just add your own here // ////////////////////////////////////// AI > ClickOnBrighterImage { void go { clickLeftIf(rgbAverageBrightness(leftImage()) > rgbAverageBrightness(rightImage())); } } ////////////////// // PUZZLE MAKER // ////////////////// static Puzzle makePuzzle() { S instruction = "Click on the brighter image"; RGBImage img = rgbImage(0xeef3e6, w*2+spacing, h); double l = random(10)/10.0, r = random(10)/10.0; Rect lr = leftRect(img), rr = rightRect(img); rgbFill(img, lr, new RGB(l)); rgbFill(img, rr, new RGB(r)); L solution = l > r ? ll(lr) : l == r ? ll(lr, rr) : ll(rr); ret new Puzzle(instruction, img, solution); }