DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T g

⟦f95befe7b⟧ TextFile

    Length: 6373 (0x18e5)
    Types: TextFile
    Names: »game.c«

Derivation

└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
    └─⟦this⟧ »EUUGD18/General/Yahtzee/game.c« 

TextFile

#include "types.h"

extern Game player[];

static int dice[5];
static int mark[5];
static int ys[] = {1, 2, 3, 4, 5, 6, 8, 10, 11, 12, 13, 14, 15, 16};
static char *more = " is the winner.  Play another game (Y/N) ? ";

static char *cd[] = {
	"-------",
	"|     |",
	"|  o  |",
	"|     |",
	"-------",
	"-------",
	"|o    |",
	"|     |",
	"|    o|",
	"-------",
	"-------",
	"|o    |",
	"|  o  |",
	"|    o|",
	"-------",
	"-------",
	"|o   o|",
	"|     |",
	"|o   o|",
	"-------",
	"-------",
	"|o   o|",
	"|  o  |",
	"|o   o|",
	"-------",
	"-------",
	"|o   o|",
	"|o   o|",
	"|o   o|",
	"-------"
};

clrroll()
{
	int i;

	for(i=0; i<5; i++) {
		mark[i] = 0;
		mvaddstr(i*4+2, 58, " ");
	}
	refresh();
}

roll()
{
	int i;

	for(i=0; i<5; i++) {
		if(mark[i] == 0) {
			dice[i] = get_rand();
			spot(i,dice[i]-1);
		}
	}
	refresh();
}

spot(i,n)
int i,n;
{
	int j,k,m;

	j = i*4;
	m = n*5;
	for(k=0; k<5; k++) mvaddstr(j+k, 60, cd[m+k]);
}

choose()
{
	int c,choice,old,i;

	for(choice=0; choice<5; choice++) if(mark[choice] == 0) break;
	mvaddstr(choice*4+2, 53, "->");
	refresh();
	old = choice;
	while(1) {
		c = key();
		if(c == '\r') {
			mvaddstr(choice*4+2, 53, "  ");
			refresh();
			break;
		}
		switch (c) {
		case 'X':
		case 'x':
			mark[choice] = 1;
			mvaddstr(choice*4+2, 58, "X");
			refresh();
			if(++choice == 5) choice = 0;
			break;
		case ' ':
			mark[choice] = 0;
			mvaddstr(choice*4+2, 58, " ");
			refresh();
		case 'j':
		case 'J':
		case DN_ARROW:
			if(++choice == 5) choice = 0;
			break;
		case 'k':
		case 'K':
		case UP_ARROW:
			if(--choice < 0) choice = 4;
			break;
		default:
			DisplayBeep(0);
			break;
		}
		mvaddstr(old*4+2, 53, "  ");
		mvaddstr(choice*4+2, 53, "->");
		refresh();
		old = choice;
	}
	for(i=0; i<5; i++) if(mark[i] == 0) return(0);
	return(1);
}

