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.22 1997/12/20 15:11:53 tom Exp $
13 #include <test.priv.h>
22 #define SIGIOT SIGABRT
25 #ifndef A_UNDERLINE /* BSD curses */
26 #define beep() write(1,"\007",1);
28 #define saveterm savetty
29 #define resetterm resetty
30 #define nocbreak nocrmode
32 #endif /* !A_UNDERLINE */
34 static int getcoord(int);
37 * Constants for tuning the random-fire algorithm. It prefers moves that
38 * diagonal-stripe the board with a stripe separation of srchstep. If
39 * no such preferred moves are found, srchstep is decremented.
41 #define BEGINSTEP 3 /* initial value of srchstep */
43 /* miscellaneous constants */
45 #define OTHER (1-turn)
50 #define CTRLC '\003' /* used as terminate command */
51 #define FF '\014' /* used as redraw command */
53 /* coordinate handling */
59 #define SHOWSPLASH ' '
60 #define IS_SHIP(c) (isupper(c) ? TRUE : FALSE)
62 /* how to position us on player board */
65 #define PY(y) (PYBASE + (y))
66 #define PX(x) (PXBASE + (x)*3)
67 #define pgoto(y, x) (void)move(PY(y), PX(x))
69 /* how to position us on cpu board */
72 #define CY(y) (CYBASE + (y))
73 #define CX(x) (CXBASE + (x)*3)
74 #define CYINV(y) ((y) - CYBASE)
75 #define CXINV(x) (((x) - CXBASE) / 3)
76 #define cgoto(y, x) (void)move(CY(y), CX(x))
78 #define ONBOARD(x, y) (x >= 0 && x < BWIDTH && y >= 0 && y < BDEPTH)
80 /* other board locations */
82 #define PROMPTLINE 21 /* prompt line */
83 #define SYBASE CYBASE + BDEPTH + 3 /* move key diagram */
85 #define MYBASE SYBASE - 1 /* diagram caption */
87 #define HYBASE SYBASE - 1 /* help area */
90 /* this will need to be changed if BWIDTH changes */
91 static char numbers[] = " 0 1 2 3 4 5 6 7 8 9";
93 static char carrier[] = "Aircraft Carrier";
94 static char battle[] = "Battleship";
95 static char sub[] = "Submarine";
96 static char destroy[] = "Destroyer";
97 static char ptboat[] = "PT Boat";
100 static char dftname[] = "stranger";
102 /* direction constants */
111 static int xincr[8] = {1, 1, 0, -1, -1, -1, 0, 1};
112 static int yincr[8] = {0, 1, 1, 1, 0, -1, -1, -1};
114 /* current ship position and direction */
115 static int curx = (BWIDTH / 2);
116 static int cury = (BDEPTH / 2);
120 char *name; /* name of the ship type */
121 int hits; /* how many times has this ship been hit? */
122 char symbol; /* symbol for game purposes */
123 int length; /* length of ship */
124 char x, y; /* coordinates of ship start point */
125 unsigned char dir; /* direction of `bow' */
126 bool placed; /* has it been placed on the board? */
130 static bool checkplace(int b, ship_t *ss, int vis);
132 static ship_t plyship[SHIPTYPES] =
134 { carrier, 0, 'A', 5},
135 { battle, 0, 'B', 4},
136 { destroy, 0, 'D', 3},
138 { ptboat, 0, 'P', 2},
141 static ship_t cpuship[SHIPTYPES] =
143 { carrier, 0, 'A', 5},
144 { battle, 0, 'B', 4},
145 { destroy, 0, 'D', 3},
147 { ptboat, 0, 'P', 2},
150 /* "Hits" board, and main board. */
151 static char hits[2][BWIDTH][BDEPTH];
152 static char board[2][BWIDTH][BDEPTH];
154 static int turn; /* 0=player, 1=computer */
155 static int plywon=0, cpuwon=0; /* How many games has each won? */
157 static int salvo, blitz, closepack;
159 #define PR (void)addstr
161 static RETSIGTYPE uninitgame(int sig) GCC_NORETURN;
163 static RETSIGTYPE uninitgame(int sig GCC_UNUSED)
164 /* end the game, either normally or due to signal */
174 static void announceopts(void)
175 /* announce which game options are enabled */
177 if (salvo || blitz || closepack)
179 (void) printw("Playing optional game (");
181 (void) printw("salvo, ");
183 (void) printw("nosalvo, ");
185 (void) printw("blitz ");
187 (void) printw("noblitz, ");
189 (void) printw("closepack)");
191 (void) printw("noclosepack)");
195 "Playing standard game (noblitz, nosalvo, noclosepack)");
198 static void intro(void)
202 srand((unsigned)(time(0L)+getpid())); /* Kick the random number generator */
204 (void) signal(SIGINT,uninitgame);
205 (void) signal(SIGINT,uninitgame);
206 (void) signal(SIGIOT,uninitgame); /* for assert(3) */
207 if(signal(SIGQUIT,SIG_IGN) != SIG_IGN)
208 (void)signal(SIGQUIT,uninitgame);
210 if((tmpname = getlogin()) != 0)
212 (void)strcpy(name,tmpname);
213 name[0] = toupper(name[0]);
216 (void)strcpy(name,dftname);
220 keypad(stdscr, TRUE);
229 (void)mvaddstr(4,29,"Welcome to Battleship!");
233 PR(" \\ \\ \\ \\ \\_____________\n");
234 PR(" \\ \\ \\_____________ \\ \\/ |\n");
235 PR(" \\ \\/ \\ \\/ |\n");
236 PR(" \\/ \\_____/ |__\n");
237 PR(" ________________/ |\n");
238 PR(" \\ S.S. Penguin |\n");
240 PR(" \\___________________________________________________/\n");
242 (void) mvaddstr(22,27,"Hit any key to continue..."); (void)refresh();
249 init_pair(COLOR_BLACK, COLOR_BLACK, COLOR_BLACK);
250 init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK);
251 init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK);
252 init_pair(COLOR_CYAN, COLOR_CYAN, COLOR_BLACK);
253 init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK);
254 init_pair(COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
255 init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK);
256 init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK);
259 #ifdef NCURSES_MOUSE_VERSION
260 (void) mousemask(BUTTON1_CLICKED, (mmask_t *)NULL);
261 #endif /* NCURSES_MOUSE_VERSION*/
265 static void prompt(int n, NCURSES_CONST char *f, const char *s)
266 /* print a message at the prompt line */
268 (void) move(PROMPTLINE + n, 0);
274 static void error(NCURSES_CONST char *s)
276 (void) move(PROMPTLINE + 2, 0);
285 static void placeship(int b, ship_t *ss, int vis)
289 for(l = 0; l < ss->length; ++l)
291 int newx = ss->x + l * xincr[ss->dir];
292 int newy = ss->y + l * yincr[ss->dir];
294 board[b][newx][newy] = ss->symbol;
298 (void) addch((chtype)ss->symbol);
304 static int rnd(int n)
306 return(((rand() & 0x7FFF) % n));
309 static void randomplace(int b, ship_t *ss)
310 /* generate a valid random ship placement into px,py */
312 register int bwidth = BWIDTH - ss->length;
313 register int bdepth = BDEPTH - ss->length;
318 ss->dir = rnd(2) ? E : S;
320 (!checkplace(b, ss, FALSE));
323 static void initgame(void)
329 (void) mvaddstr(0,35,"BATTLESHIPS");
330 (void) move(PROMPTLINE + 2, 0);
333 memset(board, 0, sizeof(char) * BWIDTH * BDEPTH * 2);
334 memset(hits, 0, sizeof(char) * BWIDTH * BDEPTH * 2);
335 for (i = 0; i < SHIPTYPES; i++)
354 /* draw empty boards */
355 (void) mvaddstr(PYBASE - 2, PXBASE + 5, "Main Board");
356 (void) mvaddstr(PYBASE - 1, PXBASE - 3,numbers);
357 for(i=0; i < BDEPTH; ++i)
359 (void) mvaddch(PYBASE + i, PXBASE - 3, (chtype)(i + 'A'));
362 attron(COLOR_PAIR(COLOR_BLUE));
365 for (j = 0; j < BWIDTH; j++)
366 (void) addstr(" . ");
371 (void) addch((chtype)(i + 'A'));
373 (void) mvaddstr(PYBASE + BDEPTH, PXBASE - 3,numbers);
374 (void) mvaddstr(CYBASE - 2, CXBASE + 7,"Hit/Miss Board");
375 (void) mvaddstr(CYBASE - 1, CXBASE - 3, numbers);
376 for(i=0; i < BDEPTH; ++i)
378 (void) mvaddch(CYBASE + i, CXBASE - 3, (chtype)(i + 'A'));
381 attron(COLOR_PAIR(COLOR_BLUE));
384 for (j = 0; j < BWIDTH; j++)
385 (void) addstr(" . ");
390 (void) addch((chtype)(i + 'A'));
393 (void) mvaddstr(CYBASE + BDEPTH,CXBASE - 3,numbers);
395 (void) mvprintw(HYBASE, HXBASE,
396 "To position your ships: move the cursor to a spot, then");
397 (void) mvprintw(HYBASE+1,HXBASE,
398 "type the first letter of a ship type to select it, then");
399 (void) mvprintw(HYBASE+2,HXBASE,
400 "type a direction ([hjkl] or [4862]), indicating how the");
401 (void) mvprintw(HYBASE+3,HXBASE,
402 "ship should be pointed. You may also type a ship letter");
403 (void) mvprintw(HYBASE+4,HXBASE,
404 "followed by `r' to position it randomly, or type `R' to");
405 (void) mvprintw(HYBASE+5,HXBASE,
406 "place all remaining ships randomly.");
408 (void) mvaddstr(MYBASE, MXBASE, "Aiming keys:");
409 (void) mvaddstr(SYBASE, SXBASE, "y k u 7 8 9");
410 (void) mvaddstr(SYBASE+1, SXBASE, " \\|/ \\|/ ");
411 (void) mvaddstr(SYBASE+2, SXBASE, "h-+-l 4-+-6");
412 (void) mvaddstr(SYBASE+3, SXBASE, " /|\\ /|\\ ");
413 (void) mvaddstr(SYBASE+4, SXBASE, "b j n 1 2 3");
415 /* have the computer place ships */
416 for(ss = cpuship; ss < cpuship + SHIPTYPES; ss++)
418 randomplace(COMPUTER, ss);
419 placeship(COMPUTER, ss, FALSE);
424 char c, docked[SHIPTYPES + 2], *cp = docked;
426 /* figure which ships still wait to be placed */
428 for (i = 0; i < SHIPTYPES; i++)
429 if (!plyship[i].placed)
430 *cp++ = plyship[i].symbol;
433 /* get a command letter */
434 prompt(1, "Type one of [%s] to pick a ship.", docked+1);
436 c = getcoord(PLAYER);
438 (!strchr(docked, c));
444 /* map that into the corresponding symbol */
445 for (ss = plyship; ss < plyship + SHIPTYPES; ss++)
449 prompt(1, "Type one of [hjklrR] to place your %s.", ss->name);
456 (!strchr("hjklrR", c) || c == FF);
460 (void)clearok(stdscr, TRUE);
465 prompt(1, "Random-placing your %s", ss->name);
466 randomplace(PLAYER, ss);
467 placeship(PLAYER, ss, TRUE);
473 prompt(1, "Placing the rest of your fleet at random...", "");
474 for (ss = plyship; ss < plyship + SHIPTYPES; ss++)
477 randomplace(PLAYER, ss);
478 placeship(PLAYER, ss, TRUE);
483 else if (strchr("hjkl8462", c))
490 case 'k': case '8': ss->dir = N; break;
491 case 'j': case '2': ss->dir = S; break;
492 case 'h': case '4': ss->dir = W; break;
493 case 'l': case '6': ss->dir = E; break;
496 if (checkplace(PLAYER, ss, TRUE))
498 placeship(PLAYER, ss, TRUE);
504 for (unplaced = i = 0; i < SHIPTYPES; i++)
505 unplaced += !plyship[i].placed;
511 (void) mvprintw(HYBASE, HXBASE,
512 "To fire, move the cursor to your chosen aiming point ");
513 (void) mvprintw(HYBASE+1, HXBASE,
514 "and strike any key other than a motion key. ");
515 (void) mvprintw(HYBASE+2, HXBASE,
517 (void) mvprintw(HYBASE+3, HXBASE,
519 (void) mvprintw(HYBASE+4, HXBASE,
521 (void) mvprintw(HYBASE+5, HXBASE,
524 (void) prompt(0, "Press any key to start...", "");
528 static int getcoord(int atcpu)
541 (void) mvprintw(CYBASE + BDEPTH+1, CXBASE+11, "(%d, %c)", curx, 'A'+cury);
546 (void) mvprintw(PYBASE + BDEPTH+1, PXBASE+11, "(%d, %c)", curx, 'A'+cury);
556 ny = cury+BDEPTH-1; nx = curx;
562 ny = cury+1; nx = curx;
568 ny = cury; nx = curx+BWIDTH-1;
574 ny = cury; nx = curx+1;
580 ny = cury+BDEPTH-1; nx = curx+BWIDTH-1;
586 ny = cury+1; nx = curx+BWIDTH-1;
592 ny = cury+BDEPTH-1; nx = curx+1;
598 ny = cury+1; nx = curx+1;
601 nx = curx; ny = cury;
602 (void)clearok(stdscr, TRUE);
605 #ifdef NCURSES_MOUSE_VERSION
612 && myevent.y >= CY(0) && myevent.y <= CY(BDEPTH)
613 && myevent.x >= CX(0) && myevent.x <= CX(BDEPTH))
615 curx = CXINV(myevent.x);
616 cury = CYINV(myevent.y);
625 /* no fall through */
626 #endif /* NCURSES_MOUSE_VERSION */
630 (void) mvaddstr(CYBASE + BDEPTH + 1, CXBASE + 11, " ");
632 (void) mvaddstr(PYBASE + BDEPTH + 1, PXBASE + 11, " ");
641 static bool collidecheck(int b, int y, int x)
642 /* is this location on the selected zboard adjacent to a ship? */
646 /* anything on the square */
647 if ((collide = IS_SHIP(board[b][x][y])) != FALSE)
650 /* anything on the neighbors */
655 for (i = 0; i < 8; i++)
661 if (ONBOARD(xend, yend)
662 && IS_SHIP(board[b][xend][yend])) {
671 static bool checkplace(int b, ship_t *ss, int vis)
675 /* first, check for board edges */
676 xend = ss->x + ss->length * xincr[ss->dir];
677 yend = ss->y + ss->length * yincr[ss->dir];
678 if (!ONBOARD(xend, yend))
684 error("Ship is hanging from the edge of the world");
687 error("Try fitting it on the board");
690 error("Figure I won't find it if you put it there?");
696 for(l = 0; l < ss->length; ++l)
698 if(collidecheck(b, ss->y+l*yincr[ss->dir], ss->x+l*xincr[ss->dir]))
704 error("There's already a ship there");
707 error("Collision alert! Aaaaaagh!");
710 error("Er, Admiral, what about the other ship?");
719 static int awinna(void)
726 ss = (i) ? cpuship : plyship;
727 for(j=0; j < SHIPTYPES; ++j, ++ss)
728 if(ss->length > ss->hits)
736 static ship_t *hitship(int x, int y)
737 /* register a hit on the targeted ship */
743 getyx(stdscr, oldy, oldx);
744 sb = (turn) ? plyship : cpuship;
745 if((sym = board[OTHER][x][y]) == 0)
746 return((ship_t *)NULL);
747 for(ss = sb; ss < sb + SHIPTYPES; ++ss)
748 if(ss->symbol == sym)
750 if (++ss->hits < ss->length) /* still afloat? */
751 return((ship_t *)NULL);
757 for (j = -1; j <= 1; j++)
759 int bx = ss->x + j * xincr[(ss->dir + 2) % 8];
760 int by = ss->y + j * yincr[(ss->dir + 2) % 8];
762 for (i = -1; i <= ss->length; ++i)
766 x1 = bx + i * xincr[ss->dir];
767 y1 = by + i * yincr[ss->dir];
770 hits[turn][x1][y1] = MARK_MISS;
771 if (turn % 2 == PLAYER)
776 attron(COLOR_PAIR(COLOR_GREEN));
778 (void)addch(MARK_MISS);
787 for (i = 0; i < ss->length; ++i)
789 int x1 = ss->x + i * xincr[ss->dir];
790 int y1 = ss->y + i * yincr[ss->dir];
792 hits[turn][x1][y1] = ss->symbol;
793 if (turn % 2 == PLAYER)
796 (void) addch((chtype)(ss->symbol));
800 (void) move(oldy, oldx);
804 (void) move(oldy, oldx);
805 return((ship_t *)NULL);
808 static int plyturn(void)
812 NCURSES_CONST char *m = NULL;
814 prompt(1, "Where do you want to shoot? ", "");
817 (void) getcoord(COMPUTER);
818 if (hits[PLAYER][curx][cury])
820 prompt(1, "You shelled this spot already! Try again.", "");
826 hit = IS_SHIP(board[COMPUTER][curx][cury]);
827 hits[PLAYER][curx][cury] = (hit ? MARK_HIT : MARK_MISS);
832 attron(COLOR_PAIR(COLOR_RED));
834 attron(COLOR_PAIR(COLOR_GREEN));
836 (void) addch((chtype)hits[PLAYER][curx][cury]);
841 prompt(1, "You %s.", hit ? "scored a hit" : "missed");
842 if(hit && (ss = hitship(curx, cury)))
847 m = " You sank my %s!";
850 m = " I have this sinking feeling about my %s....";
853 m = " My %s has gone to Davy Jones's locker!";
856 m = " Glub, glub -- my %s is headed for the bottom!";
859 m = " You'll pick up survivors from my %s, I hope...!";
862 (void)printw(m, ss->name);
864 return(awinna() == -1);
869 static int sgetc(const char *s)
882 for (s1=s; *s1 && ch != *s1; ++s1)
886 (void) addch((chtype)ch);
894 static void randomfire(int *px, int *py)
895 /* random-fire routine -- implements simple diagonal-striping strategy */
897 static int turncount = 0;
898 static int srchstep = BEGINSTEP;
899 static int huntoffs; /* Offset on search strategy */
900 int ypossible[BWIDTH * BDEPTH], xpossible[BWIDTH * BDEPTH], nposs;
901 int ypreferred[BWIDTH * BDEPTH], xpreferred[BWIDTH * BDEPTH], npref;
904 if (turncount++ == 0)
905 huntoffs = rnd(srchstep);
907 /* first, list all possible moves */
909 for (x = 0; x < BWIDTH; x++)
910 for (y = 0; y < BDEPTH; y++)
911 if (!hits[COMPUTER][x][y])
913 xpossible[nposs] = x;
914 ypossible[nposs] = y;
916 if (((x+huntoffs) % srchstep) != (y % srchstep))
918 xpreferred[npref] = x;
919 ypreferred[npref] = y;
943 error("No moves possible?? Help!");
953 static int cpufire(int x, int y)
954 /* fire away at given location */
959 hits[COMPUTER][x][y] = (hit = (board[PLAYER][x][y])) ? MARK_HIT : MARK_MISS;
960 (void) mvprintw(PROMPTLINE, 0,
961 "I shoot at %c%d. I %s!", y + 'A', x, hit ? "hit" : "miss");
962 if ((sunk = (hit && (ss = hitship(x, y)))) != 0)
963 (void) printw(" I've sunk your %s", ss->name);
970 attron(COLOR_PAIR(COLOR_RED));
972 attron(COLOR_PAIR(COLOR_GREEN));
974 (void)addch((chtype)(hit ? SHOWHIT : SHOWSPLASH));
979 return ((hit ? (sunk ? S_SUNK : S_HIT) : S_MISS) ? TRUE : FALSE);
983 * This code implements a fairly irregular FSM, so please forgive the rampant
984 * unstructuredness below. The five labels are states which need to be held
985 * between computer turns.
987 static bool cputurn(void)
989 #define POSSIBLE(x, y) (ONBOARD(x, y) && !hits[COMPUTER][x][y])
990 #define RANDOM_FIRE 0
992 #define HUNT_DIRECT 2
994 #define REVERSE_JUMP 4
995 #define SECOND_PASS 5
996 static int next = RANDOM_FIRE;
999 int navail, x, y, d, n;
1004 case RANDOM_FIRE: /* last shot was random and missed */
1007 if (!(hit = cpufire(x, y)))
1013 next = (hit == S_SUNK) ? RANDOM_FIRE : RANDOM_HIT;
1017 case RANDOM_HIT: /* last shot was random and hit */
1018 used[E/2] = used[S/2] = used[W/2] = used[N/2] = FALSE;
1021 case HUNT_DIRECT: /* last shot hit, we're looking for ship's long axis */
1022 for (d = navail = 0; d < 4; d++)
1024 x = ts.x + xincr[d*2]; y = ts.y + yincr[d*2];
1025 if (!used[d] && POSSIBLE(x, y))
1030 if (navail == 0) /* no valid places for shots adjacent... */
1031 goto refire; /* ...so we must random-fire */
1034 for (d = 0, n = rnd(navail) + 1; n; n--)
1041 x = ts.x + xincr[d*2];
1042 y = ts.y + yincr[d*2];
1044 assert(POSSIBLE(x, y));
1046 if (!(hit = cpufire(x, y)))
1050 ts.x = x; ts.y = y; ts.dir = d*2; ts.hits++;
1051 next = (hit == S_SUNK) ? RANDOM_FIRE : FIRST_PASS;
1056 case FIRST_PASS: /* we have a start and a direction now */
1057 x = ts.x + xincr[ts.dir];
1058 y = ts.y + yincr[ts.dir];
1059 if (POSSIBLE(x, y) && (hit = cpufire(x, y)))
1061 ts.x = x; ts.y = y; ts.hits++;
1062 next = (hit == S_SUNK) ? RANDOM_FIRE : FIRST_PASS;
1065 next = REVERSE_JUMP;
1068 case REVERSE_JUMP: /* nail down the ship's other end */
1070 x = ts.x + ts.hits * xincr[d];
1071 y = ts.y + ts.hits * yincr[d];
1072 if (POSSIBLE(x, y) && (hit = cpufire(x, y)))
1074 ts.x = x; ts.y = y; ts.dir = d; ts.hits++;
1075 next = (hit == S_SUNK) ? RANDOM_FIRE : SECOND_PASS;
1081 case SECOND_PASS: /* kill squares not caught on first pass */
1082 x = ts.x + xincr[ts.dir];
1083 y = ts.y + yincr[ts.dir];
1084 if (POSSIBLE(x, y) && (hit = cpufire(x, y)))
1086 ts.x = x; ts.y = y; ts.hits++;
1087 next = (hit == S_SUNK) ? RANDOM_FIRE: SECOND_PASS;
1095 /* check for continuation and/or winner */
1105 (void) mvprintw(PROMPTLINE + 2, 0,
1106 "New state %d, x=%d, y=%d, d=%d",
1109 return ((hit) ? TRUE : FALSE);
1118 for (ss = cpuship; ss < cpuship + SHIPTYPES; ss++)
1119 for(j = 0; j < ss->length; j++)
1121 cgoto(ss->y + j * yincr[ss->dir], ss->x + j * xincr[ss->dir]);
1122 (void)addch((chtype)ss->symbol);
1129 j = 18 + strlen(name);
1134 (void) mvprintw(1,(COLWIDTH-j)/2,
1135 "%s: %d Computer: %d",name,plywon,cpuwon);
1137 prompt(2, (awinna()) ? "Want to be humiliated again, %s [yn]? "
1138 : "Going to give me a chance for revenge, %s [yn]? ",name);
1139 return(sgetc("YN") == 'Y');
1142 static void do_options(int c, char *op[])
1154 (void) fprintf(stderr, "Usage: battle [-s | -b] [-c]\n");
1155 (void) fprintf(stderr, "\tWhere the options are:\n");
1156 (void) fprintf(stderr, "\t-s : play a salvo game\n");
1157 (void) fprintf(stderr, "\t-b : play a blitz game\n");
1158 (void) fprintf(stderr, "\t-c : ships may be adjacent\n");
1168 (void) fprintf(stderr,
1169 "Bad Arg: -b and -s are mutually exclusive\n");
1177 (void) fprintf(stderr,
1178 "Bad Arg: -s and -b are mutually exclusive\n");
1186 (void) fprintf(stderr,
1187 "Bad arg: type \"%s ?\" for usage message\n", op[0]);
1195 static int scount(int who)
1197 register int i, shots;
1198 register ship_t *sp;
1201 sp = cpuship; /* count cpu shots */
1203 sp = plyship; /* count player shots */
1205 for (i=0, shots = 0; i < SHIPTYPES; i++, sp++)
1207 if (sp->hits >= sp->length)
1208 continue; /* dead ship */
1215 int main(int argc, char *argv[])
1217 do_options(argc, argv);
1222 while(awinna() == -1)
1242 if (cputurn() && awinna() != -1)
1247 if (plyturn() && awinna() != -1)
1254 while(turn ? cputurn() : plyturn())
1264 /* bs.c ends here */