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

71
LINES

< > BotCompany Repo | #1036389 // MakerAndTakerGame - The "Maker & Taker" Game

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

Libraryless. Click here for Pure Java version (14348L/84K).

// The "Maker & Taker" Game
// (in which maker and taker gamble for the ball)

sclass MakerAndTakerGame {
  ///////////////////////////////
  //////// PLAYING FIELD ////////
  ///////////////////////////////

  //////// Maker's output 
  
  Bool priceIsUp;          // null: It's round 1 and it's the takers turn. (Initial situation before game begins.)
                           // true: Price has gone 1 step up since last round
                           // false: Price has gone 1 step down
                          
  //////// Taker's output & score, plus time keeper (=rounds played)
  
  int takersCurrentBet;    // +1 to bet long, -1 to bet short, +2 to bet extra long etc, 0 to stop betting for now
  int takersScore;         // Sum of taker's wins + losses
  int roundsPlayed;        // How many rounds (a round is one take and one make) we had
  
  //////// Internal toggle for fun purposes
  
  bool takersTurn = true;  // Taker always starts
  
  //////// Game protocol
  
  new L<MakerAndTakerGame> protocol;
  
  ////////////////////////////
  //////// MAKER CODE ////////
  ////////////////////////////
  
  // This defines the crypto's movement over time.
  // true = one step up, false = one step down.
  // Multiple steps at once ("cell skips") are anomalies and are not supported here.
  swappable bool nextCryptoMove() { fail("Put something here"); }
  
  void make {
    priceIsUp = nextCryptoMove();
    takersScore += takersCurrentBet*(priceIsUp ? 1 : -1);
    ++roundsPlayed;
    protocol.add((selfType) unstructure(print(structure(this))));
    takersTurn = true;
  }
  
  ////////////////////////////
  //////// TAKER CODE ////////
  ////////////////////////////
  
  // Taker's secret sauceeee!
  //
  // IOW, do strategy XYZ super-smart mega calculation stuff and set "takersCurrentBet" to a really smart value.
  // 
  // You can, but don't have to, make use of the value of priceIsUp.
  // 
  // If you're only watching or done betting, just say takersCurrentBet = 0.
  
  swappable void magicJuice {}
  
  void take {
    magicJuice();
    takersTurn = false;
  }
  
  
  // The rest is just some glue for gluing purposes.
  
  void step {
    if (takersTurn) take(); else make();
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): elmgxqgtpvxh, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1036389
Snippet name: MakerAndTakerGame - The "Maker & Taker" Game
Eternal ID of this version: #1036389/30
Text MD5: ee2dbb4e9e516b295d3d3dddaaa31a3b
Transpilation MD5: 2b52f702134eb4e5cfcc7236f9b10322
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-12-08 01:41:14
Source code size: 2290 bytes / 71 lines
Pitched / IR pitched: No / No
Views / Downloads: 163 / 337
Version history: 29 change(s)
Referenced in: #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167)