]> thyrsus.com Git - bs.git/commitdiff
Froze 2.0 release.
authorEric S. Raymond <esr@thyrsus.com>
Mon, 15 Nov 1993 18:01:23 +0000 (18:01 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Mon, 15 Nov 1993 18:01:23 +0000 (18:01 +0000)
Makefile
README
bs.c
bs.xml

index 071dd066f652937e28227b8e9e7de311d65bacef..bfddf2c58f20635fa470cd6ee7215259c1577aee 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,15 +1,17 @@
-#      Makefile for Battleships
+#      Makefile for bs, the Battleships game
 
 # Flags for use with the Linux ncurses package (recommended)
 # CFLAGS = -DNDEBUG  -I/usr/local/include -L/usr/local/lib
 # TERMLIB = -lncurses
+# CC = gcc
 
 # Flags for use with stock curses
 CFLAGS = -DNDEBUG
 TERMLIB = -lcurses
+CC = gcc
 
 bs: bs.c
-       cc $(CFLAGS) -o bs bs.c $(TERMLIB)
+       $(CC) $(CFLAGS) -o bs bs.c $(TERMLIB)
 
 lint:
        lint bs.c -lcurses
diff --git a/README b/README
index a77286ec1c4761901648263d801ea2eb1bf6a1ac..fb992d704c376801c0e9821106004eecf3fc1244 100644 (file)
--- a/README
+++ b/README
@@ -1,3 +1,5 @@
+                               BS 2.0
+
 Battleships is an intrinsically silly game, but I couldn't resist fixing this
 sucker. It now has a purely visual interface (you place ships and call for
 shots by moving the cursor around the board using the standard yuhjklbn keys).
@@ -12,7 +14,8 @@ it back, compile with -DPENGUIN. One strike against featureitis...
 The code now lints as clean as the broken SysV curses lint library will let it.
 
 Some #ifdefs in the code should result in the right things being done for
-BSD or USG systems. They key off A_UNDERLINE.
+BSD or USG systems. They key off A_UNDERLINE.  If you're using the Linux
+ncurses library, tell the makefile.
 
 This was probably a waste of a day or so. But what the hack -- rewriting the
 strategy robot as an FSM was fun, and maybe the interface will set a good
@@ -28,6 +31,8 @@ stuffed in suits and condemned to write COBOL for the rest of their days...
 
 O.K., I feel better now that I've got that off my chest...
 
+November 1993: I've added function key support, and ANSI/POSIXized the code.
+
                                                Eric S. Raymond
-                                               esr@snark.uu.net
+                                               esr@snark.thyrsus.com
 
diff --git a/bs.c b/bs.c
index 8e2a8b736ab536dba90ff754607a22d44de168af..bca0b95d29236b3e24e258922f12fc49d5255d10 100644 (file)
--- a/bs.c
+++ b/bs.c
@@ -4,9 +4,12 @@
  * with improved user interface, autoconfiguration and code cleanup
  *             by Eric S. Raymond <esr@snark.thyrsus.com>
  * v1.2 with color support and minor portability fixes, November 1990
+ * v2.0 featuring strict ANSI/POSIX conformance, November 1993.
  */
+#define _POSIX_SOURCE
 
 #include <stdio.h>
+#include <termios.h>
 #include <curses.h>
 #include <signal.h>
 #include <ctype.h>
@@ -40,6 +43,8 @@ extern char *strchr(), *strcpy();
 extern long time();
 extern void exit();
 
+static bool checkplace();
+
 /*
  * Constants for tuning the random-fire algorithm. It prefers moves that
  * diagonal-stripe the board with a stripe separation of srchstep. If
@@ -102,7 +107,7 @@ static char destroy[] = "Destroyer";
 static char ptboat[] = "PT Boat";
 
 static char name[40];
-static char dftname[] = "Stranger";
+static char dftname[] = "stranger";
 
 /* direction constants */
 #define E      0
@@ -210,12 +215,17 @@ static void intro()
        (void)signal(SIGQUIT,uninitgame);
 
     if(tmpname = getlogin())
+    {
        (void)strcpy(name,tmpname);
+       name[0] = toupper(name[0]);
+    }
     else
        (void)strcpy(name,dftname);
-    name[0] = toupper(name[0]);
 
     (void)initscr();
+#ifdef KEY_MIN
+    keypad(stdscr, TRUE);
+#endif /* KEY_MIN */
     (void)saveterm();
     (void)nonl();
     (void)cbreak();
@@ -301,6 +311,12 @@ int vis;
     ss->hits = 0;
 }
 
+static int rnd(n)
+int n;
+{
+    return(((rand() & 0x7FFF) % n));
+}
+
 static void randomplace(b, ss)
 /* generate a valid random ship placement into px,py */
 int b;
@@ -408,6 +424,7 @@ static void initgame()
     ss = (ship_t *)NULL;
     do {
        extern char *strchr();
+       static char getcoord();
        char c, docked[SHIPTYPES + 2], *cp = docked;
 
        /* figure which ships still wait to be placed */
@@ -512,12 +529,6 @@ static void initgame()
     (void) getch();
 }
 
