Page 1 of 1

IMP calculator for bridge card game

Posted: Thu Dec 11, 2014 7:12 pm
by Henko

Code: Select all

' IMP calculator for Bridge card game
' selectable Dutch/English text, designed for iPhone3 and up
' programmed by Henk Overtoom (NL), dec. 2014, in Smart Basic
' published by ...........
'
' language$="English"  ' uncomment this for English version

option base 1 
maxx=320 ! maxy=436
graphics ' fill color .8,.8,.8 ! draw color 0,0,0
graphics clear .8,.8,.8
dim score_nk(4,8,3),score_kw(4,8,3),corr(20,2),imp(25),con(3)
dim num$(7),col$(5),colE$(5),res$(13),pnt$(30),c$(5),cE$(5)

for i=1 to 13
  k$=7-i ! if i<7 then k$="+" & k$
  res$(i)="  " & k$ & "  "
  next i
res$(7)="  C  "
for i=1 to 5 ! read c$(i) ! next i
for i=1 to 5 ! read cE$(i) ! next i
for i=1 to 25 ! pnt$(i)="  " & 41-i & "  " ! next i
for i=1 to 7 ! num$(i)="  " & i & " " ! next i
for i=1 to 5 ! read col$(i) ! next i
for i=1 to 5 ! read colE$(i) ! next i
for i=1 to 25 ! read imp(i) ! next i
for i=1 to 20 ! read corr(i,1) ! next i
for i=1 to 20 ! read corr(i,2) ! next i
for i=1 to 4 ! for j=1 to 8 ! for k=1 to 3
  read score_nk(i,j,k)
  next k ! next j ! next i
for i=1 to 4 ! for j=1 to 8 ! for k=1 to 3
  read score_kw(i,j,k)
  next k ! next j ! next i
if language$="English" then
  for i=1 to 5 ! c$(i)=cE$(i) ! col$(i)=colE$(i) ! next i
  end if
data "K","R","H","S","SA"
data "C","D","H","S","NT"
data "klaver","ruiten","harten","schop","  SA"
data "clubs","diamo","hearts","spade","  NT"
data 10,40,80,120,160,210,260,310,360,420,490,590,740,890,1090,1290,1490,1740,1990,2240,2490,2990,3490,3990,9999
data 50,90,120,150,400,420,440,460,480,500,880,910,940,970,1000,1420,1440,1460,1480,1500
data 50,90,120,150,600,620,640,660,680,700,1330,1360,1390,1420,1450,2120,2140,2160,2180,2200
data 70,140,230,90,180,560,110,470,640,130,510,720
data 400,550,800,920,1090,1380,1440,1630,1960,20,100,200
data 80,160,520,110,470,640,140,530,760,420,590,880
data 450,650,1000,980,1210,1620,1510,1770,2240,30,100,200
data 90,180,560,120,490,680,400,550,800,430,610,920
data 460,670,1040,990,1230,1660,1520,1790,2250,30,100,200
data 50,100,200,100,300,600,150,500,1000,200,800,1600
data 250,1100,2200,300,1400,2800,350,1700,3400,0,0,0
data 70,140,230,90,180,760,110,670,840,130,710,920
data 600,750,1000,1370,1540,1830,2140,2330,2660,20,200,400
data 80,160,720,110,670,840,140,730,960,620,790,1080
data 650,850,1200,1430,1660,2070,2210,2470,2940,30,200,400
data 90,180,760,120,690,880,600,750,1000,630,810,1120
data 660,870,1240,1440,1680,2110,2220,2490,2980,30,200,400
data 100,200,400,200,500,1000,300,800,1600,400,1100,2200
data 500,1400,2800,600,1700,3400,700,2000,4000,0,0,0

ronde0:
select (con,c$)
if con(1)=0 then cc$="pas" else cc$="" & con(2) & c$(con(1))
if con(3)=1 then cc$=cc$ & ":"
if con(3)=2 then cc$=cc$ & "::"
pr_out(cc$)

res=result() ! u$=cc$
if res=0 then
  if con(1)<>0 then u$&=" C"
  else
  if res<0 then u$&="" & res else u$&="+" & res
  end if
