A Tool for Calculating Bridge Score

advertisement
A Tool for Calculating Bridge Score
Project Report
Table of Contents
Foreword ................................................................................................................................
................................
..................................... 1
Principle ................................................................................................................................
................................
........................................... 1
Made side ................................................................................................................................
................................
.................................... 2
Down side ................................................................................................................................
................................
.................................... 2
Develop Process ................................................................................................
................................
.............................................................. 2
Flow in text ................................................................................................................................
................................
.................................. 2
First design................................
...............................................................................................................................
............................... 2
Second design ................................................................................................
................................
.......................................................... 3
Flow in diagram ................................................................................................
................................
........................................................... 4
First design................................
...............................................................................................................................
............................... 4
Second design ................................................................................................
................................
.......................................................... 4
Result program ................................................................................................................................
................................
................................ 6
FX-50FH ................................................................................................................................
................................
....................................... 6
FX-3650P ................................................................................................................................
................................
...................................... 6
Reflection................................
................................................................................................................................
......................................... 6
Foreword
The Bridge Club of Wah Yan College, Kowloon (abbrev. WYKBC) aims to promote bridge in school.
In the game Contract Bridge, there is a score for each board, and that decides which
whi pair/team
wins the competition. For the sake of convenience, a card with a table containing the scores for
different contract made should be printed for reference, or a program (for programmable
calculators or computers) should be written. Hence, the St
Students’ Computer Team (abbrev. SCT)
started to make such a program, supporting WYKBC.
Principle
According to the method stated in Wikipedia (http://en.wikipedia.org/wiki/Bridge_scoring
http://en.wikipedia.org/wiki/Bridge_scoring), the
score is awarded to the declarer side if the contract is made, and to the defense side if the
declarer side failed to make the contract.
Page 1
WYKSCT
Made side
The components of the result score consists of 4 parts, namely Contract points,
points Level bonus,
Double bonus, and Overtrick points.
points
Down side
The score is divided into three parts, which are the 1st undertrick, 2nd and 3rd, and 4th and further
respectively. When doubled (or redoubled), n vulnerable undertricks cost as much as n+1 nonvulnerable ones.
Develop Process
Flow in text
The “Made” side is designed by the Chief Programmer of SCT, David Lau, and the “Down” side is
designed by the Director of SCT, Sunny Pun.
First design
Here is the first design of the flow:
1. Input suit (*C,D,H,M,N*), vunl(* 0,1
0, *), dbl (* 1,2 or 4 *), contract
2. Input the num_of_tricks (* e.g. down 1=-1,
1= 1, just made=0, up 1=1 *)
(* if num_of_tricks >= 0 *)
3. Case suit of:
(*contract pts*)
H,M,N: pt_per_tricks:=30 * dbl
C,D: pt_per_tricks:=20 * dbl
sum_pts:= pt_per_tricks
pt_per_tr
* contract
if suit=N then sum_pts+= 10
4. Case sum_pts of:
(*level bonus*)
0..50: lv_bonus:= 50
>100 : lv_bonus:= 300 + 200 * vunl
if cont=6 then lv_bonus+= 500 + 250 * vunl
else if cont=7 then lv_bonus+= 1000 + 500 * vunl
sum_pts += lv_bonus
5. Case dbl of :
(* overtricks *)
1: pt_per_overtrks:= pt_per_tricks
2: pt_per_overtrks:= 100 + 100 * vunl , sum_pts+=50
4: pt_per_overtrks:= 200 + 200 * vunl,
vunl sum_pts+=100
sum_pts += pt_per_overtrks * num_of_tricks
(* if num_of_tricks < 0 *)
6. num_of_tricks = -num_of_tricks
num_of_tricks
if vunl=num_of_tricks then
sum_pts:=200*dbl/2;
else
Page 2
WYKSCT
Case of dbl:
1: sum_pts:= 50 * num_of_tricks * (1+vnul)
2,4: num_of_tricks+=vnul;
if num_of_tricks<=3 then
th
sum_pts:= [100 + (num_of_tricks
(num_of_tricks-1) * 200 ] * dbl/2;
else sum_pts:= [ 500 + 300 * (num_of_tricks
(num_of_tricks-3) ] * dbl/2;
This is the first draft (version) of the program, users are required to input the suit, the
vulnerability, the double constant, the level of contract, and finally the difference of number of
tricks made with respect to the number of tricks needed, then the score will be calculated and
stored as sum_pts.. However, although not reasonable enough, the Director seems
seem not satisfied
with step 4 stated above as it seems like that the step requires many if-statements
if statements to run, which
is not convenient enough for calculator
calculator-programming.
Second design
Before:
4. Case sum_pts of:
(*level bonus*)
0..50: lv_bonus:= 50
>100 : lv_bonus:= 300 + 200 * vunl
if cont=6 then lv_bonus+= 500 + 250 * vunl
else if cont=7 then lv_bonus+= 1000 + 500 * vunl
sum_pts += lv_bonus
5. Case dbl of :
(* overtricks *)
1: pt_per_overtrks:= pt_per_tricks
2: pt_per_overtrks:=
pt_per_overtrks 100 + 100 * vunl , sum_pts+=50
4: pt_per_overtrks:= 200 + 200 * vunl , sum_pts+=100
sum_pts += pt_per_overtrks * num_of_tricks
(* if num_of_tricks < 0 *)
6. num_of_tricks = -num_of_tricks
num_of_tricks
Case of dbl:
1: sum_pts:= 50 * num_of_tricks
num_of_tri * (1+vnul)
2,4: num_of_tricks+=vnul;
if num_of_tricks<=3 then
sum_pts:= [100 + (num_of_tricks
(num_of_tricks-1) * 200 ] * dbl/2;
else sum_pts:= [ 500 + 300 * (num_of_tricks
(num_of_tricks-3) ] * dbl/2;
After:
4. if cont>=6 then sum_pts += (500 + 250 * vunl) (cont - 5) + 300
else if sum_pts>100 then sum_pts += 300 + 200 * vunl
else sum_pts += 50;
5. Case dbl of :
(* overtricks *)
1: pt_per_overtrks:= pt_per_tricks
2,4: pt_per_overtrks:= ( 100 + 100 * vunl ) * dbl/2,, sum_pts+=dbl/2*50
sum_pts += pt_per_overtrks * num_of_tricks
(* if num_of_tricks < 0 *)
6. num_of_tricks = -num_of_tricks
num_of_tricks
Page 3
WYKSCT
if vunl=num_of_tricks then
sum_pts:=200*dbl/2;
else
Case of dbl:
1: sum_pts:=
:= 50 * num_of_tricks * (1+vnul)
2,4: num_of_tricks+=vnul;
if num_of_tricks<=3 then
sum_pts:= [100 + (num_of_tricks
(num_of_tricks-1) * 200 ] * dbl/2;
else sum_pts:= [ 500 + 300 * (num_of_tricks
(num_of_tricks-3) ] * dbl/2;
This design has one less variable (lv_bonus)
(
) declared then the first one, and it combined some
cases into one. By the way, thanks for David Lau for discovering the bug of Doubled/Re-Doubled
Doubled/Re
Vulnerable Down 1.
Flow in diagram
First design
Using DiagramDesigner (http://meesoft.logicnet.dk/DiagramDesigner
http://meesoft.logicnet.dk/DiagramDesigner),
), a flow diagram is made
which is shown on the next page.
This flow is slightly different from the flow shown above. The Director thought that it would be
more user-friendly
friendly to ask how many tricks has the pair won, and calculate the num_of_tricks
above.
to-run.
run. However, during coding process (keying into calculator), it
This flow is already ready-to
seems that some steps are redundant. For instance,
instance, if suit equals 1, suit will not equals 3. As a
good habit for programmers and In order to have a faster computation speed, the flow is a little
bit more modified, and that is the version that we are using now.
Second design
The flow is mostly the same,
ame, except the “selection of suit” part in calculating trick score and the
“slam” part of adding the “game
game-score”.. The order of entering the details has changed so that it
is according to the order of record, i.e. 3NTxx-1
3NTxx Vulnerable should be entered as 3, 3 (for NT), 2
(for number of times doubled), -1,
1, and 1. The flow diagram is also on the next page.
Bid
3
NT
xx
-1
Vulnerable
Input
3
3
2
-1
1
Bid
4
♠
+2
Non-Vulnerable
Vulnerable
Input
4
2
0
2
1
Bid
3
NT
xx
-1
Vulnerable
Input
3
3
2
-1
1
Page 4
WYKSCT
Figure 1 - First Draft
Page 5
Figure 2 - Second Draft
WYKSCT
Result program
On the day of WYKBC joint school activity with Good Hope School, we used the program for
calculating score, and it has shown its power in calculating some scores which are not written in
the scoring card, for example, 3NT+3.
The Director recommended FX-50FH
FX
because it has the syntax for “if-else” statement, which is
more convenient than using Lbl (Label) and Goto to complete the desired program.
FX-50FH
(SD-Mode version) (Mode-4)
4)
ClrStat: ?→A: ?→B: ?→C: ?→D: ?→X: D<0 ֜ Goto 0: 2^(C→Y: If B=1: Then 20Y
20 →Y: Else B=3 ֜
10×2^(C DT: 30Y→Y: Ifend:
d: YA DT: A≥6 ֜ 250(2+X)(A-5 DT: If ∑x≥100: Then 300+200X
300+200 DT: Else 50 DT:
Ifend: If C≠0: Then 100C(1+X
X→M: Else Y→M: Ifend: DM+50C DT: Goto 1: Lb
bl 0: -D→M: X=M ֜
Goto 2: C=0 ֜ Goto 3: M+X
X→M: If M≤3: Then 100C(1+2(M-1 DT: Else 100C(5+C(M-3
100C(5+C(M DT: Ifend:
Goto 1: Lbl 3: 50M(1+X DT: Goto 1: Lbl 2: 100
100×2(C DT: Lbl 1: ∑x
Less than 250 memory space is needed.
FX-3650P
(SD-Mode
Mode is still needed) (Mode-Mode-1)
(Mode
ClrStat: ?→A: ?→B: ?→C: ?→D: ?→X: D<0 ֜ Goto 0: 2^(C→Y: B=1 ֜ 20Y→Y ֜ Goto 4: B=3 ֜
10×2^(C DT: 30Y→Y: Lbl 4:: YA DT: A≥6 ֜ 250(2+X)(A-5 DT: ∑x≥100֜300+200X DT ֜Goto 5: 50 DT:
Lbl 5: C≠0֜100C(1+X→M֜Goto 6: Y→M: Lbl 6: DM+50C DT: Goto 1: Lbl 0: -D→M: X=M ֜
Goto 2: C=0 ֜ Goto 3: M+X→M: M≤3֜100C(1+2(M-1 DT ֜Goto 7: 100C(5+C(M-3
100C(5+C(M
Goto 1: Lbl 3: 50M(1+X DT: Goto 1: Lbl 2: 100
100×2(C DT: Lbl 1: ∑x
DT:Lbl
7:
This is only a translated version of the original FX
FX-50FH program. The “translation
translation” is done by
replacing If {a}: Then {b}: Else {c}: Ifend: by {a}֜{b}֜Goto n: {c}: Lbl n: .
This version is not tested. Therefore, if you encounter any bugs, please feel free to contact the
SCT via sct@wyk.edu.hk.. Thank you.
Reflection
We are glad to have this as our first non-official
non official report since we can train ourselves and help
others at the same time. This project inspired us to consider helping other students by teaching
calculator-programming.
programming. Please do not be shy to contact us if you are interested.
Page 6
WYKSCT
Download