Exemplo n.º 1
0
static bool gofish (enum EPlayer player, unsigned askedfor)
{
    wattron (_wmsg, A_BOLD);
    printplayer (OTHER(player));
    waddstr (_wmsg, "say \"GO FISH!\"\n");
    wattroff (_wmsg, A_BOLD);
    if (askedfor == drawcard (player)) {
	printplayer (player);
	waddstr (_wmsg, "drew the guess and get to ask again.\n");
	return true;
    }
    return false;
}
Exemplo n.º 2
0
int
gofish(int askedfor, int player, int *hand)
{
	printplayer(OTHER(player));
	(void)printf("say \"GO FISH!\"\n");
	if (askedfor == drawcard(player, hand)) {
		printplayer(player);
		(void)printf("drew the guess!\n");
		printplayer(player);
		(void)printf("get to ask again!\n");
		return(1);
	}
	return(0);
}
Exemplo n.º 3
0
int
main(int argc, char *argv[])
{
	int ch, move;

	while ((ch = getopt(argc, argv, "ph")) != -1)
		switch(ch) {
		case 'p':
			promode = 1;
			break;
		case '?':
		case 'h':
		default:
			usage();
		}

	srandomdev();
	instructions();
	init();

	if (nrandom(2) == 1) {
		printplayer(COMPUTER);
		(void)printf("get to start.\n");
		goto istart;
	}
	printplayer(USER);
	(void)printf("get to start.\n");
	
	for (;;) {
		move = usermove();
		if (!comphand[move]) {
			if (gofish(move, USER, userhand))
				continue;
		} else {
			goodmove(USER, move, userhand, comphand);
			continue;
		}

istart:		for (;;) {
			move = compmove();
			if (!userhand[move]) {
				if (!gofish(move, COMPUTER, comphand))
					break;
			} else
				goodmove(COMPUTER, move, comphand, userhand);
		}
	}
	/* NOTREACHED */
}
Exemplo n.º 4
0
void
chkwinner(int player, const int *hand)
{
	int cb, i, ub;

	for (i = 0; i < RANKS; ++i)
		if (hand[i] > 0 && hand[i] < CARDS)
			return;
	printplayer(player);
	(void)printf("don't have any more cards!\n");
	(void)printf("My books:");
	cb = countbooks(comphand);
	(void)printf("Your books:");
	ub = countbooks(userhand);
	(void)printf("\nI have %d, you have %d.\n", cb, ub);
	if (ub > cb) {
		(void)printf("\nYou win!!!\n");
		if (nrandom(1024) == 0723)
			(void)printf("Cheater, cheater, pumpkin eater!\n");
	} else if (cb > ub) {
		(void)printf("\nI win!!!\n");
		if (nrandom(1024) == 0723)
			(void)printf("Hah!  Stupid peasant!\n");
	} else
		(void)printf("\nTie!\n");
	exit(0);
}
Exemplo n.º 5
0
static void chkwinner (enum EPlayer player)
{
    for (unsigned i = 0; i < RANKS; ++i)
	if (_hand[player][i] > 0 && _hand[player][i] < SUITS)
	    return;
    draw_panel();
    printplayer (player);
    waddstr (_wmsg, "don't have any more cards!\n\nMy books:");
    unsigned cb = countbooks (COMPUTER);
    waddstr (_wmsg, "Your books:");
    unsigned ub = countbooks (USER);
    wprintw (_wmsg, "\nI have %d, you have %d.\n", cb, ub);
    if (ub > cb) {
	waddstr (_wmsg, "\nYou win!!!\n");
	if (!nrand(64))
	    waddstr (_wmsg, "Cheater, cheater, pumpkin eater!\n");
    } else if (cb > ub) {
	waddstr (_wmsg, "\nI win!!!\n");
	if (!nrand(64))
	    waddstr (_wmsg, "Hah! Stupid peasant!\n");
    } else
	waddstr (_wmsg, "\nTie!\n");
    wgetch (_wmsg);
    exit (EXIT_SUCCESS);
}
Exemplo n.º 6
0
static void goodmove (enum EPlayer player, unsigned m)
{
    printplayer (OTHER(player));
    wprintw (_wmsg, "have %u %s%s.\n", _hand[OTHER(player)][m], c_CardNames[m], _hand[OTHER(player)][m] == 1 ? "" : "'s");

    _hand[player][m] += _hand[OTHER(player)][m];
    _hand[OTHER(player)][m] = 0;

    if (_hand[player][m] == SUITS) {
	printplayer (player);
	wprintw (_wmsg, "made a book of %s's!\n", c_CardNames[m]);
	chkwinner (player);
    }
    chkwinner (OTHER(player));

    printplayer (player);
    waddstr (_wmsg, "get another guess!\n");
}
Exemplo n.º 7
0
void
goodmove(int player, int move, int *hand, int *opphand)
{
	printplayer(OTHER(player));
	(void)printf("have %d %s%s.\n",
	    opphand[move], cards[move], opphand[move] == 1 ? "": "'s");

	hand[move] += opphand[move];
	opphand[move] = 0;

	if (hand[move] == CARDS) {
		printplayer(player);
		(void)printf("made a book of %s's!\n", cards[move]);
		chkwinner(player, hand);
	}

	chkwinner(OTHER(player), opphand);

	printplayer(player);
	(void)printf("get another guess!\n");
}
Exemplo n.º 8
0
static unsigned drawcard (enum EPlayer player)
{
    unsigned card = _deck[--_decksz];
    ++_hand[player][card];
    if (player == USER || _hand[player][card] == SUITS) {
	printplayer(player);
	wprintw (_wmsg, "drew %s", c_CardNames[card]);
	if (_hand[player][card] == SUITS) {
	    wprintw (_wmsg, " and made a book of %s's.\n", c_CardNames[card]);
	    chkwinner (player);
	} else
	    waddstr (_wmsg, ".\n");
    }
    return card;
}
Exemplo n.º 9
0
int
drawcard(int player, int *hand)
{
	int card;

	++hand[card = deck[--curcard]];
	if (player == USER || hand[card] == CARDS) {
		printplayer(player);
		(void)printf("drew %s", cards[card]);
		if (hand[card] == CARDS) {
			(void)printf(" and made a book of %s's!\n",
			     cards[card]);
			chkwinner(player, hand);
		} else
			(void)printf(".\n");
	}
	return(card);
}
Exemplo n.º 10
0
int main (void)
{
    initialize_curses();
    initialize_windows();
    shuffle_deck_and_deal();
    instructions();

    enum EPlayer player = nrand(NPLAYERS);
    printplayer (player);
    waddstr (_wmsg, "get to start.\n");
    for (;;) {
	unsigned m = makemove (player);
	if (_hand[OTHER(player)][m])
	    goodmove (player, m);
	else if (!gofish (player, m))
	    player = OTHER(player);
    }
    return EXIT_SUCCESS;
}