pr_out(u$)
score=0
if con(1)=0 then goto scoreklaar
if res<0 then
  ia=4
  ib=-res
  ic=con(3)+1
  if kw_ind=0 then score=-score_nk(ia,ib,ic) else score=-score_kw(ia,ib,ic)
  goto scoreklaar
  end if
if con(1)<3 then
  ia=1
  else
  if con(1)=3 or con(1)=4 then ia=2 else ia=3
  end if
ib=con(2)
ic=con(3)+1 
if kw_ind=0 then
  score=score_nk(ia,ib,ic)+res*score_nk(ia,8,ic)
  else
  score=score_kw(ia,ib,ic)+res*score_kw(ia,8,ic)
  end if

scoreklaar:
if language$="English" then tc$="points" else tc$="punten"
c_list("ptn",tc$,.pnt$,25,210,210,300,370)
list "ptn" set selection 19
ronde5: pause .5 ! pt=list_selected("ptn")
if pt=-1 or not bp("oke") then ronde5 else pt=41-pt
button "oke" delete
button "terug" delete

pt=pt-20
if pt=0 then
  moet=0
  else
  if pt>0 then moet=corr(pt,kw_ind+1) else moet=-corr(-pt,kw_ind+1)
  end if
fin=score-moet
if fin<0 then fac=-1 else fac=1
fin=fac*fin
for k=1 to 25
  if fin<=imp(k) then
    fin=k-1
    k=25
    end if
  next k
fin=fac*fin
u$&=" " & fin & " imps" ! pr_out(u$)

button "door" title "reset" at 95,376 size 105,50
ronde8: if not bp("door") then ronde8
list "num_bod" delete ! list "col_bod" delete
list "result" delete ! list "ptn" delete
button "door" delete ! graphics clear .8,.8,.8
goto ronde0
end

def select (con(),c$())
draw text "contract:" at 2,4
if .language$="English" then tit$="tricks" else tit$="slagen"
c_list ("num_bod",tit$,.num$,7,5,30,85,370)
if .language$="English" then tit$=" suit" else tit$="kleur"
c_list ("col_bod",tit$,.col$,5,100,30,190,280)
yb=384 ! sizex=60 ! sizey=40 ! .kw_ind=0
if .language$="English" then
  bn$="not vulnerable" ! pas$="PASS"
  else
  bn$="niet kwetsbaar" ! pas$="PAS"
  end if
button "kwets" title bn$ at 100,yb-80 size 140,50
button "pas" title pas$ at 5,yb size sizex,sizey
button "dubbel" title "X" at 80,yb size sizex,sizey
button "triple" title "XX" at 155,yb size sizex,sizey
button "oke" title "OK ?" at 230,yb size sizex,sizey
for i=1 to 3 ! con(i)=0 ! next i
select1: pause .5
if bp("kwets") then
  .kw_ind=1-.kw_ind
  if .language$="English" then
    if .kw_ind then bn$="vulnerable" else bn$="not vulnerable"
    else
    if .kw_ind then bn$="kwetsbaar" else bn$="niet kwetsbaar"
    end if
  button "kwets" set title bn$
  end if
con(2)=list_selected("num_bod") ! con(1)=list_selected("col_bod")
if con(1)>0 and con(2)>0 then select2
if bp("pas")=1 then ! con(1)=0 ! goto select3 ! end if
goto select1
select2:
if bp("dubbel") then 
  if con(3)=1 then con(3)=0 else con(3)=1
  end if
if bp("triple") then
  if con(3)=2 then con(3)=0 else con(3)=2
  end if
if bp("oke") then select3
goto select1
select3:
button "kwets" delete
button "pas" delete
button "dubbel" delete
button "triple" delete
button "oke" delete
end def

def result()
c_list("result","result",.res$,13,210,30,300,190)
list "result" set selection 7
button "oke" title "ok ?" at 230,384 size 60,40
if .con(1)=0 then return 0
done=0
result1: pause .5
i=list_selected("result")
if i>0 then ! res=7-i ! done=1 ! end if
if bp("oke") and done then goto result2
goto result1
result2:
return res
end def

