#include "types.h" #include "bigdeal.h" #include "mp.h" static char rcsid[] = "$Header: /home/sater/bridge/bigdeal/RCS/binomial.c,v 1.11 2000/08/16 15:06:30 sater Exp $"; /* * functions implementing or using the (n over k) mathematical construct */ static byte pascal_triangle[NCARDSPERDECK+1][NCARDSPERHAND+1][L]; void binomial_start() /* * Precomputes all numbers (n over k) with k<=NCARDSPERHAND and * n<=NCARDSPERDECK. * Numbers are stored in pascal_triangle[][] with L bytes precision (96 bits) * * Calculation method is the addition from the top of the triangle * where the equation: * n_over_k(n,k) = n_over_k(n-1, k-1) + n_over_k(n-1, k) * except for some boundary condition situations */ { int i,j,min; for (i=0; i<=NCARDSPERDECK; i++) { if (idn_num); for (compass=COMPASS_NORTH; compass g */ if (mp96_cmp(tmp2, g) > 0) break; } n_over_k(13*(NCOMPASS-compass)-a-j, 13-j, tmp1); n_over_k(13*(NCOMPASS-compass)-b-j, 13-j, tmp2); mp96_sub(tmp3, tmp1, tmp2); /* * tmp1 is assigned the value x_j */ mp96_mul(tmp1, tmp3, c); /* * g_j = g_{j-1} - x_j */ mp96_sub(g, g, tmp1); dip->di_hand[compass][j] = b; /* * a is set to a_j */ a = b; } } }