home » builders » builder's lessons » gambling progs

Gambling programs

Gambling programs can get very complex. It is something that in general only an experienced builder comfortable with mob programs can do. The following program was written by Dalvyn, whom I would consider our most savvy area coder. As you can see its quite a complex prog.

#15906
gamemaster master~
{70}a gamemaster~
{70}A gamemaster, clad in a silvery robe, stands here.~
This aged human seems to enjoy his work in the Gamblin Hall very
much. He is clad in a silvery robe decorated with a silver coin,
the symbol of Tymora.
~
U 35 CLASS_FIGHTERS RACE_HUMAN SEX_MALE POS_STANDING DEITY_TYMORA
ACT_SENTINEL|ACT_CITIZEN
0
ARMOR_TYPE_CLOTH MATERIAL_CLOTH
d8+2 650
13 13 13 18 13 13 13
0 0 0 0 0
LANG_COMMON
LANG_COMMON
0 0 0
>time_prog 5~
wake
mpwalkto 15921
~
>time_prog 23~
yawn
say Enough for today. I need some rest.
mpwalkto 15927
~
>arrival_prog 15927~
yawn
sleep
~
>greet_prog 100~
mpmset $n quest 20 9 0
mpmset $n quest 30 1 0
mpmset $n questr 8200 4 1 0
sayto $n If you want to play, you have found the right place!
sayto $n Read the rules on this plaque
sayto $n and give me a token, then we will start.
mpecho The gamemaster points to the plaque on the wall.
~
>give_prog 15900~
if quest(20,3,$n) == 0
  mpjunk all
  mpmset $n quest 20 3 1
  sayto $n Very well... we will play for a copper token.
  sayto $n Throw the dice when you want.
else
  sayto $n You have already given me a token
  give token $n
endif
~
>give_prog 15901~
if quest(20,3,$n) == 0
  mpjunk all
  mpmset $n quest 20 3 2
  sayto $n Very well... we will play for a silver token.
  sayto $n Throw the dice when you want.
else
  sayto $n You have already given a token.
  give token $n
endif
~
>give_prog 15902~
if quest(20,3,$n) == 0
  mpjunk all
  mpmset $n quest 20 3 3
  sayto $n Very well... we will play for a gold token.
  sayto $n Throw the dice when you want.
else
  sayto $n You have already given me a token
  give token $n
endif
~
>give_prog 15903~
if quest(20,3,$n) == 0
  mpjunk all
  mpmset $n quest 20 3 4
  sayto $n Very well... we will play for a platinum token.
  sayto $n Throw the dice when you want.
else
  sayto $n You have already given me a token
  give token $n
endif
~
>give_prog 15904~
if quest(20,3,$n) == 0
  mpjunk all
  mpmset $n quest 20 3 5
  sayto $n Very well... we will play for a luck token.
  sayto $n Throw the dice when you want.
else
  sayto $n You have already given me a token
  give token $n
endif
~
>intercept_prog throw~
if quest(20,3,$n) > 0
  if quest(23,3,$n) == 0
    if rand(16)
      mpechoat $n You throw the dice and get 1 star.
      mpechoaround $n $n throws a dice and gets 1 star.
      mpmset $n quest 23 3 1
    else
      if rand(20)
        mpechoat $n You throw the dice and get 2 stars.
        mpechoaround $n $n throws a dice and gets 2 stars.
        mpmset $n quest 23 3 2
      else
        if rand(25)
          mpechoat $n You throw the dice and get 3 stars.
          mpechoaround $n $n throws a dice and gets 3 stars.
          mpmset $n quest 23 3 3
        else
          if rand(33)
            mpechoat $n You throw the dice and get 4 stars.
            mpechoaround $n $n throws a dice and gets 4 stars.
            mpmset $n quest 23 3 4
          else
            if rand(50)
              mpechoat $n You throw the dice and get 5 stars.
              mpechoaround $n $n throws a dice and gets 5 stars.
              mpmset $n quest 23 3 5
            else
              mpechoat $n You throw the dice and get 6 stars!
              mpechoaround $n $n throws a dice and gets 6 stars!
              mpmset $n quest 23 3 6
            endif
          endif
        endif
      endif
    endif
    sayto $n Do you want to keep this result?
    sayto $n Or to throw again?
    mpmset $n questr 8200 4 1 1
  else
    sayto $n If you want to throw the dice again, say so.
    sayto $n Otherwise, tell me that you want to keep this result.
  endif