' id$ = object name
' cont$ = array met elementen
' size = aantal elementen in de list
'
def c_list(id$,title$,cont$(),size,xt,yt,xb,yb)
dim temp$(size)
for i=1 to size ! temp$(i)=cont$(i) ! next i
list id$ text temp$ at xt+2,yt+32 size xb-xt-4,yb-yt-34
draw size 3
draw rect xt,yt to xb,yb ! draw line xt,yt+30 to xb,yt+30
draw color 0,0,1 ! draw text title$ at xt+5,yt+5
draw color 0,0,0
end def

def pr_out(t$)
if .kw_ind then draw color 1,0,0 else draw color 0,0,0
draw text t$ at 120,4 ! draw color 0,0,0
end def

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

Re: IMP calculator for bridge card game

Posted: Thu Dec 11, 2014 7:19 pm
by Henko
@ mr. K.:
This is the program wanted to be used by some fellow bridgers (and probably by a lot of other bridge players)
I had a look how it could be published in the appstore, but i don't have a clue. I don't have a MAC computer either.
Could you publish it in the Dutch appstore? An English version for an international appstore can be obtained easily by uncommenting the 5th codeline.
If it can't be done, its no big deal. In that case they have to install the SB app.
Thanks.

Re: IMP calculator for bridge card game

Posted: Thu Dec 11, 2014 8:11 pm
by Mr. Kibernetik
You can easily make multilingual program, which uses English by default and Dutch if it is detected.
Use SYSTEM_LANGUAGE$() function to get device language.

App Store version of program does not allow access to program code.

Re: IMP calculator for bridge card game

Posted: Thu Dec 11, 2014 8:23 pm
by Henko
Mr. Kibernetik wrote:You can easily make multilingual program, which uses English by default and Dutch if it is detected.
Use SYSTEM_LANGUAGE$() function to get device language.

App Store version of program does not allow access to program code.
I see. I'll modify the program and upload it again. Can postings be deleted by the OP (original poster)?

Re: modified IMP calculator for bridge card game

Posted: Thu Dec 11, 2014 8:40 pm
by Henko

Code: Select all

' IMP calculator for Bridge card game (version 1.2)
' selectable Dutch/English text, designed for iPhone3 and up
' programmed by Henk Overtoom (NL), dec. 2014, in Smart Basic
' published by ...........
'
language$=system_language$()
option base 1 
maxx=320 ! maxy=436
graphics ' fill color .8,.8,.8 ! draw color 0,0,0
graphics clear .8,.8,.8
dim score_nk(4,8,3),score_kw(4,8,3),corr(20,2),imp(25),con(3)
dim num$(7),col$(5),colN$(5),res$(13),pnt$(30),c$(5),cN$(5)

for i=1 to 13
  k$=7-i ! if i<7 then k$="+" & k$
  res$(i)="  " & k$ & "  "
  next i
res$(7)="  C  "
for i=1 to 5 ! read c$(i) ! next i
for i=1 to 5 ! read cN$(i) ! next i
for i=1 to 25 ! pnt$(i)="  " & 41-i & "  " ! next i
for i=1 to 7 ! num$(i)="  " & i & " " ! next i
for i=1 to 5 ! read col$(i) ! next i
for i=1 to 5 ! read colN$(i) ! next i
for i=1 to 25 ! read imp(i) ! next i
for i=1 to 20 ! read corr(i,1) ! next i
for i=1 to 20 ! read corr(i,2) ! next i
for i=1 to 4 ! for j=1 to 8 ! for k=1 to 3
  read score_nk(i,j,k)
  next k ! next j ! next i
for i=1 to 4 ! for j=1 to 8 ! for k=1 to 3
  read score_kw(i,j,k)
  next k ! next j ! next i
if language$="nl" then
  for i=1 to 5 ! c$(i)=cN$(i) ! col$(i)=colN$(i) ! next i
  end if
