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

0 Members and 1 Guest are viewing this topic.

Offline iamredbar

BitShares Dice Game Smart Contract
« on: February 01, 2019, 03:43:47 am »
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 »
BitShares Testnet Witness

Offline pc

  • Hero Member
  • *****
  • Posts: 1477
    • View Profile
    • Bitcoin - Perspektive oder Risiko?
  • BitShares: cyrano
Re: BitShares Dice Game Smart Contract
« Reply #1 on: February 01, 2019, 10:04:18 am »
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 sschiessl

Re: BitShares Dice Game Smart Contract
« Reply #2 on: February 01, 2019, 10:13:00 am »
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 xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12895
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
Re: BitShares Dice Game Smart Contract
« Reply #3 on: February 01, 2019, 11:18:21 am »
you are doing it wrong

https://xkcd.com/221/
Give BitShares a try! Use the http://testnet.bitshares.eu provided by http://bitshares.eu powered by ChainSquad GmbH

Offline clockwork

  • Committee member
  • Sr. Member
  • *
  • Posts: 307
    • View Profile
  • BitShares: clockwork
Re: BitShares Dice Game Smart Contract
« Reply #4 on: February 01, 2019, 12:33:55 pm »

Offline iamredbar

Re: BitShares Dice Game Smart Contract
« Reply #5 on: February 01, 2019, 01:41:42 pm »
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.
BitShares Testnet Witness

Offline iamredbar

Re: BitShares Dice Game Smart Contract
« Reply #6 on: February 01, 2019, 01:42:37 pm »
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!

Haha! How did you get my code?!  ;)
BitShares Testnet Witness

Offline iamredbar

Re: BitShares Dice Game Smart Contract
« Reply #7 on: February 01, 2019, 01:50:36 pm »
Code: [Select]
#get head block number, better than irreversible
  blockNum = blockchain.get_current_block_num()
  print('Block number: {}'.format(blockNum))

  userGuess = userRoll
  seed(blockNum * (userGuess + 1))
 
  diceRatios = btsDiceRatios
  winRatio = diceRatios.get_ratio(userGuess)

  value = randint(1, 100)
  correctGuess = value < int(userGuess)

If everyone would prefer, I can post the code to github but I am embarrassed by it right now, it is very sloppy. The random number logic is above. The only thing that the rest of the code does is interface with the chain.

I would gladly have someone audit the code if they want.
« Last Edit: February 01, 2019, 02:14:14 pm by iamredbar »
BitShares Testnet Witness

Offline iamredbar

Re: BitShares Dice Game Smart Contract
« Reply #8 on: February 01, 2019, 02:23:31 pm »
Also, if the new fee schedule is approved, I will not be able to afford the fees for this game. So hopefully at least one or two people try it before it changes!
BitShares Testnet Witness

Offline iamredbar

Re: BitShares Dice Game Smart Contract
« Reply #9 on: February 01, 2019, 09:32:46 pm »
Here is the Github repo for it: https://github.com/iamredbar/bts-dice-game

Like I said, its still super sloppy and needs improvements.
BitShares Testnet Witness

Offline iamredbar

Re: BitShares Dice Game Smart Contract
« Reply #10 on: February 02, 2019, 02:15:42 pm »
It looks like one or two people have tried! (thank you DL and "lzr") Also looks like it went down while I was sleeping. It is gonna stay down for a bit! I'll post here when its back up.
« Last Edit: February 02, 2019, 02:21:21 pm by iamredbar »
BitShares Testnet Witness

Offline iamredbar

Re: BitShares Dice Game Smart Contract
« Reply #11 on: February 02, 2019, 07:36:50 pm »
Alright, I am turning it back online. I added type checking when parsing the memo, and it now also checks for correct guessing amount.

I will update the Github when I have a chance.
BitShares Testnet Witness

Offline sschiessl

Re: BitShares Dice Game Smart Contract
« Reply #12 on: February 03, 2019, 08:46:20 am »
You can add the expected transfer fee as deduction to payout, no reason to stop due to that

Offline iamredbar

Re: BitShares Dice Game Smart Contract
« Reply #13 on: February 03, 2019, 03:51:00 pm »
You can add the expected transfer fee as deduction to payout, no reason to stop due to that

I know I could, but I want to keep the fees as low as possible to incentivize. Making the contract address a LTM is a good place to start.
BitShares Testnet Witness

Offline iamredbar

Re: BitShares Dice Game Smart Contract
« Reply #14 on: February 04, 2019, 04:16:53 am »
I now have the contract running with an autoreboot if it crashes. The contract should be up all the time! When I take it down, I will post it here.
BitShares Testnet Witness

Offline Victor118

Re: BitShares Dice Game Smart Contract
« Reply #15 on: February 04, 2019, 09:23:52 am »
Interesting
May be it's a good idea to think about to implement a game of dice in bitshares core?


Offline iamredbar

Re: BitShares Dice Game Smart Contract
« Reply #17 on: February 17, 2019, 02:15:59 am »
Game is currently down for maintenance.
BitShares Testnet Witness

Offline iamredbar

Re: BitShares Dice Game Smart Contract
« Reply #18 on: March 03, 2019, 01:02:29 pm »
Contract is running again.
BitShares Testnet Witness

Offline iamredbar

Re: BitShares Dice Game Smart Contract
« Reply #19 on: March 04, 2019, 01:54:08 am »
Down for maintenance.
BitShares Testnet Witness

Offline GeraldShoug

  • Newbie
  • *
  • Posts: 9
    • View Profile
BitShares Dice Game Smart Contract
« Reply #20 on: March 27, 2019, 03:28:51 am »
FFG forums just added a new forum for:  Star Wars: DestinyA collectible dice and card game of saga-spanning duels