mirror of
https://git.wownero.com/wownero/tippero.git
synced 2024-08-15 00:33:14 +00:00
dice: allow over/under rolls
This commit is contained in:
parent
206dcbebec
commit
9d6308b0b9
1 changed files with 23 additions and 11 deletions
|
@ -62,14 +62,22 @@ def Dice(nick,chan,cmd):
|
||||||
amount=float(cmd[1])
|
amount=float(cmd[1])
|
||||||
units=long(amount*coinspecs.atomic_units)
|
units=long(amount*coinspecs.atomic_units)
|
||||||
multiplier = float(cmd[2])
|
multiplier = float(cmd[2])
|
||||||
|
overunder=GetParam(cmd,3)
|
||||||
except Exception,e:
|
except Exception,e:
|
||||||
SendTo(sendto, "Usage: dice amount multiplier")
|
SendTo(sendto, "Usage: dice amount multiplier [over|under]")
|
||||||
return
|
return
|
||||||
if multiplier < 0.1 or multiplier > 10:
|
if multiplier < 0.1 or multiplier > 10:
|
||||||
SendTo(sendto, "Invalid multiplier: should be between 0.1 and 10")
|
SendTo(sendto, "Invalid multiplier: should be between 0.1 and 10")
|
||||||
return
|
return
|
||||||
|
if overunder == "over":
|
||||||
|
under=False
|
||||||
|
elif overunder == "under" or not overunder:
|
||||||
|
under=True
|
||||||
|
else:
|
||||||
|
SendTo(sendto, "Usage: dice amount multiplier [over|under]")
|
||||||
|
return
|
||||||
|
|
||||||
log_info("Dice: %s wants to bet %s at x%f" % (nick, AmountToString(units), multiplier))
|
log_info("Dice: %s wants to bet %s at x%f, %s target" % (nick, AmountToString(units), multiplier, "under" if under else "over"))
|
||||||
potential_loss = amount * multiplier
|
potential_loss = amount * multiplier
|
||||||
valid,reason = IsBetAmountValid(amount,config.dice_min_bet,config.dice_max_bet,potential_loss,config.dice_max_loss,config.dice_max_loss_ratio)
|
valid,reason = IsBetAmountValid(amount,config.dice_min_bet,config.dice_max_bet,potential_loss,config.dice_max_loss,config.dice_max_loss_ratio)
|
||||||
if not valid:
|
if not valid:
|
||||||
|
@ -98,16 +106,19 @@ def Dice(nick,chan,cmd):
|
||||||
return
|
return
|
||||||
|
|
||||||
target = (1 - config.dice_edge) / (1+multiplier)
|
target = (1 - config.dice_edge) / (1+multiplier)
|
||||||
log_info("Dice: %s's #%d roll: %.16g, target %.16g" % (nick, rolls, roll, target))
|
log_info("Dice: %s's #%d roll: %.16g, target %s %.16g" % (nick, rolls, roll, "under" if under else "over", target))
|
||||||
|
|
||||||
lose_units = units
|
lose_units = units
|
||||||
win_units = long(units * multiplier)
|
win_units = long(units * multiplier)
|
||||||
log_log('units %s, multiplier %f, edge %f, lose_units %s, win_units %s' % (AmountToString(units), multiplier, config.dice_edge, AmountToString(lose_units), AmountToString(win_units)))
|
log_log('units %s, multiplier %f, edge %f, lose_units %s, win_units %s' % (AmountToString(units), multiplier, config.dice_edge, AmountToString(lose_units), AmountToString(win_units)))
|
||||||
win = roll <= target
|
if under:
|
||||||
if win:
|
win = roll <= target
|
||||||
msg = "%s wins %s on roll #%d! %.16g <= %.16g" % (nick, AmountToString(win_units), rolls, roll, target)
|
|
||||||
else:
|
else:
|
||||||
msg = "%s loses %s on roll #%d. %.16g > %.16g" % (nick, AmountToString(lose_units), rolls, roll, target)
|
win = roll >= target
|
||||||
|
if win:
|
||||||
|
msg = "%s wins %s on roll #%d! %.16g %s %.16g" % (nick, AmountToString(win_units), rolls, roll, "<=" if under else ">=", target)
|
||||||
|
else:
|
||||||
|
msg = "%s loses %s on roll #%d. %.16g %s %.16g" % (nick, AmountToString(lose_units), rolls, roll, ">" if under else "<", target)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
RecordGameResult(nick,chan,"dice",win,not win,win_units if win else lose_units)
|
RecordGameResult(nick,chan,"dice",win,not win,win_units if win else lose_units)
|
||||||
|
@ -223,8 +234,9 @@ def FairCode(nick,chan,cmd):
|
||||||
|
|
||||||
def DiceHelp(nick,chan):
|
def DiceHelp(nick,chan):
|
||||||
SendTo(nick,"The dice module is a provably fair %s dice betting game" % coinspecs.name)
|
SendTo(nick,"The dice module is a provably fair %s dice betting game" % coinspecs.name)
|
||||||
SendTo(nick,"Basic usage: !dice <amount> <multiplier>")
|
SendTo(nick,"Basic usage: !dice <amount> <multiplier> [over|under]")
|
||||||
SendTo(nick,"The goal is to get a roll under a target that depends on your chosen multiplier")
|
SendTo(nick,"The goal is to get a roll under (or over, at your option) a target that depends")
|
||||||
|
SendTo(nick,"on your chosen profit multiplier (1 for even money)")
|
||||||
SendTo(nick,"See !fair and !faircode for a description of the provable fairness of the game")
|
SendTo(nick,"See !fair and !faircode for a description of the provable fairness of the game")
|
||||||
SendTo(nick,"See !faircheck to get the server seed to check past rolls were fair")
|
SendTo(nick,"See !faircheck to get the server seed to check past rolls were fair")
|
||||||
|
|
||||||
|
@ -238,10 +250,10 @@ RegisterModule({
|
||||||
RegisterCommand({
|
RegisterCommand({
|
||||||
'module': __name__,
|
'module': __name__,
|
||||||
'name': 'dice',
|
'name': 'dice',
|
||||||
'parms': '<amount> <multiplier>',
|
'parms': '<amount> <multiplier> [over|under]',
|
||||||
'function': Dice,
|
'function': Dice,
|
||||||
'registered': True,
|
'registered': True,
|
||||||
'help': "start a dice game - house edge %.1f%%" % (float(config.dice_edge)*100)
|
'help': "play a dice game - house edge %.1f%%" % (float(config.dice_edge)*100)
|
||||||
})
|
})
|
||||||
RegisterCommand({
|
RegisterCommand({
|
||||||
'module': __name__,
|
'module': __name__,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue