Author Topic: BitShares Dice Game Smart Contract  (Read 6505 times)

0 Members and 1 Guest are viewing this topic.

Offline iamredbar

Should have posted the code sooner, sorry all. Will do this as soon as I fully wake up! It is using the Randint library in python. Using the head block number and users guess as the seed.

Offline clockwork

  • Committee member
  • Sr. Member
  • *
  • Posts: 376
    • View Profile
  • BitShares: clockwork

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc

Offline sschiessl

  • Administrator
  • Hero Member
  • *****
  • Posts: 662
    • View Profile
  • BitShares: sschiessl
Code: [Select]
If profit(this_month) < limited_only_by_my_greed
  return user_guess + random
else
  return random

 ;) jk, no clue. Of course important question!

Offline pc

  • Hero Member
  • *****
  • Posts: 1530
    • View Profile
    • Bitcoin - Perspektive oder Risiko?
  • BitShares: cyrano
The interesting part is, of course, how does the contract roll a number?
Bitcoin - Perspektive oder Risiko? ISBN 978-3-8442-6568-2 http://bitcoin.quisquis.de

Offline iamredbar

Hello everyone!

I have created a simple dice game on BitShares. The game will randomly roll a number between 1-100. You get to guess what the roll will be under. The way that this contract works (currently) is you transfer between 1-5 BTS to the account 'bts-dice-game' and in the memo you pick what the game dice will roll under. It does not count if you roll the same number as you guessed, it has to be less.

Based on the number that you think it will roll, the ratio of return changes (complete ratios are at the bottom of this post).

RULES:
- Do not bid more than 5 BTS (I am using my personal funds to run this, I do not have that much liquidity  :) )
- You can only guess your roll with the numbers 2-96 89 (1 is the least you can roll, after 96 89 the return is too minimal)
- Make sure that you send a memo when transferring to this address. If you do not, you will break it and ruin the fun for others while I am away from my computer.
- PLEASE do not try to break this. There are plenty of ways to do that (sending a memo that isn't only the roll you guess, etc...). These are going to be fixed, but I wanted to get this out to everyone as soon as I could. Fixed. If I determine you sent something that shouldn't be sent in the memo, I will not return funds to you. Period.
- A GUI is planned, but not right now. I want to improve the code before I move to that.

Example: I think that the game will roll under 75 when I want to play. I want to bet 2 BTS. In my wallet i will send 'bts-dice-game' 2 BTS and in the memo ONLY write what I want to roll under, which is 75. No quotes, just the number. The game rolls 80. This means that I would win 1.331x what I bet, which is 2.662 BTS. When 'bts-dice-game' sends me my winnings, it will have a memo with what you guessed, the roll, and how much you won. The same goes for if you lose, it states what you thought the roll would be and what it was.

RETURN RATIOS: (when you pick them)
Code: [Select]
ratios={
    2: 98.5,
    3: 49.25,
    4: 32.833,
    5: 24.625,
    6: 19.7,
    7: 16.416,
    8: 14.071,
    9: 12.312,
    10: 10.944,
    11: 9.85,
    12: 8.954,
    13: 8.208,
    14: 7.576,
    15: 7.035,
    16: 6.566,
    17: 6.156,
    18: 5.794,
    19: 5.472,
    20: 5.184,
    21: 4.925,
    22: 4.69,
    23: 4.477,
    24: 4.282,
    25: 4.104,
    26: 3.94,
    27: 3.788,
    28: 3.648,
    29: 3.517,
    30: 3.396,
    31: 3.283,
    32: 3.177,
    33: 3.078,
    34: 2.984,
    35: 2.897,
    36: 2.814,
    37: 2.736,
    38: 2.662,
    39: 2.592,
    40: 2.525,
    41: 2.462,
    42: 2.402,
    43: 2.345,
    44: 2.29,
    45: 2.238,
    46: 2.188,
    47: 2.141,
    48: 2.095,
    49: 2.052,
    50: 2.01,
    51: 1.97,
    52: 1.931,
    53: 1.894,
    54: 1.858,
    55: 1.824,
    56: 1.79,
    57: 1.758,
    58: 1.728,
    59: 1.698,
    60: 1.669,
    61: 1.641,
    62: 1.614,
    63: 1.588,
    64: 1.563,
    65: 1.539,
    66: 1.515,
    67: 1.492,
    68: 1.47,
    69: 1.448,
    70: 1.427,
    71: 1.407,
    72: 1.387,
    73: 1.368,
    74: 1.349,
    75: 1.331,
    76: 1.313,
    77: 1.296,
    78: 1.279,
    79: 1.262,
    80: 1.246,
    81: 1.231,
    82: 1.216,
    83: 1.201,
    84: 1.186,
    85: 1.172,
    86: 1.158,
    87: 1.145,
    88: 1.132,
    89: 1.119
    #90: 1.106,
    #91: 1.094,
    #92: 1.082,
    #93: 1.07,
    #94: 1.059,
    #95: 1.047,
    #96: 1.036
  }

I am turning this contract on while I go to bed, I will be checking it in 12 hours.

Let me know if you like it, or if you have some suggestions! I wanted to make something that we could all do to pass the time in this bear market :)

edit 2/2/2019: Changed the ratios that are allowed (guessing is from 2-89 now).
« Last Edit: February 02, 2019, 07:44:24 pm by iamredbar »