-/* $NetBSD: support.c,v 1.3 1995/03/21 15:08:59 cgd Exp $ */
+/* $NetBSD: support.c,v 1.14 2009/08/12 05:48:04 dholland Exp $ */
/*-
* Copyright (c) 1980, 1993
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)support.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$NetBSD: support.c,v 1.3 1995/03/21 15:08:59 cgd Exp $";
+__RCSID("$NetBSD: support.c,v 1.14 2009/08/12 05:48:04 dholland Exp $");
#endif
#endif /* not lint */
#include <curses.h>
+#include <stdlib.h>
#include <string.h>
#include "deck.h"
#define NTV 10 /* number scores to test */
/* score to test reachability of, and order to test them in */
-int tv[NTV] = {8, 7, 9, 6, 11, 12, 13, 14, 10, 5};
+static const int tv[NTV] = {8, 7, 9, 6, 11, 12, 13, 14, 10, 5};
+
+static int anysumto(const CARD[], int, int, int);
+static void prpeg(int, int, BOOLEAN);
+static int numofval(const CARD[], int, int);
/*
* computer chooses what to play in pegging...
* only called if no playable card will score points
*/
int
-cchose(h, n, s)
- CARD h[];
- int n, s;
+cchose(const CARD h[], int n, int s)
{
- register int i, j, l;
+ int i, j, l;
if (n <= 1)
return (0);
break;
}
}
+ if (j < 0) {
+ printf("\ncchose: internal error %d %d\n", j, n);
+ exit(93);
+ }
return (j);
}
* Evaluate and score a player hand or crib
*/
int
-plyrhand(hand, s)
- CARD hand[];
- char *s;
+plyrhand(const CARD hand[], const char *s)
{
static char prompt[BUFSIZ];
- register int i, j;
- register BOOLEAN win;
+ int i, j;
+ BOOLEAN win;
prhand(hand, CINHAND, Playwin, FALSE);
- (void) sprintf(prompt, "Your %s scores ", s);
+ (void) snprintf(prompt, sizeof(prompt), "Your %s scores ", s);
i = scorehand(hand, turnover, CINHAND, strcmp(s, "crib") == 0, explain);
if ((j = number(0, 29, prompt)) == 19)
j = 0;
msg("You should have taken %d, not %d!", i, j);
}
if (explain)
- msg("Explanation: %s", expl);
+ msg("Explanation: %s", explan);
do_wait();
} else
win = chkscr(&pscore, i);
* Handle scoring and displaying the computers hand
*/
int
-comphand(h, s)
- CARD h[];
- char *s;
+comphand(const CARD h[], const char *s)
{
- register int j;
+ int j;
j = scorehand(h, turnover, CINHAND, strcmp(s, "crib") == 0, FALSE);
prhand(h, CINHAND, Compwin, FALSE);
int Lastscore[2] = {-1, -1};
int
-chkscr(scr, inc)
- int *scr, inc;
+chkscr(int *scr, int inc)
{
BOOLEAN myturn;
myturn = (scr == &cscore);
if (inc != 0) {
- prpeg(Lastscore[myturn], '.', myturn);
- Lastscore[myturn] = *scr;
+ prpeg(Lastscore[(int)myturn], '.', myturn);
+ Lastscore[(int)myturn] = *scr;
*scr += inc;
prpeg(*scr, PEG, myturn);
refresh();
* Put out the peg character on the score board and put the
* score up on the board.
*/
-void
-prpeg(score, peg, myturn)
- register int score;
- int peg;
- BOOLEAN myturn;
+static void
+prpeg(int curscore, int pegc, BOOLEAN myturn)
{
- register int y, x;
+ int y, x;
if (!myturn)
y = SCORE_Y + 2;
else
y = SCORE_Y + 5;
- if (score <= 0 || score >= glimit) {
- if (peg == '.')
- peg = ' ';
- if (score == 0)
+ if (curscore <= 0 || curscore >= glimit) {
+ if (pegc == '.')
+ pegc = ' ';
+ if (curscore == 0)
x = SCORE_X + 2;
else {
x = SCORE_X + 2;
y++;
}
} else {
- x = (score - 1) % 30;
- if (score > 90 || (score > 30 && score <= 60)) {
+ x = (curscore - 1) % 30;
+ if (curscore > 90 || (curscore > 30 && curscore <= 60)) {
y++;
x = 29 - x;
}
x += x / 5;
x += SCORE_X + 3;
}
- mvaddch(y, x, peg);
- mvprintw(SCORE_Y + (myturn ? 7 : 1), SCORE_X + 10, "%3d", score);
+ mvaddch(y, x, pegc);
+ mvprintw(SCORE_Y + (myturn ? 7 : 1), SCORE_X + 10, "%3d", curscore);
}
/*
* the crib and puts the best two cards at the end
*/
void
-cdiscard(mycrib)
- BOOLEAN mycrib;
+cdiscard(BOOLEAN mycrib)
{
CARD d[CARDS], h[FULLHAND], cb[2];
- register int i, j, k;
+ int i, j, k;
int nc, ns;
long sums[15];
static int undo1[15] = {0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 4};
* returns true if some card in hand can be played without exceeding 31
*/
int
-anymove(hand, n, sum)
- CARD hand[];
- int n, sum;
+anymove(const CARD hand[], int n, int sum)
{
- register int i, j;
+ int i, j;
if (n < 1)
return (FALSE);
* anysumto returns the index (0 <= i < n) of the card in hand that brings
* the s up to t, or -1 if there is none
*/
-int
-anysumto(hand, n, s, t)
- CARD hand[];
- int n, s, t;
+static int
+anysumto(const CARD hand[], int n, int s, int t)
{
- register int i;
+ int i;
for (i = 0; i < n; i++) {
if (s + VAL(hand[i].rank) == t)
/*
* return the number of cards in h having the given rank value
*/
-int
-numofval(h, n, v)
- CARD h[];
- int n, v;
+static int
+numofval(const CARD h[], int n, int v)
{
- register int i, j;
+ int i, j;
j = 0;
for (i = 0; i < n; i++) {
* makeknown remembers all n cards in h for future recall
*/
void
-makeknown(h, n)
- CARD h[];
- int n;
+makeknown(const CARD h[], int n)
{
- register int i;
+ int i;
for (i = 0; i < n; i++)
known[knownum++] = h[i];