else
  sayto $n You must give me a token first!
endif
~
>speech_prog keep~
if questr(8200,4,1,$n) == 1
  if quest(20,3,$n) > 0
    if quest(23,3,$n) > 0
      mpmset $n questr 8200 4 1 0
      sayto $n Alright. My turn to throw the dice now!
      if rand(8)
        mpecho The gamemaster throws a dice and gets 1 star.
        mpmset $n quest 26 3 1
      else
        if rand(10)
          mpecho The gamemaster throws a dice and gets 2 stars.
          mpmset $n quest 26 3 2
        else
          if rand(12)
            mpecho The gamemaster throws a dice and gets 3 stars.
            mpmset $n quest 26 3 3
          else
            if rand(20)
              mpecho The gamemaster throws a dice and gets 4 stars.
              mpmset $n quest 26 3 4
            else
              if rand(50)
                mpecho The gamemaster throws a dice and gets 5 stars.
                mpmset $n quest 26 3 5
              else
                mpecho The gamemaster throws a dice and gets 6 stars!
                mpmset $n quest 26 3 6
              endif
            endif
          endif
        endif
      endif
    else
      mpechoat $n The gamemaster motions for you to throw the dice.
      mpechoaround $n The gamemaster motions for $n to throw the dice.
    endif
  else
    sayto $n You should give me a token first!
  endif
endif
~
>speech_prog throw again~
if questr(8200,4,1,$n) == 1
  if quest(20,3,$n) > 0
    if quest(23,3,$n) > 0
      mpmset $n questr 8200 4 1 0
      mpechoat $n The gamemaster motions for you to throw the dice again.
      mpechoaround $n The gamemaster motions for $n to throw the dice again.
      if rand(16)
        mpechoat $n You throw the dice and get 1 star.
        mpechoaround $n $n throws a dice and gets 1 star.
        mpmset $n quest 23 3 1
      else
        if rand(20)
          mpechoat $n You throw the dice and get 2 stars.
          mpechoaround $n $n throws a dice and gets 2 stars.
          mpmset $n quest 23 3 2
        else
          if rand(25)
            mpechoat $n You throw the dice and get 3 stars.
            mpechoaround $n $n throws a dice and gets 3 stars.
            mpmset $n quest 23 3 3
          else
            if rand(33)
              mpechoat $n You throw the dice and get 4 stars.
              mpechoaround $n $n throws a dice and gets 4 stars.
              mpmset $n quest 23 3 4
            else
              if rand(50)
                mpechoat $n You throw the dice and get 5 stars.
                mpechoaround $n $n throws a dice and gets 5 stars.
                mpmset $n quest 23 3 5
              else
                mpechoat $n You throw the dice and get 6 stars!
                mpechoaround $n $n throws a dice and gets 6 stars!
                mpmset $n quest 23 3 6
              endif
            endif
          endif
        endif
      endif
      sayto $n My turn now!
      if rand(8)
        mpecho The gamemaster throws a dice and gets 1 star.
        mpmset $n quest 26 3 1
      else
        if rand(10)
          mpecho The gamemaster throws a dice and gets 2 stars.
          mpmset $n quest 26 3 2
        else
          if rand(12)
            mpecho The gamemaster throws a dice and gets 3 stars.
            mpmset $n quest 26 3 3
          else
            if rand(20)
              mpecho The gamemaster throws a dice and gets 4 stars.
              mpmset $n quest 26 3 4
            else
              if rand(50)
                mpecho The gamemaster throws a dice and gets 5 stars.
                mpmset $n quest 26 3 5
              else
                mpecho The gamemaster throws a dice and gets 6 stars!
                mpmset $n quest 26 3 6
              endif
            endif
          endif
        endif
      endif
    else
      mpechoat $n The gamemaster motions for you to throw the dice.
      mpechoaround $n The gamemaster motions for $n to throw the dice.
    endif
  else
    sayto $n You should give me a token first!
  endif
