|
|
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 p
Length: 1823 (0x71f)
Types: TextFile
Names: »play.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
└─⟦this⟧ »EUUGD18/General/Nobs/play.c«
#include "defs.h"
#include "globs.h"
#include "window.h"
static taketurn();
playgame()
{
char k;
score[0]=score[1]=0;
resetpegs();
for (gameover=0; !gameover; ) playhand();
mvwprintw(Prompt, 0, 0, score[0]>120? "I win.\n": "You win.\n");
wrefresh(Prompt);
sleep(2);
mvwprintw(Prompt, 1, 0, "Another game?\n");
wmove(Prompt, 1, 41);
wrefresh(Prompt);
k = wgetch(Prompt);
if (k != 'y' && k != 'Y') quitflag = 1;
}
playhand()
{
int i, j;
dealer = !dealer;
deal();
werase(Pscore);
werase(Hscore);
showhand();
ncrib=0;
for (i=0; i<2; i++) {
(*dscfunc[playertype[i]])(hand[i], i==dealer);
}
showfour();
showcut();
if (RANK(cut)==KNAVE) {
mvwprintw(Prompt, 1, 0, "Two for His Heels\n");
wrefresh(Prompt);
sleep(2);
SCOREUP(dealer, 2);
sleep(1);
}
whoseturn = dealer; /* to be reversed */
handover = 0;
nleft[0]=nleft[1]=4;
resetgo();
for (i=0; i<2; i++) for (j=0; j<4; j++) played[i][j]=0;
while (!gameover && !handover) taketurn();
if (gameover) return;
gamescore();
}
static
taketurn()
{
whoseturn = !whoseturn;
switch (playertype[whoseturn]) {
case HUMAN:
humanplay();
break;
case PROGRAM:
programplay();
break;
}
}
int
goodgo(who)
int who;
{
int i;
for (i=0; i<4; i++) if (goodplay(who, i)) return 0;
return 1;
}
int
goodplay(who, which)
int who, which;
{
return !played[who][which] &&
rankvalue[RANK(hand[who][which])] + count <= 31;
}
resetgo() {
count=gocount=0;
whosego = -1;
mvwprintw(Prompt, 0, 0, "0.\n");
wrefresh(Prompt);
}
/*
* Returns nonzero if wins.
*/
scoreup(who, n)
int who, n;
{
score[who] += n;
setpegs(who);
return (score[who] > 120);
}
/*
* assumes a<b.
*/
makediscard(hand, a, b)
int a, b;
CARD hand[];
{
crib[ncrib++] = hand[a];
crib[ncrib++] = hand[b];
hand[b]=hand[5];
hand[a]=hand[4]; /* In this order only. */
}