sclass ExternalTextAI { O ai; *(S progID) { S code = loadProgramTextFile(progID, "winner.text"); if (empty(code)) fail("No winner in program, please run it first: " + progID); O program = hotwire(progID); ai = unstructureInRealm(code, program); } sclass Game { S submitted; S submit(S text) { submitted = text; null; } } S call(BufferedImage img) { new Game game; pcall { O rgbImage = nuForeignObject(ai, "main$RGBImage", img); O exportedGame = proxy(_getClass(ai, "main$GameForAI"), game); set(ai, "game", exportedGame); set(ai, "image", rgbImage); callOpt(ai, "go"); if (game.submitted != null) print("AI " + shortClassName(ai) + " returned: " + game.submitted); } ret game.submitted; } } static ExternalTextAI loadWinnerTextAI(S progID) { ret new ExternalTextAI(progID); }