Hunt for the millions (aka "miljoenenjacht")

Post Reply
Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Hunt for the millions (aka "miljoenenjacht")

Post by Henko »

Hunt for the millions (aka "miljoenenjacht")

This is a little game, which is loosely based on a quiz program on the Dutch television.
In this version, the player is presented with 16 panels (suitcases in the TV game).
13 panels hide sums of money, ranging from $1 to $4.000.000. When "opened" (touched) by the player, the hidden sum is displayed and added to the balance of the player.

However, there are three nasty panels within the 16.
One of them (marked "3/4") reduces the actual balance of the user by 25%, another (marked "1/2") reduces the actual balance by half, 50%. In both cases, the player may continue selecting and hitting panels.
The third nasty panel (marked "X") ends the game immediately and leaves the player with a zero balance.

A high-score is kept on file (which revealed a very unexpected bug in sB).

The "Bank", who would pay the balance to the player upon termination, tries to minimize its loss by making an offer to the player after each move.
The Bank does this by making a probablilistic estimate of the remaining profits and losses of the player. If the result is positive, the Bank offers 60% of it (plus the already gained balance) as a pay-off to the player.
Apart from this, the "Bank-offer" is a good indication to the player about his possible additional winnings. If the offer equals his actual balance, the mathematical expectations are minimal or negative.
IMG_1539.PNG
IMG_1539.PNG (1.22 MiB) Viewed 2311 times

Code: Select all

' Hunt for the millions
'
dim t$(16),w(16),ind(16),stat(4,4)
init()
do 
  k=check_panels() ! if k>=0 then panel(k)
  if bp("accept") then 
    balance=.boffer ! terminate()
    end if
  if bp("reset") then
    file "Millions_high" delete ! top=0 ! field "top" text "0"
    end if
  if bp("stop") then terminate()
until forever
end

def init()
graphics ! graphics clear ! draw color 0,0,0 ! draw size 3
randomize ! set toolbar off
.f$="Millions_high"
if file_exists(.f$) then file .f$ input top$
.top=top$
for i=0 to 12 ! read .t$(i),.w(i) ! next i
data "4M",4000000, "2M",2000000, "1M",1000000, "300K",300000
data "100K",100000, "30K",30000, "10K",10000, "1000",1000
data "300",300, "100",100, "30",30, "10",10, "3",3
.t$(13)=chr$(190) ! .t$(14)=chr$(189) ! .t$(15)=chr$(88)
for i=0 to 15 ! .ind(i)=(i) ! next i
for i=1 to 30
  a=rnd(16) ! b=rnd(16)
  aux=.ind(a) ! .ind(a)=.ind(b) ! .ind(b)=aux
  next i
set buttons custom ! fill color 1,1,0
set buttons font size 30
for i=0 to 3 ! for j=0 to 3
  button i&j text "" at 20+120*j,20+120*i size 100,100
  next j ! next i
set buttons default
set buttons font size 24
for i=0 to 15
  if i>12 then
    tt$="                "&.t$(i)
    field i text tt$ at 560,40+40*i size 160,30 RO
    else
    field i text "$"&n2a$(.w(i),17,0) at 560,40+40*i size 160,30 RO
    end if
    field i back color 1,1,0
  next i
draw rect 540,20 to 740,690
tt$="Your highest score ever :"
field "record" text tt$ at 20,500 size 320,40 RO ! ffo("record")
if .top=0 then tt$="0" else tt$=n2a$(.top,10,0)
field "top" text tt$ at 360,500 size 160,40 RO ! ffo("top")
tt$="Your present balance is :"
field "balance" text tt$ at 20,540 size 320,40 RO ! ffo("balance")
tt$="0"
field "bal" text tt$ at 360,540 size 160,40 RO ! ffo("bal")
tt$="The bank offers a sum of:"
field "bank" text tt$ at 20,580 size 320,40 RO ! ffo("bank")
tt$="0"
field "offer" text tt$ at 360,580 size 160,40 RO ! ffo("offer")
button "stop" text "Quit" at 20,640 size 100,50
button "accept" text "Accept offer" at 150,640 size 150,50
button "reset" text "Reset high" at 330,640 size 150,50
end def