makechoice(n)
int n;
{
	int c, choice, old, count, counts[6], f1, f2, f3, f4, f5, i, j;
	char s[4];

	for(choice=0; choice<NS; choice++)
		if(player[n].score[choice] == -1) break;
	mvaddstr(ys[choice], 0, "->");
	refresh();
	old = choice;
	while(1) {
		c = key();
		if(c == '\r') {
			mvaddstr(ys[old], 0, "  ");
			refresh();
			break;
		}
		switch (c) {
		case 'k':
		case 'K':
		case UP_ARROW:
			do {
				if(--choice < 0) choice = NS-1;
			} while(player[n].score[choice] >= 0 || choice == 6);
			break;
		case 'j':
		case 'J':
		case DN_ARROW:
			do {
				if(++choice == NS) choice = 0;
			} while(player[n].score[choice] >= 0 || choice == 6);
			break;
		default:
			DisplayBeep(0);
			break;
		}
		mvaddstr(ys[old], 0, "  ");
		mvaddstr(ys[choice], 0, "->");
		refresh();
		old = choice;
	}
	player[n].score[choice] = 0;
	for(j=1; j<=6; j++) {
		count = 0;
		for(i=0; i<5; i++)
			if(dice[i] == j) count++;
		if(count == 5) player[n].ycount++;
	}
	switch (choice) {
	case 0: case 1: case 2: case 3: case 4: case 5:		/* points */
		for(i=0; i<5; i++)
			if(dice[i] == choice+1)
				player[n].score[choice] += dice[i];
		f1=1;
		count = 0;
		for(i=0; i<6; i++)
			if(player[n].score[i] >=0)
				count += player[n].score[i];
			else f1=0;
		sprintf(s,"%d",count);
		mvaddstr(ys[5]+1, FC+n*COLW, "   ");
		mvaddstr(ys[5]+1, FC+n*COLW, s);
		refresh();
		if(f1) {
			if(count >= 63) {
				player[n].score[6] = 35;
				mvaddstr(ys[6], FC+n*COLW, "35");
				refresh();
			} else player[n].score[6] = 0;
		}
		break;
	case 13:		/* chance */
		for(i=0; i<5; i++) player[n].score[13] += dice[i];
		break;
	case 7:			/* 3 of a kind */
	case 8:			/* 4 of a kind */
	case 12:		/* yahtzee */
		for(j=1; j<=6; j++) {
			count = 0;
			for(i=0; i<5; i++)
				if(dice[i] == j) count++;
			if(choice == 7) {
				if(count >= 3)
					for(i=0; i<5; i++) player[n].score[7] += dice[i];
			} else if(choice == 8) {
				if(count >= 4)
					for(i=0; i<5; i++) player[n].score[8] += dice[i];
			} else {
				if(count == 5) player[n].score[12] = 50;
			}
		}
		break;
	case 9:			/* full house */
		for(j=0; j<6; j++) {
			counts[j] = 0;
			for(i=0; i<5; i++)
				if(dice[i] == j+1) counts[j] += 1;
		}
		f1 = f2 = 0;
		for(i=0; i<6; i++) if(counts[i] == 3) f1 = 1;
		for(i=0; i<6; i++) if(counts[i] == 2) f2 = 1;
		if(f1 && f2) player[n].score[9] = 25;
		break;
	case 10:		/* small straight */
		f1 = f2 = f3 = f4 = 0;
		for(i=0; i<5; i++) {
			if(dice[i] == 1) f1 = 1;
			if(dice[i] == 2) f2 = 1;
			if(dice[i] == 3) f3 = 1;
			if(dice[i] == 4) f4 = 1;
		}
		if(f1 && f2 && f3 && f4) {
			player[n].score[10] = 30;
			break;
		}
		f1 = f2 = f3 = f4 = 0;
		for(i=0; i<5; i++) {
			if(dice[i] == 2) f1 = 1;
			if(dice[i] == 3) f2 = 1;
			if(dice[i] == 4) f3 = 1;
			if(dice[i] == 5) f4 = 1;
		}
		if(f1 && f2 && f3 && f4) {
			player[n].score[10] = 30;
			break;
		}
		f1 = f2 = f3 = f4 = 0;
		for(i=0; i<5; i++) {
			if(dice[i] == 3) f1 = 1;
			if(dice[i] == 4) f2 = 1;
			if(dice[i] == 5) f3 = 1;
			if(dice[i] == 6) f4 = 1;
		}
		if(f1 && f2 && f3 && f4) {
			player[n].score[10] = 30;
			break;
		}
		break;
	case 11:
		f1 = f2 = f3 = f4 = f5 = 0;
		for(i=0; i<5; i++) {
			if(dice[i] == 2) f1 = 1;
			if(dice[i] == 3) f2 = 1;
			if(dice[i] == 4) f3 = 1;
			if(dice[i] == 5) f4 = 1;
			if(dice[i] == 6) f5 = 1;
		}
		if(f1 && f2 && f3 && f4 && f5) {
			player[n].score[11] = 40;
			break;
		}
		f1 = f2 = f3 = f4 = f5 = 0;
		for(i=0; i<5; i++) {
			if(dice[i] == 1) f1 = 1;
			if(dice[i] == 2) f2 = 1;
			if(dice[i] == 3) f3 = 1;
			if(dice[i] == 4) f4 = 1;
			if(dice[i] == 5) f5 = 1;
		}
		if(f1 && f2 && f3 && f4 && f5) {
			player[n].score[11] = 40;
			break;
		}
		break;
	}
	sprintf(s,"%d",player[n].score[choice]);
	mvaddstr(ys[choice], FC+n*COLW, s);
	refresh();
}

winner(n)
int n;
{
	int i,j,k1,k2,k3,tots[4],max;
	char s[4];

	for(i=0; i<n; i++) {
		k3 = (player[i].ycount - 1) * 100;
		if(k3) {
			sprintf(s,"%d",k3);
			mvaddstr(17, FC+i*COLW, s);
		}
		k1 = 0;
		for(j=0; j<7; j++) k1 += player[i].score[j];
		sprintf(s, "%d", k1);
		mvaddstr(19, FC+i*COLW, s);
		k2 = 0;
		for(j=7; j<NS; j++) k2 += player[i].score[j];
		sprintf(s,"%d",k2);
		mvaddstr(20, FC+i*COLW, s);
		tots[i] = k1 + k2 + k3;
		sprintf(s,"%d",tots[i]);
		mvaddstr(22, FC+i*COLW, s);
	}
	refresh();
	max = tots[0];
	j = 0;
	for(i=1; i<n; i++)
		if(tots[i] > max) {
			j = i;
			max = tots[i];
		}
	sprintf(s, "%d", max);
	mvaddstr(22, FC+j*COLW, s);
	move(23,0);
	clrtoeol();
	addstr(player[j].name);
	addstr(more);
	refresh();
	k1 = strlen(player[j].name) + strlen(more);
	return(yes(23,k1));
}