Esempio n. 1
0
void waitturn()
{
	time_t start,now;

start=now=time(NULL);
getgamedat(1);
status[node_num-1]=WAIT;
putgamedat();
while(curplayer!=node_num) {
	chat();
	mswait(100);
	getgamedat(0);
	if(curplayer && !node[curplayer-1] /*  || status[curplayer-1]==BET */ )
		nextplayer();		/* current player is not playing? */

	if(!node[node_num-1]) { /* current node not in game? */
		getgamedat(1);
		node[node_num-1]=user_number;	/* fix it */
		putgamedat(); }

	now=time(NULL);
	if(now-start>300) { /* only wait upto 5 minutes */
		bputs("\r\nwaitturn: timeout\r\n");
		break; } }
getgamedat(1);
status[node_num-1]=PLAY;
putgamedat();
}
Esempio n. 2
0
void Game::on_follow(bool clear){
    static int time = 0;
    if(clear){
        time = 0;
    }
    nextplayer();
    ++time;
    if(time == 4){
       time = 0;
       state = GameState_CircleFinished;
       return;
    }
    current_player->ask_follow();
    wait();
}
Esempio n. 3
0
void Game::on_deal(bool clear){
    static short deal_pos = 0;
    if(clear){
        deal_pos = 0;
        return;
    }
    current_player->deal_card(puker.get_card(deal_pos));
    ++deal_pos;
    nextplayer();
    if(deal_pos == puker.get_cards_count() - HOLDUP_NUMBER - 1){
        state = GameState_WaitingForSpecial;
    }
    Game::msleep(100);

    gamewindow->game_deal(current_player->get_id());
}
Esempio n. 4
0
void play()
{
	char str[256],str2[256],log[81],done,doub,dh,split_card,suggestion
		,*YouWereDealt="\1n\1k\0015 You \1n\1m were dealt: %s\r\n"
		,*UserWasDealt="\1n\1m\1h%s\1n\1m was dealt: %s\r\n"
		,*YourHand="\1n\1k\0015 You \1n\1m                     (%2d) %s"
		,*UserHand="\1n\1m\1h%-25s \1n\1m(%2d) %s"
		,*DealerHand="\1n\1hDealer                    \1n\1m(%2d) "
		,*Bust="\1n\1r\1hBust\1n\r\n"
		,*Natural="\1g\1h\1iNatural "
		,*Three7s="\1r\1h\1iThree 7's "
		,*Blackjack="\1n\0011\1k Blackjack! \1n\r\n"
		,*TwentyOne="\1n\0012\1k Twenty-one \1n\r\n";
	int h,i,j,file;
	uint max;
	long val;
	time_t start,now;
	struct tm* tm;

sprintf(str,"MESSAGE.%d",node_num);         /* remove message if waiting */
if(fexist(str))
    remove(str);

getgamedat(0);
if(node[node_num-1]) {
	getgamedat(1);
	node[node_num-1]=0;
	putgamedat();
	getgamedat(0); }

if(total_players && misc&INPLAY) {
	bputs("\r\n\1hWaiting for end of hand (^A to abort)...\1n");
	start=now=time(NULL);
	getgamedat(0);
	while(total_players && misc&INPLAY) {
		if((i=inkey(0))!=0) {	 /* if key was hit */
			if(i==1) {		 /* if ctrl-a */
				bputs("\r\n");
				return; } }  /* return */
		mswait(100);
		getgamedat(0);
		now=time(NULL);
		if(now-start>300) { /* only wait up to 5 minutes */
			bputs("\r\ntimeout\r\n");
			return; } }
	bputs("\r\n"); }

getgamedat(1);
node[node_num-1]=user_number;
putgamedat();

if(!total_players)
    shuffle();
else
	listplayers();

sprintf(str,"\1n\1m\1h%s \1n\1m%s\r\n",user_name,joined());
putallnodemsg(str);

while(1) {
	aborted=0;
	#if DEBUG
	debugline("top of loop");
	#endif
	if(autoplay)
		lncntr=0;
	bprintf(ShoeStatus,cur_card,total_decks*52);
	if(cur_card>(total_decks*52)-(total_players*10)-10 && lastplayer())
		shuffle();
	getgamedat(1);
	misc&=~INPLAY;
	status[node_num-1]=BET;
	node[node_num-1]=user_number;
	putgamedat();

	bprintf("\r\n\1n\1cYou have \1h%s\1n\1ck credits\r\n"
		,ultoac(credits/1024L,str));
	if(credits<min_bet/1024) {
		bprintf("\1n\1cMinimum bet: \1h%uk\r\n",min_bet);
		bputs("\1n\1r\1hCome back when you have more credits.\r\n");
        break; }
	if(credits/1024L>(ulong)max_bet)
		max=max_bet;
	else
		max=credits/1024L;
	sprintf(str,"\r\nBet amount (in kilobytes) or ~Quit [%u]: "
		,ibet<credits/1024L ? ibet : credits/1024L);
	chat();
	mnemonics(str);
	if(autoplay && keyhit())
		autoplay=0;
	if(autoplay)
		i=ibet;
	else
		i=getnum(max);
	if(i==-1)	/* if user hit ^C or 'Q' */
		break;
	bputs("\r\n");
	if(i)		/* if user entered a value */
		bet[0]=i;
	else		/* if user hit enter */
		bet[0]=ibet<credits/1024L ? ibet : credits/1024L;
	if(bet[0]<min_bet) {
		bprintf("\1n\1cMinimum bet: \1h%uk\r\n",min_bet);
		bputs("\1n\1r\1hCome back when you're ready to bet more.\r\n");
		break; }
	ibet=bet[0];
	getgamedat(0);	/* to get all new arrivals */
	sprintf(str,"\1m\1h%s\1n\1m bet \1n\1h%u\1n\1mk\r\n",user_name,bet[0]);
	putallnodemsg(str);

	pc[0]=2;						/* init player's 1st hand to 2 cards */
	for(i=1;i<MAX_HANDS;i++)		/* init player's other hands to 0 cards */
		pc[i]=0;
	hands=1;						/* init total player's hands to 1 */

	getgamedat(1);					/* first come first serve to be the */
	for(i=0;i<total_nodes;i++)		/* dealer in control of sync */
		if(node[i] && status[i]==SYNC_D)
			break;
	if(i==total_nodes) {
		#if DEBUG
		debugline("syncdealer");
		#endif
		syncdealer();  }			/* all players meet here */
	else {							/* first player is current after here */
		#if DEBUG
		debugline("syncplayer");
		#endif
		syncplayer(); } 			/* game is closed (INPLAY) at this point */

	#if DEBUG
	debugline("waitturn 1");
	#endif
    waitturn();
	getnodemsg();
										/* Initial deal card #1 */
	getcarddat();
	player[0][0]=card[cur_card++];
	putcarddat();
	sprintf(str,YouWereDealt,cardstr(card[cur_card-1]));
	if(!symbols)
		strip_symbols(str);
    bputs(str);
	sprintf(str,UserWasDealt,user_name,cardstr(card[cur_card-1]));
    putallnodemsg(str);
	
	if(lastplayer()) {
		getcarddat();
		dealer[0]=card[cur_card++];
		dc=1;
		putcarddat(); }
	nextplayer();
	#if DEBUG
	debugline("waitturn 2");
	#endif
	waitturn();
	getnodemsg();

	getcarddat();					   /* Initial deal card #2 */
	player[0][1]=card[cur_card++];
	putcarddat();
	sprintf(str,YouWereDealt,cardstr(card[cur_card-1]));
	if(!symbols)
		strip_symbols(str);
	bputs(str);
	sprintf(str,UserWasDealt,user_name,cardstr(card[cur_card-1]));
    putallnodemsg(str);
	
	if(lastplayer()) {
		getcarddat();
		dealer[1]=card[cur_card++];
		dc=2;
		putcarddat(); }
	nextplayer();
	#if DEBUG
	debugline("waitturn 3");
	#endif
	waitturn();
	getnodemsg();
	getcarddat();

	for(i=0;i<hands;i++) {
		if(autoplay)
			lncntr=0;
		done=doub=0;
		while(!done && pc[i]<MAX_CARDS && cur_card<total_decks*52) {
			h=hand(player[i],pc[i]);
			str[0]=0;
			for(j=0;j<pc[i];j++) {
				strcat(str,cardstr(player[i][j]));
				strcat(str," "); }
			j=bstrlen(str);
			while(j++<19)
				strcat(str," ");
			if(h>21) {
				strcat(str,Bust);
				sprintf(str2,YourHand,h,str);
				if(!symbols)
					strip_symbols(str2);
				bputs(str2);
				sprintf(str2,UserHand,user_name,h,str);
				putallnodemsg(str2);
				break; }
			if(h==21) {
				if(pc[i]==2) {	/* blackjack */
					if(player[i][0].suit==player[i][1].suit)
						strcat(str,Natural);
					strcat(str,Blackjack); }
				else {
					if(player[i][0].value==7
						&& player[i][1].value==7
						&& player[i][2].value==7)
						strcat(str,Three7s);
					strcat(str,TwentyOne); }
				sprintf(str2,YourHand,h,str);
				if(!symbols)
					strip_symbols(str2);
				bputs(str2);
				sprintf(str2,UserHand,user_name,h,str);
                putallnodemsg(str2);
				// fdelay(500);
				break; }
			strcat(str,"\r\n");
			sprintf(str2,YourHand,h,str);
			if(!symbols)
				strip_symbols(str2);
			bputs(str2);
			sprintf(str2,UserHand,user_name,h,str);
			putallnodemsg(str2);
			if(doub)
				break;
			sprintf(str,"\1n\1hDealer\1n\1m card up: %s\r\n"
				,cardstr(dealer[1]));
			if(!symbols)
				strip_symbols(str);
			bputs(str);

			if(tutor) {
				if(pc[i]==2)
					split_card=pair(player[i],pc[i]);
				else
					split_card=0;
                if(split_card==A
					|| (split_card==9 && (dealer[1].value<7
						|| (dealer[1].value>7 && dealer[1].value<10)))
                    || split_card==8
					|| (split_card==7 && dealer[1].value<9)
					|| (split_card==6 && dealer[1].value<7)
					|| (split_card==4 && dealer[1].value==5)
					|| (split_card && split_card<4 && dealer[1].value<8))
					suggestion='P';
                else if(soft(player[i],pc[i])) {
                    if(h>18)
						suggestion='S';
					else if(pc[i]==2
						&& ((h==18
							&& dealer[1].value>3 && dealer[1].value<7)
                        || (h==17
							&& dealer[1].value>2 && dealer[1].value<7)
                        || (h>13
							&& dealer[1].value>3 && dealer[1].value<7)
                        || (h==12
							&& dealer[1].value>4 && dealer[1].value<7)))
						suggestion='D';
                    else
						suggestion='H'; }
                else { /* hard */
					if(h>16 || (h>13 && dealer[1].value<7)
						|| (h==12 && dealer[1].value>3 && dealer[1].value<7))
						suggestion='S';
					else if(pc[i]==2
						&& (h==11 || (h==10 && dealer[1].value<10)
						|| (h==9 && dealer[1].value<7)))
						suggestion='D';
                    else
						suggestion='H'; } }

			if(tutor==1)
				suggest(suggestion);
			strcpy(str,"\r\n~Hit");
			strcpy(tmp,"H\r");
			if(bet[i]+ibet<=credits/1024L && pc[i]==2) {
				strcat(str,", ~Double");
				strcat(tmp,"D"); }
			if(bet[i]+ibet<=credits/1024L && pc[i]==2 && hands<MAX_HANDS
				&& player[i][0].value==player[i][1].value) {
				strcat(str,", ~Split");
				strcat(tmp,"S"); }
			strcat(str,", or [Stand]: ");
			chat();
			mnemonics(str);
			if(autoplay && keyhit())
				autoplay=0;


			if(autoplay) {
				lncntr=0;
				bputs("\r\n");
				strcpy(str,stand());
				bputs(str);
				putallnodemsg(str);
				done=1; }
			else
			switch(getkeys(tmp,0)) {
				case 'H':     /* hit */
					if(tutor==2 && suggestion!='H')
						wrong(suggestion);
					strcpy(str,hit());
					bputs(str);
					putallnodemsg(str);
					getcarddat();
					player[i][pc[i]++]=card[cur_card++];
					putcarddat();
					break;
				case 'D':   /* double down */
					if(tutor==2 && suggestion!='D')
                        wrong(suggestion);
					strcpy(str,doubit());
					bputs(str);
					putallnodemsg(str);
					getcarddat();
					player[i][pc[i]++]=card[cur_card++];
					putcarddat();
					doub=1;
					bet[i]+=ibet;
					break;
				case 'S':   /* split */
					if(tutor==2 && suggestion!='P')
                        wrong(suggestion);
					strcpy(str,split());
					bputs(str);
					putallnodemsg(str);
					player[hands][0]=player[i][1];
					getcarddat();
					player[i][1]=card[cur_card++];
					player[hands][1]=card[cur_card++];
					putcarddat();
					pc[hands]=2;
					bet[hands]=ibet;
					hands++;
					break;
				case CR:
					if(tutor==2 && suggestion!='S')
                        wrong(suggestion);
					strcpy(str,stand());
					bputs(str);
					putallnodemsg(str);
					done=1;
					break; } } }

	if(lastplayer()) {	/* last player plays the dealer's hand */
		getcarddat();
		while(hand(dealer,dc)<17 && dc<MAX_CARDS && cur_card<total_decks*52)
			dealer[dc++]=card[cur_card++];
		putcarddat(); }

	nextplayer();
	#if DEBUG
	debugline("waitturn 4");
	#endif
	waitturn();
	getnodemsg();

	if(firstplayer()==node_num) {
		strcpy(str,"\1n\0014\1h Final \1n\r\n");
		bputs(str);
		putallnodemsg(str); }
	getcarddat();
	dh=hand(dealer,dc); 					/* display dealer's hand */
	sprintf(str,DealerHand,dh);
	for(i=0;i<dc;i++) {
		strcat(str,cardstr(dealer[i]));
		strcat(str," "); }
	i=bstrlen(str);
	while(i++<50)				/* was 50 */
		strcat(str," ");
	if(dh>21) {
		strcat(str,Bust);
		if(!symbols)
			strip_symbols(str);
		bputs(str); }
	else if(dh==21) {
		if(dc==2) { 	/* blackjack */
			if(dealer[0].suit==dealer[1].suit)
				strcat(str,Natural);
			strcat(str,Blackjack); }
		else {			/* twenty-one */
			if(dc==3 && dealer[0].value==7 && dealer[1].value==7
				&& dealer[2].value==7)
				strcat(str,Three7s);
			strcat(str,TwentyOne); }
		if(!symbols)
            strip_symbols(str);
		bputs(str); }
	else {
		if(!symbols)
            strip_symbols(str);
		bprintf("%s\r\n",str); }

	for(i=0;i<hands;i++) {						/* display player's hand(s) */
		h=hand(player[i],pc[i]);
		str[0]=0;
		for(j=0;j<pc[i];j++) {
			strcat(str,cardstr(player[i][j]));
			strcat(str," "); }
		j=bstrlen(str);
		while(j++<19)
			strcat(str," ");
		if(logit) {
			now=time(NULL);
			tm=localtime(&now);
			sprintf(log,"%02d%02d%02d.log"                  /* log winnings */
				,tm->tm_mon+1,tm->tm_mday,tm->tm_year%100);
			if((file=nopen(log,O_RDONLY))!=-1) {
				read(file,tmp,filelength(file));
				tmp[filelength(file)]=0;
				val=atol(tmp);
				close(file); }
			else
				val=0L;
			if((file=nopen(log,O_WRONLY|O_CREAT|O_TRUNC))==-1) {
				bprintf("error opening %s\r\n",log);
				return; } }
		if(h<22 && (h>dh || dh>21	/* player won */
			|| (h==21 && pc[i]==2 && dh==21 && dh>2))) {	/* blackjack */
			j=bet[i];								  /* and dealer got 21 */
			if(h==21 && 	/* natural blackjack or three 7's */
				((player[i][0].value==7 && player[i][1].value==7
				&& player[i][2].value==7)
				|| (pc[i]==2 && player[i][0].suit==player[i][1].suit)))
				j*=2;
			else if(h==21 && pc[i]==2)	/* regular blackjack */
				j*=1.5; /* blackjack pays 1 1/2 to 1 */
			sprintf(tmp,"\1n\1h\1m\1iWon!\1n\1h %u\1n\1mk",j);
			strcat(str,tmp);
			credits+=j*1024L;
			val-=j*1024L;
			moduserdat(); }
		else if(h<22 && h==dh)
			strcat(str,"\1n\1hPush");
		else {
			strcat(str,"\1nLost");
			credits-=bet[i]*1024L;
			val+=bet[i]*1024L;
			moduserdat(); }
		if(logit) {
			sprintf(tmp,"%ld",val);
			write(file,tmp,strlen(tmp));
			close(file); }					/* close winning log */
		strcat(str,"\1n\r\n");
		sprintf(str2,YourHand,h,str);
		if(!symbols)
			strip_symbols(str2);
		bputs(str2);
		sprintf(str2,UserHand,user_name,h,str);
		putallnodemsg(str2); }

	nextplayer();
	if(!lastplayer()) {
		#if DEBUG
		debugline("lastplayer waitturn");
		#endif
		waitturn();
		nextplayer(); }
	#if DEBUG
	debugline("end of loop");
	#endif
	getnodemsg(); }

getgamedat(1);
node[node_num-1]=0;
putgamedat();
sprintf(str,"\1n\1m\1h%s \1n\1m%s\r\n",user_name,left());
putallnodemsg(str);
}