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)

1  
sclass AIStrategy_Racer_RandomWithVary<A> extends AIStrategy<A> {
2  
  // user must set
3  
  F0<A> random;
4  
  F1<A> vary;
5  
6  
  // user can set
7  
  int discardEvery = 5000;
8  
  
9  
  // internal
10  
  AIStrategy_RandomWithVariation<A> leader, overtaker;
11  
  new Best<A> leadersBest;
12  
  int roundsSinceChange;
13  
14  
  public bool step() { go(); false; }
15  
  
16  
  AIStrategy_RandomWithVariation newAI() {
17  
    ret copyFields(this, new AIStrategy_RandomWithVariation, 'random, 'vary);
18  
  }
19  
  
20  
  void go {
21  
    if (tossACoin()) {
22  
      if (leader == null) leader = newAI();
23  
      A guess = leader.guess();
24  
      if (guess == null) ret;
25  
      double score = submit(guess);
26  
      leader.updateBest(guess, score);
27  
      leadersBest.put(guess, score);
28  
    } else {
29  
      if (overtaker == null) overtaker = newAI();
30  
      A guess = overtaker.guess();
31  
      if (guess == null) ret;
32  
      double score = submit(guess);
33  
      overtaker.updateBest(guess, score);
34  
      if (score > leadersBest.score()) {
35  
        // displace leader!
36  
        if (verbose)
37  
          print("Overtake at " + formatScore(overtaker.best.score()) + " vs " + formatScore(leadersBest.score()));
38  
        leader = overtaker;
39  
        overtaker = null;
40  
        roundsSinceChange = 0;
41  
      } else if (roundsSinceChange++ >= discardEvery) {
42  
        // make new overtaker
43  
        if (verbose)
44  
          print("Discarding overtaker at " + formatScore(overtaker.best.score()) + " vs " + formatScore(leadersBest.score()));
45  
        overtaker = null;
46  
        roundsSinceChange = 0;
47  
      }
48  
    }
49  
  }
50  
}

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: 355 / 886
Version history: 7 change(s)
Referenced in: [show references]