!7 static int lineWidth = 18; static int lines = 4; !include #1006931 // AI Game & API p { newImageText = "New Letter!"; pGame(); } sclass Line { Pt a, b; *() {} *(Pt *a, Pt *b) {} } sclass Submission { new L lines; *() {} *(Line... lines) { this.lines = asList(lines); } *(L *lines) {} } ////////////////// // PUZZLE MAKER // ////////////////// static RGBImage makeImage() { //ret loadRGBImage(/*#1006930*/#1006944); S letter = "" + randomCharBetween('A', 'Z'); ret new RGBImage(renderText(#1004568, 100, letter)); } //////////////// // FORM MAKER // //////////////// static JComponent makeTheForm(final GameForAI game) { null; // TODO } static Pt ptFromForm(JTextField x, JTextField y) { ret new Pt(intFromTextField(x), intFromTextField(y)); } static Pt ptFromForm(JSpinner x, JSpinner y) { ret new Pt(intFromSpinner(x), intFromSpinner(y)); } ////////////// // RENDERER // ////////////// static RGBImage renderImage(Submission s) { BufferedImage bi = newBufferedImage(w, h, Color.white); for (Line l : s.lines) drawRoundEdgeLine(bi, l.a, l.b, Color.black, lineWidth); ret new RGBImage(bi); } ////////////////////////////////////// // Test AIs. Just add your own here // ////////////////////////////////////// AI > AIRandom { new Best best; Line randomLine() { ret new Line(randomPoint(), randomPoint()); } Pt randomPoint() { ret main.randomPoint(image()); } void go { //print("Round: " + round()); if (round() == 1 && best.has()) submit(best.get()); else { Submission guess = guess(); best.put(guess, submit(guess); } } Submission guess() { ret new Submission(produceN(func { randomLine() }, lines)); } } AIRandom > AIRandomWithVariation { int n; Submission guess() { if (odd(n++) && best.has()) ret vary(best.get()); else ret super.guess(); } Submission vary(Submission s) { s = cloneThroughStructure(s); varyLine(random(s.lines)); ret s; } void varyLine(Line l) { if (tossACoin()) l.a = varyPoint(l.a); else l.b = varyPoint(l.b); } Pt varyPoint(Pt p) { ret tossACoin() ? randomPoint() : varyPoint(p, 10); } Pt varyPoint(Pt p, int range) { range = max(range, 1); ret new Pt( random(p.x-range, p.x+range+1), random(p.y-range, p.y+range+1)); } }