!7

!include #1007130 // AI Game Include

p {
  showBlunderWindow = false;
  pGame();
}

//////////////////////////////////////
// Test AIs. Just add your own here //
//////////////////////////////////////

AI > AI_BWImageCat {
  new BWImageCategorizer cat;
  new L<S> texts;
  static ImageSurface is;
  bool lax;
  float confidence;

  *() {
    cat.allowedDistance = 0.03f;
  }
  
  void go {
    BWImage img = autoCroppedBWImage(bwImage());
    if (lax) { // mode for users of this AI (e.g. AI Game 6.2)
      Pair<Int, Float> x = cat.locateLax(img);
      confidence = x.b;
      submit(get(texts, x.a));
      ret;
    }
    int i = cat.addImage(img);
    S guess = get(texts, i);
    S solution = submit(guess);
    if (nempty(solution) && empty(guess)) {
      listSet(texts, i, solution);
      bool first = is == null;
      is = showImage(is, shortClassName(this) + ": " + join(texts), mergeImagesHorizontally(cat.rgbImages()));
      if (first) {
        setFrameWidth(is, 600);
        moveToTopRightCorner(is);
      }
    }
  }
}

//////////////////
// PUZZLE MAKER //
//////////////////

static Puzzle makePuzzle() {
  S text = randomID(1);
  ret new Puzzle("Enter the lowercase letter you see:", addRandomSizedBorder(renderSourceCode_1(text)), text);
}