def check_panels()
k=-1
for i=0 to 3 ! for j=0 to 3
  if .stat(i,j) then continue
  if bp(i&j) then
  k=4*i+j ! button i&j text .t$(.ind(k)) ! field .ind(k) hide
  .stat(i,j)=1 ! return k
  end if
  next j ! next i
return k
end def

def panel(k)
k=.ind(k)
if k<13 then
  .balance+=.w(k) ! field "bal" text n2a$(.balance,10,0)
  end if
if k=13 then
  .balance*=0.75
  if .balance then field "bal" text n2a$(.balance,10,0)
  end if
if k=14 then
  .balance*=0.5
  if .balance then field "bal" text n2a$(.balance,10,0)
  end if
if k=15 then
  field "bal" text "0" ! .balance=0 ! terminate()
  end if
.boffer=bank_offer()
if .boffer=0 then tt$="0" else tt$=n2a$(.boffer,10,0)
field "offer" text tt$
end def

def terminate()
if file_exists(.f$) then file .f$ delete
.top=max(.top,.balance)
file .f$ print .top
stop
end def

def bank_offer()
dim st(16)
for i=0 to 15 ! if field_visible(str$(i)) then st(i)=1 ! next i
togo=0 ! n=0
for i=0 to 12
  if st(i) then ! togo+=.w(i) ! n+=1 ! end if
  next i
for i=13 to 15 ! if st(i) then n+=1 ! next i
profit=(togo-.balance)/n
if st(13) then profit-=(.balance+togo)/n/8
if st(14) then profit-=(.balance+togo)/n/4
return .balance+int(max(0,.6*profit))
end def

' format a number for PRINT or DRAW TEXT statement
' num = the number to be formatted
' len = the field length to be used for the formatted number,
'       inclusive decimals, sign, dots, and comma
'       len=0 will automatically use the shortest field needed
' dec = the number of decimal positions
' to print a table right-aligned, give len a value of at least the
'    longest number in the table. Giving even more than that, will
'    have a TAB effect for the whole table
'    
def n2a$(num,len,dec)
dec=max(dec,0)! fh$="###" ! f$="" ! th$="," ! dec$="."
if num<0 then ! s=1 ! num=-num ! else ! s=0 ! end if
pre=max(floor(log10(num)+1),1) ! noc=floor((pre-1)/3)
le=pre+noc+s ! if dec then le+=dec+1
if len and len>le then spaces=len-le else spaces=0
while spaces ! f$&=" " ! spaces-=1 ! end while
if s then f$&="-" ! f$&=left$(fh$,pre-3*noc)
while noc ! f$&=th$&fh$ ! noc-=1 ! end while
if dec then ! f$&=dec$ ! while dec ! f$&="#" ! dec-=1 ! end while ! end if
return str$(num,f$)
end def

def ffo(a$)
field a$ font name "Courier-bold"
field a$ font size 20
field a$ back alpha 0
field a$ font color 0,0,1
end def

def bp(a$) = button_pressed(a$)

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Hunt for the millions (aka "miljoenenjacht")

Post by rbytes »

I won over $2 million playing the game this morning, but nothing has been deposited in my bank account yet. :shock:
The only thing that gets me down is gravity...

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Hunt for the millions (aka "miljoenenjacht")

Post by Henko »

rbytes wrote:
Tue Aug 07, 2018 9:16 pm
I won over $2 million playing the game this morning, but nothing has been deposited in my bank account yet. :shock:
Are you absolutely sure about that? Check your bank balance carefully, the last 7 or 8 digits before the decimal point.... 8-)

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Hunt for the millions (aka "miljoenenjacht")

Post by rbytes »

Oh yeah, there it is! :lol:
The only thing that gets me down is gravity...

Post Reply