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).

1  
// The "Maker & Taker" Game
2  
// (in which maker and taker gamble for the ball)
3  
4  
sclass MakerAndTakerGame {
5  
  ///////////////////////////////
6  
  //////// PLAYING FIELD ////////
7  
  ///////////////////////////////
8  
9  
  //////// Maker's output 
10  
  
11  
  Bool priceIsUp;          // null: It's round 1 and it's the takers turn. (Initial situation before game begins.)
12  
                           // true: Price has gone 1 step up since last round
13  
                           // false: Price has gone 1 step down
14  
                          
15  
  //////// Taker's output & score, plus time keeper (=rounds played)
16  
  
17  
  int takersCurrentBet;    // +1 to bet long, -1 to bet short, +2 to bet extra long etc, 0 to stop betting for now
18  
  int takersScore;         // Sum of taker's wins + losses
19  
  int roundsPlayed;        // How many rounds (a round is one take and one make) we had
20  
  
21  
  //////// Internal toggle for fun purposes
22  
  
23  
  bool takersTurn = true;  // Taker always starts
24  
  
25  
  //////// Game protocol
26  
  
27  
  new L<MakerAndTakerGame> protocol;
28  
  
29  
  ////////////////////////////
30  
  //////// MAKER CODE ////////
31  
  ////////////////////////////
32  
  
33  
  // This defines the crypto's movement over time.
34  
  // true = one step up, false = one step down.
35  
  // Multiple steps at once ("cell skips") are anomalies and are not supported here.
36  
  swappable bool nextCryptoMove() { fail("Put something here"); }
37  
  
38  
  void make {
39  
    priceIsUp = nextCryptoMove();
40  
    takersScore += takersCurrentBet*(priceIsUp ? 1 : -1);
41  
    ++roundsPlayed;
42  
    protocol.add((selfType) unstructure(print(structure(this))));
43  
    takersTurn = true;
44  
  }
45  
  
46  
  ////////////////////////////
47  
  //////// TAKER CODE ////////
48  
  ////////////////////////////
49  
  
50  
  // Taker's secret sauceeee!
51  
  //
52  
  // IOW, do strategy XYZ super-smart mega calculation stuff and set "takersCurrentBet" to a really smart value.
53  
  // 
54  
  // You can, but don't have to, make use of the value of priceIsUp.
55  
  // 
56  
  // If you're only watching or done betting, just say takersCurrentBet = 0.
57  
  
58  
  swappable void magicJuice {}
59  
  
60  
  void take {
61  
    magicJuice();
62  
    takersTurn = false;
63  
  }
64  
  
65  
  
66  
  // The rest is just some glue for gluing purposes.
67  
  
68  
  void step {
69  
    if (takersTurn) take(); else make();
70  
  }
71  
}

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