⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 canfield.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 3 页
字号:
		temp = *source;	*source = (*source)->next;	temp->next = *dest;	*dest = temp;}/* * Procedure to set the cards on the foundation base when available. * Note that it is only called on a foundation pile at the beginning of * the game, so the pile will have exactly one card in it. */fndbase(cp, column, row)	struct cardtype **cp;{	bool nomore;	if (*cp != NIL)		do {			if ((*cp)->rank == basecard->rank) {				base++;				printcard(pilemap[base], foundrow, *cp);				if (*cp == tableau[0])					length[0] = length[0] - 1;				if (*cp == tableau[1])					length[1] = length[1] - 1;				if (*cp == tableau[2])					length[2] = length[2] - 1;				if (*cp == tableau[3])					length[3] = length[3] - 1;				transit(cp, &found[base]);				if (cp == &talon)					usedtalon();				if (cp == &stock)					usedstock();				if (*cp != NIL) {					printcard(column, row, *cp);					nomore = FALSE;				} else {					removecard(column, row);					nomore = TRUE;				}				cardsoff++;				if (infullgame) {					this.wins += valuepercardup;					game.wins += valuepercardup;					total.wins += valuepercardup;				}			} else 				nomore = TRUE;	} while (nomore == FALSE);}/* * procedure to initialize the things necessary for the game */initgame(){	register i;	for (i=0; i<18; i++) {		deck[i]->visible = TRUE;		deck[i]->paid = TRUE;	}	stockcnt = 13;	stock = deck[12];	for (i=12; i>=1; i--)		deck[i]->next = deck[i - 1];	deck[0]->next = NIL;	found[0] = deck[13];	deck[13]->next = NIL;	for (i=1; i<4; i++)		found[i] = NIL;	basecard = found[0];	for (i=14; i<18; i++) {		tableau[i - 14] = deck[i];		deck[i]->next = NIL;	}	for (i=0; i<4; i++) {		bottom[i] = tableau[i];		length[i] = tabrow;	}	hand = deck[18];	for (i=18; i<decksize-1; i++)		deck[i]->next = deck[i + 1];	deck[decksize-1]->next = NIL;	talon = NIL;	base = 0;	cinhand = 34;	taloncnt = 0;	timesthru = 0;	cardsoff = 1;	coldrow = ctoprow;	coldcol = cinitcol;	cnewrow = ctoprow;	cnewcol = cinitcol + cwidthcol;}/* * procedure to print the beginning cards and to start each game */startgame(){	register int j;	shuffle(deck);	initgame();	this.hand = costofhand;	game.hand += costofhand;	total.hand += costofhand;	this.inspection = 0;	this.game = 0;	this.runs = 0;	this.information = 0;	this.wins = 0;	this.thinktime = 0;	infullgame = FALSE;	startedgame = FALSE;	printcard(foundcol, foundrow, found[0]);	printcard(stockcol, stockrow, stock);	printcard(atabcol, tabrow, tableau[0]);	printcard(btabcol, tabrow, tableau[1]);	printcard(ctabcol, tabrow, tableau[2]);	printcard(dtabcol, tabrow, tableau[3]);	printcard(taloncol, talonrow, talon);	move(foundrow - 2, basecol);	printw("Base");	move(foundrow - 1, basecol);	printw("Rank");	printrank(basecol, foundrow, found[0], 0);	for (j=0; j<=3; j++)		fndbase(&tableau[j], pilemap[j], tabrow);	fndbase(&stock, stockcol, stockrow);	showstat();	/* show card counting info to cheaters */	movetotalon();	updatebettinginfo();}/* * procedure to clear the message printed from an error */clearmsg(){	int i;	if (errmsg == TRUE) {		errmsg = FALSE;		move(msgrow, msgcol);		for (i=0; i<25; i++)			addch(' ');		refresh();	}}/* * procedure to print an error message if the move is not listed */dumberror(){	errmsg = TRUE;	move(msgrow, msgcol);	printw("Not a proper move       ");}/* * procedure to print an error message if the move is not possible */destinerror(){	errmsg = TRUE;	move(msgrow, msgcol);	printw("Error: Can't move there");}/* * function to see if the source has cards in it */boolnotempty(cp)struct cardtype *cp;{	if (cp == NIL) {		errmsg = TRUE;		move(msgrow, msgcol);		printw("Error: no cards to move");		return (FALSE);	} else 		return (TRUE);}/* * function to see if the rank of one card is less than another */boolranklower(cp1, cp2)	struct cardtype *cp1, *cp2;{	if (cp2->rank == Ace) 		if (cp1->rank == King)			return (TRUE);		else 			return (FALSE);	else if (cp1->rank + 1 == cp2->rank)		return (TRUE);	else 		return (FALSE);}/* * function to check the cardcolor for moving to a tableau */booldiffcolor(cp1, cp2)	struct cardtype *cp1, *cp2;{	if (cp1->color == cp2->color)		return (FALSE);	else 		return (TRUE);}/* * function to see if the card can move to the tableau */booltabok(cp, des)	struct cardtype *cp;{	if ((cp == stock) && (tableau[des] == NIL))		return (TRUE);	else if (tableau[des] == NIL)		if (stock == NIL && 		    cp != bottom[0] && cp != bottom[1] && 		    cp != bottom[2] && cp != bottom[3])			return (TRUE);		else 			return (FALSE);	else if (ranklower(cp, tableau[des]) && diffcolor(cp, tableau[des]))		return (TRUE);	else 		return (FALSE);}/* * procedure to turn the cards onto the talon from the deck */movetotalon(){	int i, fin;	if (cinhand <= 3 && cinhand > 0) {		move(msgrow, msgcol);		printw("Hand is now empty        ");	}	if (cinhand >= 3)		fin = 3;	else if (cinhand > 0)		fin = cinhand;	else if (talon != NIL) {		timesthru++;		errmsg = TRUE;		move(msgrow, msgcol);		if (timesthru != 4) {			printw("Talon is now the new hand");			this.runs += costofrunthroughhand;			game.runs += costofrunthroughhand;			total.runs += costofrunthroughhand;			while (talon != NIL) {				transit(&talon, &hand);				cinhand++;			}			if (cinhand >= 3)				fin = 3;			else				fin = cinhand;			taloncnt = 0;			coldrow = ctoprow;			coldcol = cinitcol;			cnewrow = ctoprow;			cnewcol = cinitcol + cwidthcol;			clearstat();			showstat();		} else {			fin = 0;			done = TRUE;			printw("I believe you have lost");			refresh();			sleep(5);		}	} else {		errmsg = TRUE;		move(msgrow, msgcol);		printw("Talon and hand are empty");		fin = 0;	}	for (i=0; i<fin; i++) {		transit(&hand, &talon);		INCRHAND(cnewrow, cnewcol);		INCRHAND(coldrow, coldcol);		removecard(cnewcol, cnewrow);		if (i == fin - 1)			talon->visible = TRUE;		if (Cflag) {			if (talon->paid == FALSE && talon->visible == TRUE) {				this.information += costofinformation;				game.information += costofinformation;				total.information += costofinformation;				talon->paid = TRUE;			}			printcard(coldcol, coldrow, talon);		}	}	if (fin != 0) {		printcard(taloncol, talonrow, talon);		cinhand -= fin;		taloncnt += fin;		if (Cflag) {			move(handstatrow, handstatcol);			printw("%3d", cinhand);			move(talonstatrow, talonstatcol);			printw("%3d", taloncnt);		}		fndbase(&talon, taloncol, talonrow);	}}/* * procedure to print card counting info on screen */showstat(){	int row, col;	register struct cardtype *ptr;	if (!Cflag)		return;	move(talonstatrow, talonstatcol - 7);	printw("Talon: %3d", taloncnt);	move(handstatrow, handstatcol - 7);	printw("Hand:  %3d", cinhand);	move(stockstatrow, stockstatcol - 7);	printw("Stock: %3d", stockcnt);	for ( row = coldrow, col = coldcol, ptr = talon;	      ptr != NIL;	      ptr = ptr->next ) {		if (ptr->paid == FALSE && ptr->visible == TRUE) {			ptr->paid = TRUE;			this.information += costofinformation;			game.information += costofinformation;			total.information += costofinformation;		}		printcard(col, row, ptr);		DECRHAND(row, col);	}	for ( row = cnewrow, col = cnewcol, ptr = hand;	      ptr != NIL;	      ptr = ptr->next ) {		if (ptr->paid == FALSE && ptr->visible == TRUE) {			ptr->paid = TRUE;			this.information += costofinformation;			game.information += costofinformation;			total.information += costofinformation;		}		INCRHAND(row, col);		printcard(col, row, ptr);	}}/* * procedure to clear card counting info from screen */clearstat(){	int row;	move(talonstatrow, talonstatcol - 7);	printw("          ");	move(handstatrow, handstatcol - 7);	printw("          ");	move(stockstatrow, stockstatcol - 7);	printw("          ");	for ( row = ctoprow ; row <= cbotrow ; row++ ) {		move(row, cinitcol);		printw("%56s", " ");	}}/* * procedure to update card counting base */usedtalon(){	removecard(coldcol, coldrow);	DECRHAND(coldrow, coldcol);	if (talon != NIL && (talon->visible == FALSE)) {		talon->visible = TRUE;		if (Cflag) {			this.information += costofinformation;			game.information += costofinformation;			total.information += costofinformation;			talon->paid = TRUE;			printcard(coldcol, coldrow, talon);		}	}	taloncnt--;	if (Cflag) {		move(talonstatrow, talonstatcol);		printw("%3d", taloncnt);	}}/* * procedure to update stock card counting base */usedstock(){	stockcnt--;	if (Cflag) {		move(stockstatrow, stockstatcol);		printw("%3d", stockcnt);	}}/* * let 'em know how they lost! */showcards(){	register struct cardtype *ptr;	int row;	if (!Cflag || cardsoff == 52)		return;	for (ptr = talon; ptr != NIL; ptr = ptr->next) {		ptr->visible = TRUE;		ptr->paid = TRUE;	}	for (ptr = hand; ptr != NIL; ptr = ptr->next) {		ptr->visible = TRUE;		ptr->paid = TRUE;	}	showstat();	move(stockrow + 1, sidecol);	printw("     ");	move(talonrow - 2, sidecol);	printw("     ");	move(talonrow - 1, sidecol);	printw("     ");	move(talonrow, sidecol);	printw("     ");	move(talonrow + 1, sidecol);	printw("     ");	for (ptr = stock, row = stockrow; ptr != NIL; ptr = ptr->next, row++) {		move(row, stockcol - 1);		printw("|   |");		printcard(stockcol, row, ptr);	}	if (stock == NIL) {		move(row, stockcol - 1);		printw("|   |");		row++;	}	move(handstatrow, handstatcol - 7);	printw("          ");	move(row, stockcol - 1);	printw("=---=");	if ( cardsoff == 52 )		getcmd(moverow, movecol, "Hit return to exit");}/* * procedure to update the betting values */updatebettinginfo(){	long thiscosts, gamecosts, totalcosts;	double thisreturn, gamereturn, totalreturn;	time_t now;	register long dollars;	time(&now);	dollars = (now - acctstart) / secondsperdollar;	if (dollars > 0) {		acctstart += dollars * secondsperdollar;		if (dollars > maxtimecharge)			dollars = maxtimecharge;		this.thinktime += dollars;		game.thinktime += dollars;		total.thinktime += dollars;	}	thiscosts = this.hand + this.inspection + this.game +		this.runs + this.information + this.thinktime;	gamecosts = game.hand + game.inspection + game.game +		game.runs + game.information + game.thinktime;	totalcosts = total.hand + total.inspection + total.game +		total.runs + total.information + total.thinktime;	this.worth = this.wins - thiscosts;	game.worth = game.wins - gamecosts;	total.worth = total.wins - totalcosts;	thisreturn = ((double)this.wins / (double)thiscosts - 1.0) * 100.0;	gamereturn = ((double)game.wins / (double)gamecosts - 1.0) * 100.0;	totalreturn = ((double)total.wins / (double)totalcosts - 1.0) * 100.0;	if (status != BETTINGBOX)		return;	move(tboxrow + 2, boxcol + 13);	printw("%4d%8d%9d", this.hand, game.hand, total.hand);	move(tboxrow + 3, boxcol + 13);	printw("%4d%8d%9d", this.inspection, game.inspection, total.inspection);	move(tboxrow + 4, boxcol + 13);	printw("%4d%8d%9d", this.game, game.game, total.game);	move(tboxrow + 5, boxcol + 13);	printw("%4d%8d%9d", this.runs, game.runs, total.runs);	move(tboxrow + 6, boxcol + 13);	printw("%4d%8d%9d", this.information, game.information,		total.information);	move(tboxrow + 7, boxcol + 13);	printw("%4d%8d%9d", this.thinktime, game.thinktime, total.thinktime);	move(tboxrow + 8, boxcol + 13);	printw("%4d%8d%9d", thiscosts, gamecosts, totalcosts);	move(tboxrow + 9, boxcol + 13);	printw("%4d%8d%9d", this.wins, game.wins, total.wins);	move(tboxrow + 10, boxcol + 13);	printw("%4d%8d%9d", this.worth, game.worth, total.worth);	move(tboxrow + 11, boxcol + 13);	printw("%4.0f%%%7.1f%%%8.1f%%", thisreturn, gamereturn, totalreturn);}/* * procedure to move a card from the stock or talon to the tableau */simpletableau(cp, des)struct cardtype **cp;{	int origin;	if (notempty(*cp)) {		if (tabok(*cp, des)) {			if (*cp == stock)				origin = stk;			else				origin = tal;			if (tableau[des] == NIL)				bottom[des] = *cp;			transit(cp, &tableau[des]);			length[des]++;			printcard(pilemap[des], length[des], tableau[des]);			timesthru = 0;			if (origin == stk) {				usedstock();				printcard(stockcol, stockrow, stock);			} else {				usedtalon();				printcard(taloncol, talonrow, talon);			}		} else 			destinerror();	}}/* * print the tableau */tabprint(sour, des){	int dlength, slength, i;	struct cardtype *tempcard;	for (i=tabrow; i<=length[sour]; i++)		removecard(pilemap[sour], i);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -