#include #include #include static unsigned int runners,ru,q,*scratched,*a,*b,*c,*ah,*bh,*ch,*p; static float *v,*bet,*g,*ralph,*books; static char pins[256]=""; void menu(void); void input_odds(void); void calc_sing_trif_odds(void); void pin(void); void couple(void); void replace(float rep,float with,int ci,int q,float cbet); int evalpin(int i,int j,int k,int poss,int posf); main(void) { bbc_mode(0); menu(); return 0; } void menu(void) { unsigned char cha,dum; do { bbc_cls(); printf("\n\n\n\n\n\n\n\n"); printf(" Trifectas Menu\n"); printf(" -================-\n\n"); printf("\n"); printf(" 1. Input odds\n\n"); printf(" 2. Pin horses\n\n"); printf(" 3. Calculate bets\n\n"); printf(" 4. Group bets\n\n"); printf(" 5. End\n\n"); printf("\n"); printf(" Enter the number of your choice :"); do scanf("%c",&cha); while (cha<'1' || cha>'5'); scanf("%c",&dum); switch(cha) { case '1': input_odds(); break; case '2': pin(); break; case '3': calc_sing_trif_odds(); break; case '4': couple(); break; } } while (cha!='5'); } void input_odds(void) { unsigned int i,noscr,scrh; unsigned char yn,dum; bbc_cls(); printf("How many runners ? "); do { scanf("%i",&runners); } while (runners<3); scanf("%c",&dum); ru=runners*runners*runners; v=malloc(sizeof(float)*(ru+1)); a=malloc(sizeof(int)*(ru+1)); b=malloc(sizeof(int)*(ru+1)); c=malloc(sizeof(int)*(ru+1)); bet=malloc(sizeof(float)*(ru+1)); g=malloc(sizeof(float)*(ru+1)); p=malloc(sizeof(int)*(ru+1)); ah=malloc(sizeof(int)*(runners+1)); bh=malloc(sizeof(int)*(runners+1)); ch=malloc(sizeof(int)*(runners+1)); scratched=malloc(sizeof(int)*(runners+1)); ralph=malloc(sizeof(float)*(runners+1)); books=malloc(sizeof(float)*(runners+1)); if (!v || !a || !b || !c || !bet || !g || !p || !ah || !bh || !ch || !scratched || !ralph || !books) { printf("Memory request failed\n"); printf("Exiting ...\n"); exit(1); } for(i=0;i<=ru;++i) { v[i]=0; a[i]=0; b[i]=0; c[i]=0; bet[i]=0; g[i]=0; p[i]=0; } for(i=0;i<=runners;++i) { ah[i]=0; bh[i]=0; ch[i]=0; scratched[i]=0; ralph[i]=0; books[i]=0; } printf("Any scratchings (Y/N) ? "); scanf("%c",&yn); if (yn=='y' || yn=='Y') { printf("How many horses have been scratched ? "); scanf("%i",&noscr); for (scrh=1;scrh<=noscr;++scrh) { printf("Enter horse number to be scratched : "); scanf("%i",&i); scratched[i]=1; } } else { noscr=0; } bbc_cls(); printf("Now input the odds :\n"); for (i=1;i<=runners;++i) { if (!scratched[i]) { printf("Your odds for number %i : ",i); scanf("%f",&ralph[i]); printf("Book odds for number %i : ",i); scanf("%f",&books[i]); } } printf("\n"); printf("Any errors (Y/N) ? "); scanf("%c",&yn); while (yn=='y' || yn=='Y') { printf("Which number ? "); scanf("%i",&i); printf("Your odds for number %i : ",i); scanf("%f",&ralph[i]); printf("Book odds for number %i : ",i); scanf("%f",&books[i]); printf("\n"); printf("Any more errors (Y/N) ? "); scanf("%c",&yn); } } void calc_sing_trif_odds(void) { float collect,coff,bettot,oddsr,oddsb,r,per,two,three,trif; unsigned int i,j,k; unsigned char cha,dum; do { bbc_cls(); printf("How much do you want to collect ? $"); scanf("%f",&collect); printf("What is your cut-off ratio ? "); scanf("%f",&coff); printf("\n"); printf("The computer is now calculating the odds\n"); printf("Please wait ...\n"); q=0; bettot=0; for (i=1;i<=runners;++i) { if (!scratched[i]) { for (j=1;j<=runners;++j) { if (!scratched[j] && i!=j) { for (k=1;k<=runners;++k) { if (!scratched[k] && i!=k && j!=k) { oddsr=ralph[i]*ralph[j]*ralph[k]; oddsb=books[i]*books[j]*books[k]; r=oddsb/oddsr; if (r>=coff && evalpin(i,j,k,0,255)==1) { per=100/(ralph[i]+1); two=(100-per)/(100/(ralph[j]+1)); three=(100-per-100/(ralph[j]+1))/(100/(ralph[k]+1)); trif=(ralph[i]+1)*two*three; ++q; bet[q]=(float) collect/(trif); bet[q]=(float) ((int) (bet[q]*2))/2; bettot+=bet[q]; v[q]=r; a[q]=i; b[q]=j; c[q]=k; } } } } } } } bbc_cls(); printf("There are %d bets with a ratio of %f or greater\n",q,coff); printf("For a total outlay of $%f to collect $%f\n",bettot,collect); printf("\n"); printf("'U'se these bets or try 'A'nother cut off ratio or 'M'enu ? "); do scanf("%c",&cha); while (cha!='u' && cha!='U' && cha!='a' && cha!='A' && cha!='m' && cha!='M'); scanf("%c",&dum); printf("\n"); } while (cha=='a' || cha=='A'); if (cha!='m' && cha!='M') { do { for (i=1;i<=q;++i) { if (((int) i/21)==((float) i/21)) { printf("\n"); printf("Hit return to continue ..."); scanf("%c",&cha); printf("\n"); } printf("%i / %i / %i%5.1f ................ $%0.2f\n",a[i],b[i],c[i],v[i],bet[i]); } printf("\n"); printf("Do you want to see these odds again (Y/N) ? "); do scanf("%c",&cha); while (cha!='y' && cha!='Y' && cha!='n' && cha != 'N'); scanf("%c",&dum); printf("\n"); } while (cha=='y' || cha=='Y'); } printf("Hit return for the menu ..."); scanf("%c",&cha); } void pin(void) { bbc_cls(); printf("\n\n\n\n\n\n\n\n\n\n\n"); printf("Pinnings code strings have a number of different components. Firstly, a horse number followed by either 'f', 's' or 't' pins a horse to run first, second or third respectively. These basic components are bound into expressions using thebinary operators '|' (or) and '&' (and). In addition there is one unary operation, '!' (not), which will invert the value of the entire expression so far. Order of operations is normally left to right, but parenthesis, '(' and ')', may be used to enclose a sub-expression. If only a small part of the total expression is to be inverted using '!', this small part would go into parenthesis, along with a '!' just before the ')'. Spaces must not occur in pinnings code strings.\n\n"); printf("Enter your pinnings code string :"); scanf("%s",pins); } void couple(void) { unsigned int n,r,fin,i,cj,j,nu,bs,ok,adda,addb,addc,ai,bi,ci,cn,ln,cma,t,line; float cbet; unsigned char cha; bbc_cls(); if (q==0) { printf("No bets to group.\n"); printf("\n"); printf("Hit return to continue ..."); scanf("%c",&cha); return; } printf("Sorting ...\n"); for (n=1;n<=q;++n) p[n]=n; r=q-1; do { fin=1; for (n=1;n<=r;++n) { if (bet[p[n]]0); printf("Grouping ...\n"); printf("\n"); line=0; for (n=1;n<=q;++n) g[p[n]]=0; cbet=0; for (n=1;n<=q;++n) { i=p[n]; if (g[i]==0) { for (nu=1;nu<=runners;++nu) { ah[nu]=0; bh[nu]=0; ch[nu]=0; } ah[a[i]]=1; bh[b[i]]=1; ch[c[i]]=1; if (bet[i]!=cbet) { cbet=bet[i]; bs=n; } g[i]=-1; if (i='0' && pins[p]<='9') h=10*h+(pins[p]-'1'+1); if (pins[p]=='f') { if (i==h && op==0) val=1; if (i!=h && op==1) val=0; } if (pins[p]=='s') { if (j==h && op==0) val=1; if (j!=h && op==1) val=0; } if (pins[p]=='t') { if (k==h && op==0) val=1; if (k!=h && op==1) val=0; } if (pins[p]<'0' || pins[p]>'9') h=0; if (pins[p]=='&') op=1; if (pins[p]=='|') op=0; if (pins[p]=='!') { if (val==0) val=1; else val=0; } if (pins[p]=='(') { bdpth=0; q=p; do { if (pins[q]=='(') ++bdpth; if (pins[q]==')') --bdpth; ++q; } while (q<=posf && bdpth!=0); if (bdpth!=0) { printf("Unmatched brackets in pinnings code\n"); exit(1); } if (op==0) val=val || evalpin(i,j,k,p+1,q-2); else val=val && evalpin(i,j,k,p+1,q-2); p=q-1; } ++p; } return val; }