|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T g
Length: 3455 (0xd7f) Types: TextFile Names: »gamescore.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987 └─⟦this⟧ »EUUGD18/General/Nobs/gamescore.c«
#include "defs.h" #include "globs.h" #include "window.h" gamescore() { sleep(2); handscore(!dealer); if (!gameover) { sleep(2); handscore(dealer); } if (!gameover) { sleep(1); werase(Pscore); werase(Hscore); exposecrib(); sleep(2); cribscore(); } } handscore(who) int who; { int i; CARD dummy[5]; for (i=0; i<4; i++) dummy[i]=hand[who][i]; dummy[4]=cut; evalhand(dummy, 0, who); } cribscore() { int i; CARD dummy[5]; for (i=0; i<4; i++) dummy[i]=crib[i]; dummy[4]=cut; evalhand(dummy, 1, dealer); } int evalhand(ehand, iscrib, whoscore) CARD ehand[]; int iscrib; int whoscore; /* -1 means silent */ { /* * If iscrib is on, don't allow four-flushes. */ int i, j, mask, bit, hmask, sum, hcount; char *runname; int runval; short rep[15]; /* Extra zeroes make it easier */ WINDOW *Win; if (whoscore==1) Win=Hscore; else if (whoscore==0) Win=Pscore; if (iscrib && whoscore>=0) { wprintw(Win, "%s Crib:\n", whoscore? "Your": "My"); wrefresh(Win); sleep(1); } hcount=0; for (mask=1; mask<32; mask++) { hmask=mask; sum=0; for (bit=0; bit<5; bit++) { if (1&hmask) sum+=rankvalue[RANK(ehand[bit])]; hmask >>= 1; } if (sum==15) { hcount += 2; if (whoscore>=0) { wprintw(Win, "Fifteen-%d\n", hcount); wrefresh(Win); sleep(1); } } /* * Need we add any cards? */ if (sum >= 15) mask |= mask-1; } /* * Count the ranks. */ for (i=0; i<15; i++) rep[i]=0; for (i=0; i<5; i++) rep[RANK(ehand[i])]+=1; /* * Look for isolated pairs, etc. */ for (i=1; i<14; i++) if (rep[i]>1) { if (!(rep[i-1] && (rep[i-2] || rep[i+1]) || rep[i+1] && rep[i+2])) { hcount += pairvalue[rep[i]]; if (whoscore>=0) { wprintw(Win, "and a %s is %d\n", pairname[rep[i]], hcount); wrefresh(Win); sleep(1); } } } /* * Look for runs, including multiples. */ for (i=1; i<12; i++) if (rep[i]) { if (!rep[i+2]) { i+=2; continue; } if (!rep[i+1]) { i+=1; continue; } /* * We have a run! */ if (rep[i+3]) { if (rep[i+4]) { runname="Sequence of Five\n"; runval=5; } else { runname="Sequence of Four\n"; runval=4; for (j=i; j<i+4; j++) if (rep[j]>1) { runname="Double Sequence\n of Four"; runval=10; break; } } } else { for (sum=0, j=i; j<i+3; j++) { if (rep[j]==3) { runname="Triple Sequence"; runval=15; goto scorerun; } sum += rep[j]-1; } runname=drunname[sum]; runval=drunval[sum]; } scorerun: hcount += runval; if (whoscore>=0) { wprintw(Win, "and a %s is %d\n", runname, hcount); wrefresh(Win); sleep(1); } break; /* You can't have two runs */ } /* * Check for flushes. */ for (i=1; i<4; i++) if (!SAMESUIT(ehand[i],ehand[0])) goto endflush; if (SAMESUIT(ehand[4], ehand[0])) { hcount += 5; if (whoscore>=0) { wprintw(Win, "and a Flush of Five is %d\n", hcount); wrefresh(Win); sleep(1); } } else if (!iscrib) { hcount += 4; if (whoscore>=0) { wprintw(Win, "and a Flush is %d\n", hcount); wrefresh(Win); sleep(1); } } endflush: for (i=0; i<4; i++) if (RANK(ehand[i])==KNAVE && SAMESUIT(ehand[i], ehand[4])) { hcount += 1; if (whoscore>=0) { wprintw(Win, "and One for His Nobs is %d\n",hcount); wrefresh(Win); sleep(1); } break; } /* * Final reckoning, if wanted. */ if (whoscore>=0) { sleep(1); if (hcount) SCOREUP(whoscore, hcount); } return hcount; }