Yes, odd handles the odd tricks and after I posted it I realized that
for readability I should have split it into above-the-line and 
below-the-line as

'below above' =. (2^dbl) * (10 0 * suit=4) + (level,y) * suit { 2 3 # 20 30

and then {.odd and {:odd could be replaced.

Hey, wait, I didn't include the partscore bonus!  I'll append a fixed 
version.

To handle rubber bridge or Chicago, you have other considerations:
0. most games still allow honors;
1. You need to be able to specify the partscore bonus: 0 except for the 
last hand, then 300 (or whatever local custom calls for);
2. You might need to consider that some old-fashioned players don't 
accept the scoring changes of 1987; for them doubled nonvulnerable 
undertricks go 1-3-5-7... , and 50 for the insult is not changed to 100 
when there is a redouble.
3. As you say, you would need to pass in any existing partscore.  Maybe 
you would add on to x, making it
'level suit vul dbl leg psbonus' =. 6 {. x


Second version below

Henry Rich

NB. score bridge (duplicate and Chicago)
NB. x is contract: level suit vul dbl [leg partscorebonus]
NB. suit is 0=C, 4=NT
NB. dbl is 0, 1, or 2
NB. y is result, neg=down, nonneg=made
NB. result is score for contracting side
NB. Does not support honors
bridgescore =: 4 : 0"1 0
'level suit vul dbl leg psb' =. x , (#x) }. 0 0 0 0 0 50
if. y < 0 do.
   if. dbl do.
     dbl * 100 + (y * 300) - 100 * ((y * -.vul) >. _2)
   else.
     y * vul { 50 100
   end.
else.
   'b a' =. (2^dbl) * (10 0 * suit=4) + (level,y) * suit { 2 3 # 20 30
   pts =. (dbl * 50) + b + (100 <: leg+b) { psb , vul { 300 500
   pts =. pts + (<vul,level) { _8 {."1 ] 500 1000 ,: 750 1500
   pts =. pts + dbl { a , (>:vul) * y * 100 200
end.
)



Brian Schott wrote:
> Henry,
> 
> Yes, I like your crisp code very much. I want to alter it to
> accommodate existing part scores and splitting the result into above-
> and below-the-line portions.
> 
> It seems that the temporary noun `odd` produces the below-the-line
> portion as its first element, right? And that could be partitioned
> from the final result to produce the two parts?
> 
> On the other hand if the existing part scores were appended to the y
> argument, making it a vector argument, wouldn't that be a way to
> produce a multipart `result` that would resemble the resulting score,
> at least for winning contracts?
> 
> Thank you so much for sharing this code.
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> 
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to