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.17 1997/04/06 01:42:57 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)
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 unsigned hits; /* how many times has this ship been hit? */
122 char symbol; /* symbol for game purposes */
123 unsigned char 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], board[2][BWIDTH][BDEPTH];
153 static int turn; /* 0=player, 1=computer */
154 static int plywon=0, cpuwon=0; /* How many games has each won? */
156 static int salvo, blitz, closepack;
158 #define PR (void)addstr
160 static RETSIGTYPE uninitgame(int sig) GCC_NORETURN;
162 static void uninitgame(int sig GCC_UNUSED)
163 /* end the game, either normally or due to signal */
173 static void announceopts(void)
174 /* announce which game options are enabled */
176 if (salvo || blitz || closepack)
178 (void) printw("Playing optional game (");
180 (void) printw("salvo, ");
182 (void) printw("nosalvo, ");
184 (void) printw("blitz ");
186 (void) printw("noblitz, ");
188 (void) printw("closepack)");
190 (void) printw("noclosepack)");
194 "Playing standard game (noblitz, nosalvo, noclosepack)");
197 static void intro(void)
201 srand((unsigned)(time(0L)+getpid())); /* Kick the random number generator */
203 (void) signal(SIGINT,uninitgame);
204 (void) signal(SIGINT,uninitgame);
205 (void) signal(SIGIOT,uninitgame); /* for assert(3) */
206 if(signal(SIGQUIT,SIG_IGN) != SIG_IGN)
207 (void)signal(SIGQUIT,uninitgame);
209 if((tmpname = getlogin()) != 0)
211 (void)strcpy(name,tmpname);
212 name[0] = toupper(name[0]);
215 (void)strcpy(name,dftname);
219 keypad(stdscr, TRUE);
228 (void)mvaddstr(4,29,"Welcome to Battleship!");
232 PR(" \\ \\ \\ \\ \\_____________\n");
233 PR(" \\ \\ \\_____________ \\ \\/ |\n");
234 PR(" \\ \\/ \\ \\/ |\n");
235 PR(" \\/ \\_____/ |__\n");
236 PR(" ________________/ |\n");
237 PR(" \\ S.S. Penguin |\n");
239 PR(" \\___________________________________________________/\n");
241 (void) mvaddstr(22,27,"Hit any key to continue..."); (void)refresh();
248 init_pair(COLOR_BLACK, COLOR_BLACK, COLOR_BLACK);
249 init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK);
250 init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK);
251 init_pair(COLOR_CYAN, COLOR_CYAN, COLOR_BLACK);
252 init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK);
253 init_pair(COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
254 init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK);
255 init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK);
258 #ifdef NCURSES_MOUSE_VERSION
259 (void) mousemask(BUTTON1_CLICKED, (mmask_t *)NULL);
260 #endif /* NCURSES_MOUSE_VERSION*/
264 static void prompt(int n, NCURSES_CONST char *f, const char *s)
265 /* print a message at the prompt line */
267 (void) move(PROMPTLINE + n, 0);
273 static void error(NCURSES_CONST char *s)
275 (void) move(PROMPTLINE + 2, 0);
284 static void placeship(int b, ship_t *ss, int vis)
288 for(l = 0; l < ss->length; ++l)
290 int newx = ss->x + l * xincr[ss->dir];
291 int newy = ss->y + l * yincr[ss->dir];
293 board[b][newx][newy] = ss->symbol;
297 (void) addch((chtype)ss->symbol);
303 static int rnd(int n)
305 return(((rand() & 0x7FFF) % n));
308 static void randomplace(int b, ship_t *ss)
309 /* generate a valid random ship placement into px,py */
311 register int bwidth = BWIDTH - ss->length;
312 register int bdepth = BDEPTH - ss->length;
317 ss->dir = rnd(2) ? E : S;
319 (!checkplace(b, ss, FALSE));
322 static void initgame(void)
328 (void) mvaddstr(0,35,"BATTLESHIPS");
329 (void) move(PROMPTLINE + 2, 0);
332 memset(board, 0, sizeof(char) * BWIDTH * BDEPTH * 2);
333 memset(hits, 0, sizeof(char) * BWIDTH * BDEPTH * 2);
334 for (i = 0; i < SHIPTYPES; i++)
337 ss->x = ss->y = ss->dir = ss->hits = ss->placed = 0;
339 ss->x = ss->y = ss->dir = ss->hits = ss->placed = 0;
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)
347 (void) mvaddch(PYBASE + i, PXBASE - 3, (chtype)(i + 'A'));
350 attron(COLOR_PAIR(COLOR_BLUE));
353 for (j = 0; j < BWIDTH; j++)
354 (void) addstr(" . ");
359 (void) addch((chtype)(i + 'A'));
361 (void) mvaddstr(PYBASE + BDEPTH, PXBASE - 3,numbers);
362 (void) mvaddstr(CYBASE - 2, CXBASE + 7,"Hit/Miss Board");
363 (void) mvaddstr(CYBASE - 1, CXBASE - 3, numbers);
364 for(i=0; i < BDEPTH; ++i)
366 (void) mvaddch(CYBASE + i, CXBASE - 3, (chtype)(i + 'A'));
369 attron(COLOR_PAIR(COLOR_BLUE));
372 for (j = 0; j < BWIDTH; j++)
373 (void) addstr(" . ");
378 (void) addch((chtype)(i + 'A'));
381 (void) mvaddstr(CYBASE + BDEPTH,CXBASE - 3,numbers);
383 (void) mvprintw(HYBASE, HXBASE,
384 "To position your ships: move the cursor to a spot, then");
385 (void) mvprintw(HYBASE+1,HXBASE,
386 "type the first letter of a ship type to select it, then");
387 (void) mvprintw(HYBASE+2,HXBASE,
388 "type a direction ([hjkl] or [4862]), indicating how the");
389 (void) mvprintw(HYBASE+3,HXBASE,
390 "ship should be pointed. You may also type a ship letter");
391 (void) mvprintw(HYBASE+4,HXBASE,
392 "followed by `r' to position it randomly, or type `R' to");
393 (void) mvprintw(HYBASE+5,HXBASE,
394 "place all remaining ships randomly.");
396 (void) mvaddstr(MYBASE, MXBASE, "Aiming keys:");
397 (void) mvaddstr(SYBASE, SXBASE, "y k u 7 8 9");
398 (void) mvaddstr(SYBASE+1, SXBASE, " \\|/ \\|/ ");
399 (void) mvaddstr(SYBASE+2, SXBASE, "h-+-l 4-+-6");
400 (void) mvaddstr(SYBASE+3, SXBASE, " /|\\ /|\\ ");
401 (void) mvaddstr(SYBASE+4, SXBASE, "b j n 1 2 3");
403 /* have the computer place ships */
404 for(ss = cpuship; ss < cpuship + SHIPTYPES; ss++)
406 randomplace(COMPUTER, ss);
407 placeship(COMPUTER, ss, FALSE);
412 char c, docked[SHIPTYPES + 2], *cp = docked;
414 /* figure which ships still wait to be placed */
416 for (i = 0; i < SHIPTYPES; i++)
417 if (!plyship[i].placed)
418 *cp++ = plyship[i].symbol;
421 /* get a command letter */
422 prompt(1, "Type one of [%s] to pick a ship.", docked+1);
424 c = getcoord(PLAYER);
426 (!strchr(docked, c));
432 /* map that into the corresponding symbol */
433 for (ss = plyship; ss < plyship + SHIPTYPES; ss++)
437 prompt(1, "Type one of [hjklrR] to place your %s.", ss->name);
444 (!strchr("hjklrR", c) || c == FF);
448 (void)clearok(stdscr, TRUE);
453 prompt(1, "Random-placing your %s", ss->name);
454 randomplace(PLAYER, ss);
455 placeship(PLAYER, ss, TRUE);
461 prompt(1, "Placing the rest of your fleet at random...", "");
462 for (ss = plyship; ss < plyship + SHIPTYPES; ss++)
465 randomplace(PLAYER, ss);
466 placeship(PLAYER, ss, TRUE);
471 else if (strchr("hjkl8462", c))
478 case 'k': case '8': ss->dir = N; break;
479 case 'j': case '2': ss->dir = S; break;
480 case 'h': case '4': ss->dir = W; break;
481 case 'l': case '6': ss->dir = E; break;
484 if (checkplace(PLAYER, ss, TRUE))
486 placeship(PLAYER, ss, TRUE);
492 for (unplaced = i = 0; i < SHIPTYPES; i++)
493 unplaced += !plyship[i].placed;
499 (void) mvprintw(HYBASE, HXBASE,
500 "To fire, move the cursor to your chosen aiming point ");
501 (void) mvprintw(HYBASE+1, HXBASE,
502 "and strike any key other than a motion key. ");
503 (void) mvprintw(HYBASE+2, HXBASE,
505 (void) mvprintw(HYBASE+3, HXBASE,
507 (void) mvprintw(HYBASE+4, HXBASE,
509 (void) mvprintw(HYBASE+5, HXBASE,
512 (void) prompt(0, "Press any key to start...", "");
516 static int getcoord(int atcpu)
529 (void) mvprintw(CYBASE + BDEPTH+1, CXBASE+11, "(%d, %c)", curx, 'A'+cury);
534 (void) mvprintw(PYBASE + BDEPTH+1, PXBASE+11, "(%d, %c)", curx, 'A'+cury);
544 ny = cury+BDEPTH-1; nx = curx;
550 ny = cury+1; nx = curx;
556 ny = cury; nx = curx+BWIDTH-1;
562 ny = cury; nx = curx+1;
568 ny = cury+BDEPTH-1; nx = curx+BWIDTH-1;
574 ny = cury+1; nx = curx+BWIDTH-1;
580 ny = cury+BDEPTH-1; nx = curx+1;
586 ny = cury+1; nx = curx+1;
589 nx = curx; ny = cury;
590 (void)clearok(stdscr, TRUE);
593 #ifdef NCURSES_MOUSE_VERSION
600 && myevent.y >= CY(0) && myevent.y <= CY(BDEPTH)
601 && myevent.x >= CX(0) && myevent.x <= CX(BDEPTH))
603 curx = CXINV(myevent.x);
604 cury = CYINV(myevent.y);
613 /* no fall through */
614 #endif /* NCURSES_MOUSE_VERSION */
618 (void) mvaddstr(CYBASE + BDEPTH + 1, CXBASE + 11, " ");
620 (void) mvaddstr(PYBASE + BDEPTH + 1, PXBASE + 11, " ");
629 static int collidecheck(int b, int y, int x)
630 /* is this location on the selected zboard adjacent to a ship? */
634 /* anything on the square */
635 if ((collide = IS_SHIP(board[b][x][y])) != 0)
638 /* anything on the neighbors */
643 for (i = 0; i < 8; i++)
649 if (ONBOARD(xend, yend))
650 collide += IS_SHIP(board[b][xend][yend]);
656 static bool checkplace(int b, ship_t *ss, int vis)
660 /* first, check for board edges */
661 xend = ss->x + ss->length * xincr[ss->dir];
662 yend = ss->y + ss->length * yincr[ss->dir];
663 if (!ONBOARD(xend, yend))
669 error("Ship is hanging from the edge of the world");
672 error("Try fitting it on the board");
675 error("Figure I won't find it if you put it there?");
681 for(l = 0; l < ss->length; ++l)
683 if(collidecheck(b, ss->y+l*yincr[ss->dir], ss->x+l*xincr[ss->dir]))
689 error("There's already a ship there");
692 error("Collision alert! Aaaaaagh!");
695 error("Er, Admiral, what about the other ship?");
704 static int awinna(void)
711 ss = (i) ? cpuship : plyship;
712 for(j=0; j < SHIPTYPES; ++j, ++ss)
713 if(ss->length > ss->hits)
721 static ship_t *hitship(int x, int y)
722 /* register a hit on the targeted ship */
728 getyx(stdscr, oldy, oldx);
729 sb = (turn) ? plyship : cpuship;
730 if((sym = board[OTHER][x][y]) == 0)
731 return((ship_t *)NULL);
732 for(ss = sb; ss < sb + SHIPTYPES; ++ss)
733 if(ss->symbol == sym)
735 if (++ss->hits < ss->length) /* still afloat? */
736 return((ship_t *)NULL);
742 for (j = -1; j <= 1; j++)
744 int bx = ss->x + j * xincr[(ss->dir + 2) % 8];
745 int by = ss->y + j * yincr[(ss->dir + 2) % 8];
747 for (i = -1; i <= ss->length; ++i)
751 x1 = bx + i * xincr[ss->dir];
752 y1 = by + i * yincr[ss->dir];
755 hits[turn][x1][y1] = MARK_MISS;
756 if (turn % 2 == PLAYER)
761 attron(COLOR_PAIR(COLOR_GREEN));
763 (void)addch(MARK_MISS);
772 for (i = 0; i < ss->length; ++i)
774 int x1 = ss->x + i * xincr[ss->dir];
775 int y1 = ss->y + i * yincr[ss->dir];
777 hits[turn][x1][y1] = ss->symbol;
778 if (turn % 2 == PLAYER)
781 (void) addch((chtype)(ss->symbol));
785 (void) move(oldy, oldx);
789 (void) move(oldy, oldx);
790 return((ship_t *)NULL);
793 static int plyturn(void)
797 NCURSES_CONST char *m = NULL;
799 prompt(1, "Where do you want to shoot? ", "");
802 (void) getcoord(COMPUTER);
803 if (hits[PLAYER][curx][cury])
805 prompt(1, "You shelled this spot already! Try again.", "");
811 hit = IS_SHIP(board[COMPUTER][curx][cury]);
812 hits[PLAYER][curx][cury] = hit ? MARK_HIT : MARK_MISS;
817 attron(COLOR_PAIR(COLOR_RED));
819 attron(COLOR_PAIR(COLOR_GREEN));
821 (void) addch((chtype)hits[PLAYER][curx][cury]);
826 prompt(1, "You %s.", hit ? "scored a hit" : "missed");
827 if(hit && (ss = hitship(curx, cury)))
832 m = " You sank my %s!";
835 m = " I have this sinking feeling about my %s....";
838 m = " My %s has gone to Davy Jones's locker!";
841 m = " Glub, glub -- my %s is headed for the bottom!";
844 m = " You'll pick up survivors from my %s, I hope...!";
847 (void)printw(m, ss->name);
849 return(awinna() == -1);
854 static int sgetc(const char *s)
867 for (s1=s; *s1 && ch != *s1; ++s1)
871 (void) addch((chtype)ch);
879 static void randomfire(int *px, int *py)
880 /* random-fire routine -- implements simple diagonal-striping strategy */
882 static int turncount = 0;
883 static int srchstep = BEGINSTEP;
884 static int huntoffs; /* Offset on search strategy */
885 int ypossible[BWIDTH * BDEPTH], xpossible[BWIDTH * BDEPTH], nposs;
886 int ypreferred[BWIDTH * BDEPTH], xpreferred[BWIDTH * BDEPTH], npref;
889 if (turncount++ == 0)
890 huntoffs = rnd(srchstep);
892 /* first, list all possible moves */
894 for (x = 0; x < BWIDTH; x++)
895 for (y = 0; y < BDEPTH; y++)
896 if (!hits[COMPUTER][x][y])
898 xpossible[nposs] = x;
899 ypossible[nposs] = y;
901 if (((x+huntoffs) % srchstep) != (y % srchstep))
903 xpreferred[npref] = x;
904 ypreferred[npref] = y;
928 error("No moves possible?? Help!");
938 static bool cpufire(int x, int y)
939 /* fire away at given location */
944 hits[COMPUTER][x][y] = (hit = (board[PLAYER][x][y])) ? MARK_HIT : MARK_MISS;
945 (void) mvprintw(PROMPTLINE, 0,
946 "I shoot at %c%d. I %s!", y + 'A', x, hit ? "hit" : "miss");
947 if ((sunk = (hit && (ss = hitship(x, y)))) != 0)
948 (void) printw(" I've sunk your %s", ss->name);
955 attron(COLOR_PAIR(COLOR_RED));
957 attron(COLOR_PAIR(COLOR_GREEN));
959 (void)addch((chtype)(hit ? SHOWHIT : SHOWSPLASH));
964 return(hit ? (sunk ? S_SUNK : S_HIT) : S_MISS);
968 * This code implements a fairly irregular FSM, so please forgive the rampant
969 * unstructuredness below. The five labels are states which need to be held
970 * between computer turns.
972 static bool cputurn(void)
974 #define POSSIBLE(x, y) (ONBOARD(x, y) && !hits[COMPUTER][x][y])
975 #define RANDOM_FIRE 0
977 #define HUNT_DIRECT 2
979 #define REVERSE_JUMP 4
980 #define SECOND_PASS 5
981 static int next = RANDOM_FIRE;
984 int navail, x, y, d, n, hit = S_MISS;
988 case RANDOM_FIRE: /* last shot was random and missed */
991 if (!(hit = cpufire(x, y)))
997 next = (hit == S_SUNK) ? RANDOM_FIRE : RANDOM_HIT;
1001 case RANDOM_HIT: /* last shot was random and hit */
1002 used[E/2] = used[S/2] = used[W/2] = used[N/2] = FALSE;
1005 case HUNT_DIRECT: /* last shot hit, we're looking for ship's long axis */
1006 for (d = navail = 0; d < 4; d++)
1008 x = ts.x + xincr[d*2]; y = ts.y + yincr[d*2];
1009 if (!used[d] && POSSIBLE(x, y))
1014 if (navail == 0) /* no valid places for shots adjacent... */
1015 goto refire; /* ...so we must random-fire */
1018 for (d = 0, n = rnd(navail) + 1; n; n--)
1025 x = ts.x + xincr[d*2];
1026 y = ts.y + yincr[d*2];
1028 assert(POSSIBLE(x, y));
1030 if (!(hit = cpufire(x, y)))
1034 ts.x = x; ts.y = y; ts.dir = d*2; ts.hits++;
1035 next = (hit == S_SUNK) ? RANDOM_FIRE : FIRST_PASS;
1040 case FIRST_PASS: /* we have a start and a direction now */
1041 x = ts.x + xincr[ts.dir];
1042 y = ts.y + yincr[ts.dir];
1043 if (POSSIBLE(x, y) && (hit = cpufire(x, y)))
1045 ts.x = x; ts.y = y; ts.hits++;
1046 next = (hit == S_SUNK) ? RANDOM_FIRE : FIRST_PASS;
1049 next = REVERSE_JUMP;
1052 case REVERSE_JUMP: /* nail down the ship's other end */
1054 x = ts.x + ts.hits * xincr[d];
1055 y = ts.y + ts.hits * yincr[d];
1056 if (POSSIBLE(x, y) && (hit = cpufire(x, y)))
1058 ts.x = x; ts.y = y; ts.dir = d; ts.hits++;
1059 next = (hit == S_SUNK) ? RANDOM_FIRE : SECOND_PASS;
1065 case SECOND_PASS: /* kill squares not caught on first pass */
1066 x = ts.x + xincr[ts.dir];
1067 y = ts.y + yincr[ts.dir];
1068 if (POSSIBLE(x, y) && (hit = cpufire(x, y)))
1070 ts.x = x; ts.y = y; ts.hits++;
1071 next = (hit == S_SUNK) ? RANDOM_FIRE: SECOND_PASS;
1079 /* check for continuation and/or winner */
1089 (void) mvprintw(PROMPTLINE + 2, 0,
1090 "New state %d, x=%d, y=%d, d=%d",
1102 for (ss = cpuship; ss < cpuship + SHIPTYPES; ss++)
1103 for(j = 0; j < ss->length; j++)
1105 cgoto(ss->y + j * yincr[ss->dir], ss->x + j * xincr[ss->dir]);
1106 (void)addch((chtype)ss->symbol);
1113 j = 18 + strlen(name);
1118 (void) mvprintw(1,(COLWIDTH-j)/2,
1119 "%s: %d Computer: %d",name,plywon,cpuwon);
1121 prompt(2, (awinna()) ? "Want to be humiliated again, %s [yn]? "
1122 : "Going to give me a chance for revenge, %s [yn]? ",name);
1123 return(sgetc("YN") == 'Y');
1126 static void do_options(int c, char *op[])
1138 (void) fprintf(stderr, "Usage: battle [-s | -b] [-c]\n");
1139 (void) fprintf(stderr, "\tWhere the options are:\n");
1140 (void) fprintf(stderr, "\t-s : play a salvo game\n");
1141 (void) fprintf(stderr, "\t-b : play a blitz game\n");
1142 (void) fprintf(stderr, "\t-c : ships may be adjacent\n");
1152 (void) fprintf(stderr,
1153 "Bad Arg: -b and -s are mutually exclusive\n");
1161 (void) fprintf(stderr,
1162 "Bad Arg: -s and -b are mutually exclusive\n");
1170 (void) fprintf(stderr,
1171 "Bad arg: type \"%s ?\" for usage message\n", op[0]);
1179 static int scount(int who)
1181 register int i, shots;
1182 register ship_t *sp;
1185 sp = cpuship; /* count cpu shots */
1187 sp = plyship; /* count player shots */
1189 for (i=0, shots = 0; i < SHIPTYPES; i++, sp++)
1191 if (sp->hits >= sp->length)
1192 continue; /* dead ship */
1199 int main(int argc, char *argv[])
1201 do_options(argc, argv);
1206 while(awinna() == -1)
1226 if (cputurn() && awinna() != -1)
1231 if (plyturn() && awinna() != -1)
1238 while(turn ? cputurn() : plyturn())
1248 /* bs.c ends here */