2 * bs.c - original author: Bruce Holloway
3 * salvo option by: Chuck A DeGaul
4 * with improved user interface, autoconfiguration and code cleanup
5 * by Eric S. Raymond <esr@snark.thyrsus.com>
6 * v1.2 with color support and minor portability fixes, November 1990
7 * v2.0 featuring strict ANSI/POSIX conformance, November 1993.
8 * v2.1 with ncurses mouse support, September 1995
10 * $Id: bs.c,v 1.36 2002/06/29 23:32:18 tom Exp $
17 #include <test.priv.h>
20 #define SIGIOT SIGABRT
23 static int getcoord(int);
26 * Constants for tuning the random-fire algorithm. It prefers moves that
27 * diagonal-stripe the board with a stripe separation of srchstep. If
28 * no such preferred moves are found, srchstep is decremented.
30 #define BEGINSTEP 3 /* initial value of srchstep */
32 /* miscellaneous constants */
34 #define OTHER (1-turn)
39 #define CTRLC '\003' /* used as terminate command */
40 #define FF '\014' /* used as redraw command */
42 /* coordinate handling */
48 #define SHOWSPLASH ' '
49 #define IS_SHIP(c) (isupper(UChar(c)) ? TRUE : FALSE)
51 /* how to position us on player board */
54 #define PY(y) (PYBASE + (y))
55 #define PX(x) (PXBASE + (x)*3)
56 #define pgoto(y, x) (void)move(PY(y), PX(x))
58 /* how to position us on cpu board */
61 #define CY(y) (CYBASE + (y))
62 #define CX(x) (CXBASE + (x)*3)
63 #define CYINV(y) ((y) - CYBASE)
64 #define CXINV(x) (((x) - CXBASE) / 3)
65 #define cgoto(y, x) (void)move(CY(y), CX(x))
67 #define ONBOARD(x, y) (x >= 0 && x < BWIDTH && y >= 0 && y < BDEPTH)
69 /* other board locations */
71 #define PROMPTLINE 21 /* prompt line */
72 #define SYBASE CYBASE + BDEPTH + 3 /* move key diagram */
74 #define MYBASE SYBASE - 1 /* diagram caption */
76 #define HYBASE SYBASE - 1 /* help area */
79 /* this will need to be changed if BWIDTH changes */
80 static char numbers[] = " 0 1 2 3 4 5 6 7 8 9";
82 static char carrier[] = "Aircraft Carrier";
83 static char battle[] = "Battleship";
84 static char sub[] = "Submarine";
85 static char destroy[] = "Destroyer";
86 static char ptboat[] = "PT Boat";
89 static char dftname[] = "stranger";
91 /* direction constants */
100 static int xincr[8] =
101 {1, 1, 0, -1, -1, -1, 0, 1};
102 static int yincr[8] =
103 {0, 1, 1, 1, 0, -1, -1, -1};
105 /* current ship position and direction */
106 static int curx = (BWIDTH / 2);
107 static int cury = (BDEPTH / 2);
110 char *name; /* name of the ship type */
111 int hits; /* how many times has this ship been hit? */
112 char symbol; /* symbol for game purposes */
113 int length; /* length of ship */
114 int x, y; /* coordinates of ship start point */
115 int dir; /* direction of `bow' */
116 bool placed; /* has it been placed on the board? */
119 static bool checkplace(int b, ship_t * ss, int vis);
121 #define SHIPIT(name, symbol, length) { name, 0, symbol, length, 0,0, 0, FALSE }
123 static ship_t plyship[SHIPTYPES] =
125 SHIPIT(carrier, 'A', 5),
126 SHIPIT(battle, 'B', 4),
127 SHIPIT(destroy, 'D', 3),
129 SHIPIT(ptboat, 'P', 2),
132 static ship_t cpuship[SHIPTYPES] =
134 SHIPIT(carrier, 'A', 5),
135 SHIPIT(battle, 'B', 4),
136 SHIPIT(destroy, 'D', 3),
138 SHIPIT(ptboat, 'P', 2),
141 /* "Hits" board, and main board. */
142 static char hits[2][BWIDTH][BDEPTH];
143 static char board[2][BWIDTH][BDEPTH];
145 static int turn; /* 0=player, 1=computer */
146 static int plywon = 0, cpuwon = 0; /* How many games has each won? */
148 static int salvo, blitz, closepack;
150 #define PR (void)addstr
152 static RETSIGTYPE uninitgame(int sig) GCC_NORETURN;
154 static RETSIGTYPE uninitgame(int sig GCC_UNUSED)
155 /* end the game, either normally or due to signal */
159 (void) reset_shell_mode();
162 ExitProgram(sig ? EXIT_FAILURE : EXIT_SUCCESS);
167 /* announce which game options are enabled */
169 if (salvo || blitz || closepack) {
170 (void) printw("Playing optional game (");
172 (void) printw("salvo, ");
174 (void) printw("nosalvo, ");
176 (void) printw("blitz ");
178 (void) printw("noblitz, ");
180 (void) printw("closepack)");
182 (void) printw("noclosepack)");
185 "Playing standard game (noblitz, nosalvo, noclosepack)");
193 srand((unsigned) (time(0L) + getpid())); /* Kick the random number generator */
195 (void) signal(SIGINT, uninitgame);
196 (void) signal(SIGINT, uninitgame);
197 (void) signal(SIGIOT, uninitgame); /* for assert(3) */
198 if (signal(SIGQUIT, SIG_IGN) != SIG_IGN)
199 (void) signal(SIGQUIT, uninitgame);
201 if ((tmpname = getlogin()) != 0) {
202 (void) strcpy(name, tmpname);
203 name[0] = toupper(name[0]);
205 (void) strcpy(name, dftname);
208 keypad(stdscr, TRUE);
209 (void) def_prog_mode();
216 (void) mvaddstr(4, 29, "Welcome to Battleship!");
220 PR(" \\ \\ \\ \\ \\_____________\n");
221 PR(" \\ \\ \\_____________ \\ \\/ |\n");
222 PR(" \\ \\/ \\ \\/ |\n");
223 PR(" \\/ \\_____/ |__\n");
224 PR(" ________________/ |\n");
225 PR(" \\ S.S. Penguin |\n");
227 PR(" \\___________________________________________________/\n");
229 (void) mvaddstr(22, 27, "Hit any key to continue...");
237 init_pair(COLOR_BLACK, COLOR_BLACK, COLOR_BLACK);
238 init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK);
239 init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK);
240 init_pair(COLOR_CYAN, COLOR_CYAN, COLOR_BLACK);
241 init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK);
242 init_pair(COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
243 init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK);
244 init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK);
247 #ifdef NCURSES_MOUSE_VERSION
248 (void) mousemask(BUTTON1_CLICKED, (mmask_t *) NULL);
249 #endif /* NCURSES_MOUSE_VERSION */
254 prompt(int n, NCURSES_CONST char *f, const char *s)
255 /* print a message at the prompt line */
257 (void) move(PROMPTLINE + n, 0);
264 error(NCURSES_CONST char *s)
266 (void) move(PROMPTLINE + 2, 0);
275 placeship(int b, ship_t * ss, int vis)
279 for (l = 0; l < ss->length; ++l) {
280 int newx = ss->x + l * xincr[ss->dir];
281 int newy = ss->y + l * yincr[ss->dir];
283 board[b][newx][newy] = ss->symbol;
286 (void) addch((chtype) ss->symbol);
295 return (((rand() & 0x7FFF) % n));
299 randomplace(int b, ship_t * ss)
300 /* generate a valid random ship placement into px,py */
304 ss->dir = rnd(2) ? E : S;
305 ss->x = rnd(BWIDTH - (ss->dir == E ? ss->length : 0));
306 ss->y = rnd(BDEPTH - (ss->dir == S ? ss->length : 0));
308 (!checkplace(b, ss, FALSE));
318 (void) mvaddstr(0, 35, "BATTLESHIPS");
319 (void) move(PROMPTLINE + 2, 0);
322 memset(board, 0, sizeof(char) * BWIDTH * BDEPTH * 2);
323 memset(hits, 0, sizeof(char) * BWIDTH * BDEPTH * 2);
324 for (i = 0; i < SHIPTYPES; i++) {
342 /* draw empty boards */
343 (void) mvaddstr(PYBASE - 2, PXBASE + 5, "Main Board");
344 (void) mvaddstr(PYBASE - 1, PXBASE - 3, numbers);
345 for (i = 0; i < BDEPTH; ++i) {
346 (void) mvaddch(PYBASE + i, PXBASE - 3, (chtype) (i + 'A'));
349 attron(COLOR_PAIR(COLOR_BLUE));
352 for (j = 0; j < BWIDTH; j++)
353 (void) addstr(" . ");
358 (void) addch((chtype) (i + 'A'));
360 (void) mvaddstr(PYBASE + BDEPTH, PXBASE - 3, numbers);
361 (void) mvaddstr(CYBASE - 2, CXBASE + 7, "Hit/Miss Board");
362 (void) mvaddstr(CYBASE - 1, CXBASE - 3, numbers);
363 for (i = 0; i < BDEPTH; ++i) {
364 (void) mvaddch(CYBASE + i, CXBASE - 3, (chtype) (i + 'A'));
367 attron(COLOR_PAIR(COLOR_BLUE));
370 for (j = 0; j < BWIDTH; j++)
371 (void) addstr(" . ");
376 (void) addch((chtype) (i + 'A'));
379 (void) mvaddstr(CYBASE + BDEPTH, CXBASE - 3, numbers);
381 (void) mvprintw(HYBASE, HXBASE,
382 "To position your ships: move the cursor to a spot, then");
383 (void) mvprintw(HYBASE + 1, HXBASE,
384 "type the first letter of a ship type to select it, then");
385 (void) mvprintw(HYBASE + 2, HXBASE,
386 "type a direction ([hjkl] or [4862]), indicating how the");
387 (void) mvprintw(HYBASE + 3, HXBASE,
388 "ship should be pointed. You may also type a ship letter");
389 (void) mvprintw(HYBASE + 4, HXBASE,
390 "followed by `r' to position it randomly, or type `R' to");
391 (void) mvprintw(HYBASE + 5, HXBASE,
392 "place all remaining ships randomly.");
394 (void) mvaddstr(MYBASE, MXBASE, "Aiming keys:");
395 (void) mvaddstr(SYBASE, SXBASE, "y k u 7 8 9");
396 (void) mvaddstr(SYBASE + 1, SXBASE, " \\|/ \\|/ ");
397 (void) mvaddstr(SYBASE + 2, SXBASE, "h-+-l 4-+-6");
398 (void) mvaddstr(SYBASE + 3, SXBASE, " /|\\ /|\\ ");
399 (void) mvaddstr(SYBASE + 4, SXBASE, "b j n 1 2 3");
401 /* have the computer place ships */
402 for (ss = cpuship; ss < cpuship + SHIPTYPES; ss++) {
403 randomplace(COMPUTER, ss);
404 placeship(COMPUTER, ss, FALSE);
407 ss = (ship_t *) NULL;
409 char c, docked[SHIPTYPES + 2], *cp = docked;
411 /* figure which ships still wait to be placed */
413 for (i = 0; i < SHIPTYPES; i++)
414 if (!plyship[i].placed)
415 *cp++ = plyship[i].symbol;
418 /* get a command letter */
419 prompt(1, "Type one of [%s] to pick a ship.", docked + 1);
421 c = getcoord(PLAYER);
423 (!strchr(docked, c));
428 /* map that into the corresponding symbol */
429 for (ss = plyship; ss < plyship + SHIPTYPES; ss++)
433 prompt(1, "Type one of [hjklrR] to place your %s.", ss->name);
440 (!strchr("hjklrR", c) || c == FF);
443 (void) clearok(stdscr, TRUE);
445 } else if (c == 'r') {
446 prompt(1, "Random-placing your %s", ss->name);
447 randomplace(PLAYER, ss);
448 placeship(PLAYER, ss, TRUE);
449 error((char *) NULL);
451 } else if (c == 'R') {
452 prompt(1, "Placing the rest of your fleet at random...", "");
453 for (ss = plyship; ss < plyship + SHIPTYPES; ss++)
455 randomplace(PLAYER, ss);
456 placeship(PLAYER, ss, TRUE);
459 error((char *) NULL);
460 } else if (strchr("hjkl8462", c)) {
483 if (checkplace(PLAYER, ss, TRUE)) {
484 placeship(PLAYER, ss, TRUE);
485 error((char *) NULL);
490 for (unplaced = i = 0; i < SHIPTYPES; i++)
491 unplaced += !plyship[i].placed;
497 (void) mvprintw(HYBASE, HXBASE,
498 "To fire, move the cursor to your chosen aiming point ");
499 (void) mvprintw(HYBASE + 1, HXBASE,
500 "and strike any key other than a motion key. ");
501 (void) mvprintw(HYBASE + 2, HXBASE,
503 (void) mvprintw(HYBASE + 3, HXBASE,
505 (void) mvprintw(HYBASE + 4, HXBASE,
507 (void) mvprintw(HYBASE + 5, HXBASE,
510 (void) prompt(0, "Press any key to start...", "");
526 (void) mvprintw(CYBASE + BDEPTH + 1, CXBASE + 11, "(%d, %c)",
530 (void) mvprintw(PYBASE + BDEPTH + 1, PXBASE + 11, "(%d, %c)",
535 switch (c = getch()) {
539 ny = cury + BDEPTH - 1;
552 nx = curx + BWIDTH - 1;
563 ny = cury + BDEPTH - 1;
564 nx = curx + BWIDTH - 1;
570 nx = curx + BWIDTH - 1;
575 ny = cury + BDEPTH - 1;
587 (void) clearok(stdscr, TRUE);
590 #ifdef NCURSES_MOUSE_VERSION
597 && myevent.y >= CY(0) && myevent.y <= CY(BDEPTH)
598 && myevent.x >= CX(0) && myevent.x <= CX(BDEPTH)) {
599 curx = CXINV(myevent.x);
600 cury = CYINV(myevent.y);
607 /* no fall through */
608 #endif /* NCURSES_MOUSE_VERSION */
612 (void) mvaddstr(CYBASE + BDEPTH + 1, CXBASE + 11, " ");
614 (void) mvaddstr(PYBASE + BDEPTH + 1, PXBASE + 11, " ");
624 collidecheck(int b, int y, int x)
625 /* is this location on the selected zboard adjacent to a ship? */
629 /* anything on the square */
630 if ((collide = IS_SHIP(board[b][x][y])) != FALSE)
633 /* anything on the neighbors */
637 for (i = 0; i < 8; i++) {
642 if (ONBOARD(xend, yend)
643 && IS_SHIP(board[b][xend][yend])) {
653 checkplace(int b, ship_t * ss, int vis)
657 /* first, check for board edges */
658 xend = ss->x + (ss->length - 1) * xincr[ss->dir];
659 yend = ss->y + (ss->length - 1) * yincr[ss->dir];
660 if (!ONBOARD(xend, yend)) {
664 error("Ship is hanging from the edge of the world");
667 error("Try fitting it on the board");
670 error("Figure I won't find it if you put it there?");
676 for (l = 0; l < ss->length; ++l) {
677 if (collidecheck(b, ss->y + l * yincr[ss->dir], ss->x + l * xincr[ss->dir])) {
681 error("There's already a ship there");
684 error("Collision alert! Aaaaaagh!");
687 error("Er, Admiral, what about the other ship?");
702 for (i = 0; i < 2; ++i) {
703 ss = (i) ? cpuship : plyship;
704 for (j = 0; j < SHIPTYPES; ++j, ++ss)
705 if (ss->length > ss->hits)
714 hitship(int x, int y)
715 /* register a hit on the targeted ship */
721 getyx(stdscr, oldy, oldx);
722 sb = (turn) ? plyship : cpuship;
723 if ((sym = board[OTHER][x][y]) == 0)
724 return ((ship_t *) NULL);
725 for (ss = sb; ss < sb + SHIPTYPES; ++ss)
726 if (ss->symbol == sym) {
727 if (++ss->hits < ss->length) /* still afloat? */
728 return ((ship_t *) NULL);
733 for (j = -1; j <= 1; j++) {
734 int bx = ss->x + j * xincr[(ss->dir + 2) % 8];
735 int by = ss->y + j * yincr[(ss->dir + 2) % 8];
737 for (i = -1; i <= ss->length; ++i) {
740 x1 = bx + i * xincr[ss->dir];
741 y1 = by + i * yincr[ss->dir];
742 if (ONBOARD(x1, y1)) {
743 hits[turn][x1][y1] = MARK_MISS;
744 if (turn % 2 == PLAYER) {
748 attron(COLOR_PAIR(COLOR_GREEN));
750 (void) addch(MARK_MISS);
756 (void) addch(SHOWSPLASH);
762 for (i = 0; i < ss->length; ++i) {
763 int x1 = ss->x + i * xincr[ss->dir];
764 int y1 = ss->y + i * yincr[ss->dir];
766 hits[turn][x1][y1] = ss->symbol;
767 if (turn % 2 == PLAYER) {
769 (void) addch((chtype) (ss->symbol));
774 attron(COLOR_PAIR(COLOR_RED));
776 (void) addch(SHOWHIT);
783 (void) move(oldy, oldx);
787 (void) move(oldy, oldx);
788 return ((ship_t *) NULL);
796 NCURSES_CONST char *m = NULL;
798 prompt(1, "Where do you want to shoot? ", "");
800 (void) getcoord(COMPUTER);
801 if (hits[PLAYER][curx][cury]) {
802 prompt(1, "You shelled this spot already! Try again.", "");
807 hit = IS_SHIP(board[COMPUTER][curx][cury]);
808 hits[PLAYER][curx][cury] = (hit ? MARK_HIT : MARK_MISS);
813 attron(COLOR_PAIR(COLOR_RED));
815 attron(COLOR_PAIR(COLOR_GREEN));
818 (void) addch((chtype) hits[PLAYER][curx][cury]);
823 prompt(1, "You %s.", hit ? "scored a hit" : "missed");
824 if (hit && (ss = hitship(curx, cury))) {
827 m = " You sank my %s!";
830 m = " I have this sinking feeling about my %s....";
833 m = " My %s has gone to Davy Jones's locker!";
836 m = " Glub, glub -- my %s is headed for the bottom!";
839 m = " You'll pick up survivors from my %s, I hope...!";
842 (void) printw(m, ss->name);
844 return (awinna() == -1);
862 for (s1 = s; *s1 && ch != *s1; ++s1)
865 (void) addch((chtype) ch);
873 randomfire(int *px, int *py)
874 /* random-fire routine -- implements simple diagonal-striping strategy */
876 static int turncount = 0;
877 static int srchstep = BEGINSTEP;
878 static int huntoffs; /* Offset on search strategy */
879 int ypossible[BWIDTH * BDEPTH], xpossible[BWIDTH * BDEPTH], nposs;
880 int ypreferred[BWIDTH * BDEPTH], xpreferred[BWIDTH * BDEPTH], npref;
883 if (turncount++ == 0)
884 huntoffs = rnd(srchstep);
886 /* first, list all possible moves */
888 for (x = 0; x < BWIDTH; x++)
889 for (y = 0; y < BDEPTH; y++)
890 if (!hits[COMPUTER][x][y]) {
891 xpossible[nposs] = x;
892 ypossible[nposs] = y;
894 if (((x + huntoffs) % srchstep) != (y % srchstep)) {
895 xpreferred[npref] = x;
896 ypreferred[npref] = y;
915 error("No moves possible?? Help!");
916 ExitProgram(EXIT_FAILURE);
926 cpufire(int x, int y)
927 /* fire away at given location */
932 hits[COMPUTER][x][y] = (hit = (board[PLAYER][x][y])) ? MARK_HIT : MARK_MISS;
933 (void) mvprintw(PROMPTLINE, 0,
934 "I shoot at %c%d. I %s!", y + 'A', x, hit ? "hit" :
936 if ((sunk = (hit && (ss = hitship(x, y)))) != 0)
937 (void) printw(" I've sunk your %s", ss->name);
944 attron(COLOR_PAIR(COLOR_RED));
946 attron(COLOR_PAIR(COLOR_GREEN));
949 (void) addch((chtype) (hit ? SHOWHIT : SHOWSPLASH));
954 return ((hit ? (sunk ? S_SUNK : S_HIT) : S_MISS) ? TRUE : FALSE);
958 * This code implements a fairly irregular FSM, so please forgive the rampant
959 * unstructuredness below. The five labels are states which need to be held
960 * between computer turns.
965 #define POSSIBLE(x, y) (ONBOARD(x, y) && !hits[COMPUTER][x][y])
966 #define RANDOM_FIRE 0
968 #define HUNT_DIRECT 2
970 #define REVERSE_JUMP 4
971 #define SECOND_PASS 5
972 static int next = RANDOM_FIRE;
975 int navail, x, y, d, n;
979 case RANDOM_FIRE: /* last shot was random and missed */
982 if (!(hit = cpufire(x, y)))
988 next = (hit == S_SUNK) ? RANDOM_FIRE : RANDOM_HIT;
992 case RANDOM_HIT: /* last shot was random and hit */
993 used[E / 2] = used[S / 2] = used[W / 2] = used[N / 2] = FALSE;
996 case HUNT_DIRECT: /* last shot hit, we're looking for ship's long axis */
997 for (d = navail = 0; d < 4; d++) {
998 x = ts.x + xincr[d * 2];
999 y = ts.y + yincr[d * 2];
1000 if (!used[d] && POSSIBLE(x, y))
1005 if (navail == 0) /* no valid places for shots adjacent... */
1006 goto refire; /* ...so we must random-fire */
1008 for (d = 0, n = rnd(navail) + 1; n; n--)
1015 x = ts.x + xincr[d * 2];
1016 y = ts.y + yincr[d * 2];
1018 assert(POSSIBLE(x, y));
1020 if (!(hit = cpufire(x, y)))
1027 next = (hit == S_SUNK) ? RANDOM_FIRE : FIRST_PASS;
1032 case FIRST_PASS: /* we have a start and a direction now */
1033 x = ts.x + xincr[ts.dir];
1034 y = ts.y + yincr[ts.dir];
1035 if (POSSIBLE(x, y) && (hit = cpufire(x, y))) {
1039 next = (hit == S_SUNK) ? RANDOM_FIRE : FIRST_PASS;
1041 next = REVERSE_JUMP;
1044 case REVERSE_JUMP: /* nail down the ship's other end */
1046 x = ts.x + ts.hits * xincr[d];
1047 y = ts.y + ts.hits * yincr[d];
1048 if (POSSIBLE(x, y) && (hit = cpufire(x, y))) {
1053 next = (hit == S_SUNK) ? RANDOM_FIRE : SECOND_PASS;
1058 case SECOND_PASS: /* kill squares not caught on first pass */
1059 x = ts.x + xincr[ts.dir];
1060 y = ts.y + yincr[ts.dir];
1061 if (POSSIBLE(x, y) && (hit = cpufire(x, y))) {
1065 next = (hit == S_SUNK) ? RANDOM_FIRE : SECOND_PASS;
1072 /* check for continuation and/or winner */
1081 (void) mvprintw(PROMPTLINE + 2, 0,
1082 "New state %d, x=%d, y=%d, d=%d",
1085 return ((hit) ? TRUE : FALSE);
1094 for (ss = cpuship; ss < cpuship + SHIPTYPES; ss++)
1095 for (j = 0; j < ss->length; j++) {
1096 cgoto(ss->y + j * yincr[ss->dir], ss->x + j * xincr[ss->dir]);
1097 (void) addch((chtype) ss->symbol);
1104 j = 18 + strlen(name);
1109 (void) mvprintw(1, (COLWIDTH - j) / 2,
1110 "%s: %d Computer: %d", name, plywon, cpuwon);
1112 prompt(2, (awinna())? "Want to be humiliated again, %s [yn]? "
1113 : "Going to give me a chance for revenge, %s [yn]? ", name);
1114 return (sgetc("YN") == 'Y');
1118 do_options(int c, char *op[])
1123 for (i = 1; i < c; i++) {
1127 (void) fprintf(stderr, "Usage: battle [-s | -b] [-c]\n");
1128 (void) fprintf(stderr, "\tWhere the options are:\n");
1129 (void) fprintf(stderr, "\t-s : play a salvo game\n");
1130 (void) fprintf(stderr, "\t-b : play a blitz game\n");
1131 (void) fprintf(stderr, "\t-c : ships may be adjacent\n");
1132 ExitProgram(EXIT_FAILURE);
1139 (void) fprintf(stderr,
1140 "Bad Arg: -b and -s are mutually exclusive\n");
1141 ExitProgram(EXIT_FAILURE);
1147 (void) fprintf(stderr,
1148 "Bad Arg: -s and -b are mutually exclusive\n");
1149 ExitProgram(EXIT_FAILURE);
1156 (void) fprintf(stderr,
1157 "Bad arg: type \"%s ?\" for usage message\n",
1159 ExitProgram(EXIT_FAILURE);
1169 register int i, shots;
1170 register ship_t *sp;
1173 sp = cpuship; /* count cpu shots */
1175 sp = plyship; /* count player shots */
1177 for (i = 0, shots = 0; i < SHIPTYPES; i++, sp++) {
1178 if (sp->hits >= sp->length)
1179 continue; /* dead ship */
1187 main(int argc, char *argv[])
1189 setlocale(LC_ALL, "");
1191 do_options(argc, argv);
1196 while (awinna() == -1) {
1209 if (cputurn() && awinna() != -1)
1212 if (plyturn() && awinna() != -1)
1218 while (turn ? cputurn() : plyturn())
1228 /* bs.c ends here */