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

50
LINES

< > BotCompany Repo | #1019838 // AIStrategy_Racer_RandomWithVary - Racer AI based on RandomWithVariation

JavaX fragment (include)

sclass AIStrategy_Racer_RandomWithVary<A> extends AIStrategy<A> {
  // user must set
  F0<A> random;
  F1<A> vary;

  // user can set
  int discardEvery = 5000;
  
  // internal
  AIStrategy_RandomWithVariation<A> leader, overtaker;
  new Best<A> leadersBest;
  int roundsSinceChange;

  public bool step() { go(); false; }
  
  AIStrategy_RandomWithVariation newAI() {
    ret copyFields(this, new AIStrategy_RandomWithVariation, 'random, 'vary);
  }
  
  void go {
    if (tossACoin()) {
      if (leader == null) leader = newAI();
      A guess = leader.guess();
      if (guess == null) ret;
      double score = submit(guess);
      leader.updateBest(guess, score);
      leadersBest.put(guess, score);
    } else {
      if (overtaker == null) overtaker = newAI();
      A guess = overtaker.guess();
      if (guess == null) ret;
      double score = submit(guess);
      overtaker.updateBest(guess, score);
      if (score > leadersBest.score()) {
        // displace leader!
        if (verbose)
          print("Overtake at " + formatScore(overtaker.best.score()) + " vs " + formatScore(leadersBest.score()));
        leader = overtaker;
        overtaker = null;
        roundsSinceChange = 0;
      } else if (roundsSinceChange++ >= discardEvery) {
        // make new overtaker
        if (verbose)
          print("Discarding overtaker at " + formatScore(overtaker.best.score()) + " vs " + formatScore(leadersBest.score()));
        overtaker = null;
        roundsSinceChange = 0;
      }
    }
  }
}

Author comment

Began life as a copy of #1018798

download  show line numbers  debug dex  old transpilations   

Travelled to 9 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1019838
Snippet name: AIStrategy_Racer_RandomWithVary - Racer AI based on RandomWithVariation
Eternal ID of this version: #1019838/8
Text MD5: 7c442f7f67cd508d5452a0ed25a92a51
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-04-14 21:56:09
Source code size: 1563 bytes / 50 lines
Pitched / IR pitched: No / No
Views / Downloads: 281 / 805
Version history: 7 change(s)
Referenced in: [show references]