endif
~
>rand_prog 60~
if quest(20,3,$r) > 0
 if quest(23,3,$r) > 0
  if quest(26,3,$r) > 0
   mpjunk all
   if quest(20,3,$r) == 1
    mpoload 15900
    mpoload 15900
   else
    if quest(20,3,$r) == 2
     mpoload 15901
     mpoload 15901
    else
     if quest(20,3,$r) == 3
      mpoload 15902
      mpoload 15902
     else
      if quest(20,3,$r) == 4
       mpoload 15903
       mpoload 15903
      else
       mpoload 15904
       mpoload 15904
      endif
     endif
    endif
   endif
   if quest(23,3,$r) == 6
    if quest(26,3,$r) == 6
     sayto $r Same results! You get reimbursed.
     give token $r
    else
     sayto $r You win!
     give token $r
     give token $r
    endif
   else
    if quest(23,3,$r) == 5
     if quest(26,3,$r) == 6
      sayto $r I win... and you lose!
     else
      if quest(26,3,$r) == 5
       sayto $r Same results! You get reimbursed.
       give token $r
      else
       sayto $r You win!
       give token $r
       give token $r
      endif
     endif
    else
     if quest(23,3,$r) == 4
      if quest(26,3,$r) > 4
       sayto $r I win... and you lose!
      else
       if quest(26,3,$r) == 4
        sayto $r Same results! You get reimbursed.
        give token $r
       else
        sayto $r You win!
        give token $r
        give token $r
       endif
      endif
     else
      if quest(23,3,$r) == 3
       if quest(26,3,$r) > 3
        sayto $r I win... and you lose!
       else
        if quest(26,3,$r) == 3
         sayto $r Same results! You get reimbursed.
         give token $r
        else
         sayto $r You win!
         give token $r
         give token $r
        endif
       endif
      else
       if quest(23,3,$r) == 2
        if quest(26,3,$r) > 2
         sayto $r I win... and you lose!
        else
         if quest(26,3,$r) == 2
          sayto $r Same results! You get reimbursed.
          give token $r
         else
          sayto $r You win!
          give token $r
          give token $r
         endif
        endif
       else
        if quest(26,3,$r) == 1
         sayto $r Same results! You get reimbursed.
         give token $r
        else
         sayto $r I win... and you lose!
        endif
       endif
      endif
     endif
    endif
   endif
   mpmset $r quest 20 9 0
   mpmset $r quest 30 1 0
   mpjunk all
  endif
 endif
endif
~
>fight_prog 20~
yell Help! I am being attacked by $N
mpat 4500 yell Help! I am being attacked by $N in Fortune Hall.
if quest(0,3,self) < 5
  mpmadd self quest 0 3 1
  mpecho A guard comes to the help of $I
  if rand(20)
    mpmload 4500
    mpforce m4500 mpkill $n
  else
    mpmload 15911
    mpforce m15911 mpkill $n
  endif
endif
~
>death_prog 100~
mplog WITNESS: (on $v) $I has been killed by $n in Fortune Hall.
mpmset self quest 0 3 0
~
|

The first give_prog are to trigger the game, when the game master is given a token (representing the amount that he is willing to bet). The game consists of two contestants rolling 1d6. The player has the choice to reroll once if he wishes (in which case he's forced to keep the second result). It uses qbits on the player to indicate the state: before the first roll, after the first roll, after the second roll, and so on. It uses qbits to store the result of the both the player's and the game master's dice.

20,3 designates the amount that was bet (actually, the type of token). 0 means that no token has been given. 23,3 indicates the result of the player's dice (0 = not thrown, 1-6 = result). 26,3 indicates the result of the game master's dice (0 = not thrown, 1-6 = result)

The program uses 3 intercept progs: throw (for rolling the dice the first time), keep (if the player wants to keep the first result, indicating that the game master must roll his dice), and again (if the player wants to reroll). These intercept prog only determine the results randomly.

Then the rand prog is triggered after some time, and the result of the game is shown (either the player get new tokens if he won, or the qbits are reset if he lost). The other progs are just greet prog, and fight prog with no relation to the actual gambling game.