* Copyright (c) 1990 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* %sccs.include.redist.c%
"@(#) Copyright (c) 1990 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)fish.c 5.3 (Berkeley) %G%";
#define OTHER(a) (1 - (a))
"A", "2", "3", "4", "5", "6", "7",
"8", "9", "10", "J", "Q", "K", NULL
,
#define PRC(card) (void)printf(" %s", cards[card])
int asked
[RANKS
], comphand
[RANKS
], deck
[RANKS
];
int userasked
[RANKS
], userhand
[RANKS
];
while ((ch
= getopt(argc
, argv
, "p")) != EOF
)
(void)fprintf(stderr
, "usage: fish [-p]\n");
srandom(time((time_t *)NULL
));
(void)printf("get to start.\n");
(void)printf("get to start.\n");
if (gofish(move
, USER
, userhand
))
goodmove(USER
, move
, userhand
, comphand
);
if (!gofish(move
, COMPUTER
, comphand
))
goodmove(COMPUTER
, move
, comphand
, userhand
);
(void)printf("Your hand is:");
(void)printf("You ask me for: ");
if (fgets(buf
, BUFSIZ
, stdin
) == NULL
)
(void)printf("%d cards in my hand, %d in the pool.\n",
countcards(comphand
), countcards(deck
));
(void)printf("My books:");
(void)countbooks(comphand
);
buf
[strlen(buf
) - 1] = '\0';
if (!strcasecmp(buf
, "p") && !promode
) {
(void)printf("Entering pro mode.\n");
if (!strcasecmp(buf
, "quit"))
if (!strcasecmp(*p
, buf
))
(void)printf("I don't understand!\n");
(void)printf("You don't have any of those!\n");
(void)printf("You don't have any %s's!\n", cards
[n
]);
(void)printf("No cheating!\n");
(void)printf("Guess again.\n");
lmove
= (lmove
+ 1) % RANKS
;
} while (!comphand
[lmove
] || comphand
[lmove
] == CARDS
);
(void)printf("I ask you for: %s.\n", cards
[lmove
]);
for (i
= 0; i
< RANKS
; ++i
)
comphand
[i
] > 0 && comphand
[i
] < CARDS
) {
if (comphand
[i
] && comphand
[i
] != CARDS
) {
if (comphand
[i
] != CARDS
&&
comphand
[i
] > comphand
[max
])
if (nrandom(1024) == 0723) {
for (i
= 0; i
< RANKS
; ++i
)
if (userhand
[i
] && comphand
[i
])
for (i
= 0; i
< RANKS
; ++i
)
if (comphand
[i
] && comphand
[i
] != CARDS
&&
for (i
= 0; i
< RANKS
; ++i
)
while (deck
[card
= nrandom(RANKS
)] == 0);
if (player
== USER
|| hand
[card
] == CARDS
) {
(void)printf("drew %s", cards
[card
]);
if (hand
[card
] == CARDS
) {
(void)printf(" and made a book of %s's!\n",
gofish(askedfor
, player
, hand
)
printplayer(OTHER(player
));
(void)printf("say \"GO FISH!\"\n");
if (askedfor
== drawcard(player
, hand
)) {
(void)printf("drew the guess!\n");
(void)printf("get to ask again!\n");
goodmove(player
, move
, hand
, opphand
)
printplayer(OTHER(player
));
(void)printf("have %d %s%s.\n",
opphand
[move
], cards
[move
], opphand
[move
] == 1 ? "": "'s");
hand
[move
] += opphand
[move
];
if (hand
[move
] == CARDS
) {
(void)printf("made a book of %s's!\n", cards
[move
]);
chkwinner(OTHER(player
), opphand
);
(void)printf("get another guess!\n");
for (i
= 0; i
< RANKS
; ++i
)
if (hand
[i
] > 0 && hand
[i
] < CARDS
)
(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
);
(void)printf("\nYou win!!!\n");
if (nrandom(1024) == 0723)
(void)printf("Cheater, cheater, pumpkin eater!\n");
(void)printf("\nI win!!!\n");
if (nrandom(1024) == 0723)
(void)printf("Hah! Stupid peasant!\n");
(void)printf("\nTie!\n");
for (book
= i
= 0; i
< RANKS
; i
++)
for (j
= hand
[i
]; --j
>= 0;)
(void)printf(" + Book%s of", book
> 1 ? "s" : "");
for (i
= 0; i
< RANKS
; i
++)
for (count
= i
= 0; i
< RANKS
; i
++)
for (count
= i
= 0; i
< RANKS
; i
++)
for (i
= 0; i
< RANKS
; ++i
)
for (i
= 0; i
< HANDSIZE
; ++i
) {
while (!deck
[rank
= nrandom(RANKS
)]);
for (i
= 0; i
< HANDSIZE
; ++i
) {
while (!deck
[rank
= nrandom(RANKS
)]);
return((int)random() % n
);
(void)printf("Would you like instructions (y or n)? ");
while (getchar() != '\n');
(void)sprintf(buf
, "%s %s", _PATH_MORE
, _PATH_INSTR
);
(void)printf("Hit return to continue...\n");
while ((input
= getchar()) != EOF
&& input
!= '\n');
(void)fprintf(stderr
, "usage: fish [-p]\n");