data "C","D","H","S","NT"
data "K","R","H","S","SA"
data "clubs","diamo","hearts","spade","  NT"
data "klaver","ruiten","harten","schop","  SA"
data 10,40,80,120,160,210,260,310,360,420,490,590,740,890,1090,1290,1490,1740,1990,2240,2490,2990,3490,3990,9999
data 50,90,120,150,400,420,440,460,480,500,880,910,940,970,1000,1420,1440,1460,1480,1500
data 50,90,120,150,600,620,640,660,680,700,1330,1360,1390,1420,1450,2120,2140,2160,2180,2200
data 70,140,230,90,180,560,110,470,640,130,510,720
data 400,550,800,920,1090,1380,1440,1630,1960,20,100,200
data 80,160,520,110,470,640,140,530,760,420,590,880
data 450,650,1000,980,1210,1620,1510,1770,2240,30,100,200
data 90,180,560,120,490,680,400,550,800,430,610,920
data 460,670,1040,990,1230,1660,1520,1790,2250,30,100,200
data 50,100,200,100,300,600,150,500,1000,200,800,1600
data 250,1100,2200,300,1400,2800,350,1700,3400,0,0,0
data 70,140,230,90,180,760,110,670,840,130,710,920
data 600,750,1000,1370,1540,1830,2140,2330,2660,20,200,400
data 80,160,720,110,670,840,140,730,960,620,790,1080
data 650,850,1200,1430,1660,2070,2210,2470,2940,30,200,400
data 90,180,760,120,690,880,600,750,1000,630,810,1120
data 660,870,1240,1440,1680,2110,2220,2490,2980,30,200,400
data 100,200,400,200,500,1000,300,800,1600,400,1100,2200
data 500,1400,2800,600,1700,3400,700,2000,4000,0,0,0

ronde0:
select (con,c$)
if con(1)=0 then cc$="pas" else cc$="" & con(2) & c$(con(1))
if con(3)=1 then cc$=cc$ & ":"
if con(3)=2 then cc$=cc$ & "::"
pr_out(cc$)

res=result() ! u$=cc$
if res=0 then
  if con(1)<>0 then u$&=" C"
  else
  if res<0 then u$&="" & res else u$&="+" & res
  end if
pr_out(u$)
score=0
if con(1)=0 then goto scoreklaar
if res<0 then
  ia=4
  ib=-res
  ic=con(3)+1
  if kw_ind=0 then score=-score_nk(ia,ib,ic) else score=-score_kw(ia,ib,ic)
  goto scoreklaar
  end if
if con(1)<3 then
  ia=1
  else
  if con(1)=3 or con(1)=4 then ia=2 else ia=3
  end if
ib=con(2)
ic=con(3)+1 
if kw_ind=0 then
  score=score_nk(ia,ib,ic)+res*score_nk(ia,8,ic)
  else
  score=score_kw(ia,ib,ic)+res*score_kw(ia,8,ic)
  end if

scoreklaar:
if language$="nl" then tc$="punten" else tc$="points"
c_list("ptn",tc$,.pnt$,25,210,210,300,370)
list "ptn" set selection 19
ronde5: pause .5 ! pt=list_selected("ptn")
if pt=-1 or not bp("oke") then ronde5 else pt=41-pt
' button "oke" delete
' button "terug" delete

pt=pt-20
if pt=0 then
  moet=0
  else
  if pt>0 then moet=corr(pt,kw_ind+1) else moet=-corr(-pt,kw_ind+1)
  end if
fin=score-moet
if fin<0 then fac=-1 else fac=1
fin=fac*fin
for k=1 to 25
  if fin<=imp(k) then
    fin=k-1
    k=25
    end if
  next k
fin=fac*fin
u$&=" " & fin & " imps" ! pr_out(u$)

button "door" title "reset" at 95,376 size 105,50
ronde8: if not bp("door") then ronde8
list "num_bod" delete ! list "col_bod" delete
list "result" delete ! list "ptn" delete
button "door" delete ! graphics clear .8,.8,.8
goto ronde0
end

def select (con(),c$())
draw text "contract:" at 2,4
if .language$="nl" then tit$="slagen" else tit$="tricks"
c_list ("num_bod",tit$,.num$,7,5,30,85,370)
if .language$="nl" then tit$="kleur" else tit$=" suit"
c_list ("col_bod",tit$,.col$,5,100,30,190,280)
yb=384 ! sizex=60 ! sizey=40 ! .kw_ind=0
if .language$="nl" then
  bn$="niet kwetsbaar" ! pas$="PAS"
  else
  bn$="not vulnerable" ! pas$="PASS"
  end if