-static int rnd(n)
-int n;
-{
-    return(((rand() & 0x7FFF) % n));
-}
-
 static int getcoord(atcpu)
 int atcpu;
 {
@@ -543,14 +554,54 @@ int atcpu;
 
        switch(c = getch())
        {
-       case 'k': case '8': ny = cury+BDEPTH-1; nx = curx;   break;
-       case 'j': case '2': ny = cury+1;        nx = curx;   break;
-       case 'h': case '4': ny = cury;          nx = curx+BWIDTH-1; break;
-       case 'l': case '6': ny = cury;          nx = curx+1; break;
-       case 'y': case '7': ny = cury+BDEPTH-1; nx = curx+BWIDTH-1; break;
-       case 'b': case '1': ny = cury+1;        nx = curx+BWIDTH-1; break;
-       case 'u': case '9': ny = cury+BDEPTH-1; nx = curx+1; break;
-       case 'n': case '3': ny = cury+1;        nx = curx+1; break;
+       case 'k': case '8':
+#ifdef KEY_MIN
+       case KEY_UP:
+#endif /* KEY_MIN */
+           ny = cury+BDEPTH-1; nx = curx;
+           break;
+       case 'j': case '2':
+#ifdef KEY_MIN
+       case KEY_DOWN:
+#endif /* KEY_MIN */
+           ny = cury+1;        nx = curx;
+           break;
+       case 'h': case '4':
+#ifdef KEY_MIN
+       case KEY_LEFT:
+#endif /* KEY_MIN */
+           ny = cury;          nx = curx+BWIDTH-1;
+           break;
+       case 'l': case '6':
+#ifdef KEY_MIN
+       case KEY_RIGHT:
+#endif /* KEY_MIN */
+           ny = cury;          nx = curx+1;
+           break;
+       case 'y': case '7':
+#ifdef KEY_MIN
+       case KEY_A1:
+#endif /* KEY_MIN */
+           ny = cury+BDEPTH-1; nx = curx+BWIDTH-1;
+           break;
+       case 'b': case '1':
+#ifdef KEY_MIN
+       case KEY_C1:
+#endif /* KEY_MIN */
+           ny = cury+1;        nx = curx+BWIDTH-1;
+           break;
+       case 'u': case '9':
+#ifdef KEY_MIN
+       case KEY_A3:
+#endif /* KEY_MIN */
+           ny = cury+BDEPTH-1; nx = curx+1;
+           break;
+       case 'n': case '3':
+#ifdef KEY_MIN
+       case KEY_C3:
+#endif /* KEY_MIN */
+           ny = cury+1;        nx = curx+1;
+           break;
        case FF:
            nx = curx; ny = cury;
            (void)clearok(stdscr, TRUE);
@@ -598,7 +649,7 @@ int y, x;
     return(collide);
 }
 
-static int checkplace(b, ss, vis)
+static bool checkplace(b, ss, vis)
 int b;
 ship_t *ss;
 int vis;
@@ -610,7 +661,7 @@ int vis;
     yend = ss->y + ss->length * yincr[ss->dir];
     if (!ONBOARD(xend, yend))
     {
-       if(vis)
+       if (vis)
            switch(rnd(3))
            {
            case 0:
@@ -637,16 +688,16 @@ int vis;
                        error("There's already a ship there");
                        break;
                    case 1:
-                       error("Collision alert! Aaaaaagh!");
+                       error("Collision alert!  Aaaaaagh!");
                        break;
                    case 2:
                        error("Er, Admiral, what about the other ship?");
                        break;
                    }
-           return(0);
+           return(FALSE);
            }
        }
-    return(1);
+    return(TRUE);
 }
 
 static int awinna()
diff --git a/bs.xml b/bs.xml
index 38cfe82a9811d7455de010b4a572c53248194d16..00aa063904ab61b115daa964fcf85d13796f6adf 100644 (file)
--- a/bs.xml
+++ b/bs.xml
@@ -1,4 +1,4 @@
-.TH BATTLESHIPS 6 "Aug 23, 1989"
+.TH BATTLESHIPS 6 "Nov 15 1993"
 .SH NAME
 bs \- battleships game
 .SH SYNOPSIS
@@ -7,7 +7,8 @@ battle [ -b | -s ] [ -c ]
 This program allows you to play the familiar Battleships game against the
 computer on a 10x10 board. The interface is visual and largely
 self-explanatory; you place your ships and pick your shots by moving the
-cursor around the `sea' with the rogue/hack motion keys hjklyubn.
+cursor around the `sea' with the rogue/hack motion keys hjklyubn.  If
+your UNIX has a modern (non-BSD) curses, your arrow keys will also work.
 .PP
 Note that when selecting a ship to place, you must type the capital letter
 (these are, after all, capital ships). During ship placement, the `r' command
@@ -35,8 +36,10 @@ Normally, ships must be separated by at least one square of open water. The
 -c option disables this check and allows them to close-pack.
 .PP
 The algorithm the computer uses once it has found a ship to sink is provably
-optimal. The dispersion criterion for the random-fire algorithm may not be.
+optimal.  The dispersion criterion for the random-fire algorithm may not be.
 .SH AUTHORS
 Originally written by one Bruce Holloway in 1986. Salvo mode added by Chuck A.
 DeGaul (cbosgd!cad). Visual user interface, `closepack' option, code rewrite
-and manual page by Eric S. Raymond <esr@snark.thyrsus.com> August 1989.
+and manual page by Eric S. Raymond <esr@snark.thyrsus.com> August
+1989.  Keypad support and ANSI/POSIX conformance, November '93.
+