From 3fe24df1237a77549ba64c6331383a9a40aed1de Mon Sep 17 00:00:00 2001 From: emkael Date: Sat, 25 Nov 2017 16:15:54 +0100 Subject: Initial BigDeal sources --- binomial.c | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 binomial.c (limited to 'binomial.c') diff --git a/binomial.c b/binomial.c new file mode 100644 index 0000000..7e565c1 --- /dev/null +++ b/binomial.c @@ -0,0 +1,139 @@ +#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; + } + } +} -- cgit v1.2.3