Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

34
LINES

< > BotCompany Repo | #1022920 // AIStrategy

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (5838L/33K).

abstract sclass AIStrategy<A> implements Steppable {
  // user must set
  F1<A, Double> submit; // scoring function
  
  *() {}
  *(F1<A, Double> *submit) {}
  
  selfType setJudge(IF1<A, Number> judge) {
    submit = func(A a) -> double { judge.get(a).doubleValue() };
    this;
  }
  
  long round;
  new Best<A> best;
  bool verbose;
  event newBest(A guess, double score);
  
  void updateBest(A guess, double score) {
    if (best.put(guess, score))
      newBest(guess, score);
  }
  
  double submit(A guess) {
    if (guess == null) ret best.worstScore();
    double score = callF(submit, guess);
    updateBest(guess, score);
    ret score;
  }
  
  selfType lowerIsBetter(bool b) {
    best.lowerIsBetter(b);
    this;
  }
}

Author comment

Began life as a copy of #1018798

download  show line numbers  debug dex  old transpilations   

Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1022920
Snippet name: AIStrategy
Eternal ID of this version: #1022920/15
Text MD5: d644e46fab8a1b19788b68d8b279b796
Transpilation MD5: 1e7cb03abb3ac31f2182239052f7e86c
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-03-13 05:31:20
Source code size: 767 bytes / 34 lines
Pitched / IR pitched: No / No
Views / Downloads: 352 / 876
Version history: 14 change(s)
Referenced in: [show references]