!7 // too brave // rewrite Submission = BackgroundPlus. static double thresholdPercent = 0.1; // quit when less than 0.1% improvement (absolute) static int thresholdRounds = 5000; // ...in the last 5000 rounds p-experiment-tt { S imageID = #1101217; Pair p = imageToCode(imageID, 1); Submission s = cast unstruct(p.a); printAsciiHeading("RESULT"); printIndent(javaTokWordWrap(80, "The image shows " + thingToText(getSingleton(s.things)) + " on a " + ai_rgbToEnglish(s.background) + " background" + " (accuracy: " + formatScore(p.b) + ")")); double angle = sortLineByY((LineWithColor) first(s.things)).angle(); showImage("Rotated.", rotateImageInSameSize(img.getBufferedImage(), -angle)); } sS thingToText(O o) { if (o instanceof LineWithColor) { LineWithColor l = cast o; ret "a " + ai_rgbToEnglish(l.color) + ", " + l.width + " pixel wide line with angle " + iround(mod(l.angle(), 180)) + "°"; } ret "an unknown object"; } // returns code, score static Pair imageToCode(S imageID, int lines) { main.lines = lines; showTheImage = showRepro = false; loadImageSnippet(imageID); new AI_Racer ai; new L scores; Game game = null; double score = 0; print("Calculating...\n"); while licensed { game = scoreAI(ai); score = game.percentScore(); scores.add(score); print(l(scores)*rounds + " rounds. Score: " + formatScore(score)); int lookback = thresholdRounds/rounds; int i = l(scores)-lookback-1; if (i >= 0) //if (score < max(0.01, scores.get(i))*(1+thresholdPercent/100)) { if (score < scores.get(i)+thresholdPercent) { print("No more improvement, exiting after " + l(scores)*rounds + " rounds"); break; } } S code = game.bestCode(); printAsciiHeading("Best code (" + lUtf8(code) + " bytes)"); printIndent(javaTokWordWrap(80, code)); ret pair(code, score); } static int lines = 8; !include #1015048 // AI Game & API sclass Submission extends BackgroundPlus { *() {} *(BackgroundPlus b) { copyFields(b, this); check(); } void check { assertEqualsQuick(main.lines, l(things)); } } ////////////////// // PUZZLE MAKER // ////////////////// sS lastLetter; static RGBImage makeImage() { lastLetter = randomUpperCaseLetterNotEqualTo(lastLetter); ret randomLetterImage(lastLetter, #1004568, 100); } /////////////// // RENDERERS // /////////////// static BufferedImage renderImage1(Submission s) { ret renderRenderable(w, h, s); } static BufferedImage renderWithHints(Submission s) { ret renderRenderable_withHints(w, h, s); } ////////////////////////////////////// // Test AIs. Just add your own here // ////////////////////////////////////// AI_Random_abstract > AI_Random { Submission guess() { ret Submission(randomBackgroundPlusLines(w, h, lines)); } } AI_RandomWithVariation_abstract > AI_RandomWithVariation { AI_RandomWithVariation() { super(new AI_Random); } Submission vary(Submission s) { ret varyBackgroundPlusLines(s, w, h); } } !include #1014957 // AI_Racer