button "kwets" title bn$ at 100,yb-80 size 140,50
button "pas" title pas$ at 5,yb size sizex,sizey
button "dubbel" title "X" at 80,yb size sizex,sizey
button "triple" title "XX" at 155,yb size sizex,sizey
button "oke" title "OK ?" at 230,yb size sizex,sizey
for i=1 to 3 ! con(i)=0 ! next i
select1: pause .5
if bp("kwets") then
  .kw_ind=1-.kw_ind
  if .language$="nl" then
    if .kw_ind then bn$="kwetsbaar" else bn$="niet kwetsbaar"
    else
    if .kw_ind then bn$="vulnerable" else bn$="not vulnerable"
    end if
  button "kwets" set title bn$
  end if
con(2)=list_selected("num_bod") ! con(1)=list_selected("col_bod")
if con(1)>0 and con(2)>0 then select2
if bp("pas")=1 then ! con(1)=0 ! goto select3 ! end if
goto select1
select2:
if bp("dubbel") then 
  if con(3)=1 then con(3)=0 else con(3)=1
  end if
if bp("triple") then
  if con(3)=2 then con(3)=0 else con(3)=2
  end if
if bp("oke") then select3
goto select1
select3:
button "kwets" delete
button "pas" delete
button "dubbel" delete
button "triple" delete
button "oke" delete
end def

def result()
c_list("result","result",.res$,13,210,30,300,190)
list "result" set selection 7
button "oke" title "ok ?" at 230,384 size 60,40
if .con(1)=0 then return 0
done=0
result1: pause .5
i=list_selected("result")
if i>0 then ! res=7-i ! done=1 ! end if
if bp("oke") and done then goto result2
goto result1
result2:
return res
end def

' id$ = object name
' cont$ = array met elementen
' size = aantal elementen in de list
'
def c_list(id$,title$,cont$(),size,xt,yt,xb,yb)
dim temp$(size)
for i=1 to size ! temp$(i)=cont$(i) ! next i
list id$ text temp$ at xt+2,yt+32 size xb-xt-4,yb-yt-34
draw size 3
draw rect xt,yt to xb,yb ! draw line xt,yt+30 to xb,yt+30
draw color 0,0,1 ! draw text title$ at xt+5,yt+5
draw color 0,0,0
end def

def pr_out(t$)
if .kw_ind then draw color 1,0,0 else draw color 0,0,0
draw text t$ at 120,4 ! draw color 0,0,0
end def

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

Re: IMP calculator for bridge card game

Posted: Thu Dec 11, 2014 9:29 pm
by Dalede
Henko wrote:
Mr. Kibernetik wrote:You can easily make multilingual program, which uses English by default and Dutch if it is detected.
Use SYSTEM_LANGUAGE$() function to get device language.

App Store version of program does not allow access to program code.
I see. I'll modify the program and upload it again. Can postings be deleted by the OP (original poster)?
you can delete a post but usually better is that you can modify it to your hearts content. Both can be reached from the edit button.

Dale

Re: IMP calculator for bridge card game

Posted: Fri Dec 12, 2014 6:51 am
by Mr. Kibernetik
Henko, I can submit your app to App Store, but I think they will consider it to be too simple-looking and will reject.
Anyway, we can try - and will see.
So, you will need to make desktop icons for it according to this info: viewtopic.php?f=34&t=731

Re: IMP calculator for bridge card game

Posted: Fri Dec 12, 2014 9:20 am
by Henko
Mr. Kibernetik wrote:Henko, I can submit your app to App Store, but I think they will consider it to be too simple-looking and will reject.
Anyway, we can try - and will see.
So, you will need to make desktop icons for it according to this info: viewtopic.php?f=34&t=731
Thanks for willing to try (and for creating the possibility), but I pass.
If my fellow bridgers want to use the app, they can pay a few bucks to install SB and that's it.

I found precisely one app in the app store that has exactly the same function (named "Duplicate bridge imp scorer"), but does so with a lot of erronuous results. Hence it has zero usability, but the screen is full of nice colors :lol: that is in accordance with your remark about Apples acceptance policy ;)

Anyway, thanks again for your supportive attitude.

Re: IMP calculator for bridge card game

Posted: Fri Dec 12, 2014 9:35 am
by Mr. Kibernetik
Also, even running in smart BASIC, if you want to keep your algorithm in secret, you can make your program coded - so nobody will be able to enter and look into your code.