]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/bs.c
ncurses 6.0 - patch 20170617
[ncurses.git] / test / bs.c
index e529e2783ed8347bb7d7e6e7b9258318988e66ed..5959758858e9c7b284806b12140e17a90c3e36e1 100644 (file)
--- a/test/bs.c
+++ b/test/bs.c
@@ -34,7 +34,7 @@
  * v2.0 featuring strict ANSI/POSIX conformance, November 1993.
  * v2.1 with ncurses mouse support, September 1995
  *
- * $Id: bs.c,v 1.66 2017/04/15 13:38:13 tom Exp $
+ * $Id: bs.c,v 1.68 2017/06/17 18:45:40 tom Exp $
  */
 
 #include <test.priv.h>
@@ -220,6 +220,7 @@ intro(void)
     srand((unsigned) (time(0L) + getpid()));   /* Kick the random number generator */
 
     CATCHALL(uninitgame);
+    (void) initscr();
 
     if ((tmpname = getlogin()) != 0 &&
        (your_name = strdup(tmpname)) != 0) {
@@ -228,7 +229,6 @@ intro(void)
        your_name = strdup(dftname);
     }
 
-    (void) initscr();
     keypad(stdscr, TRUE);
     (void) def_prog_mode();
     (void) nonl();
@@ -1003,7 +1003,7 @@ cputurn(void)
 #define REVERSE_JUMP   4
 #define SECOND_PASS    5
     static int next = RANDOM_FIRE;
-    static bool used[4];
+    static bool used[5];
     static ship_t ts;
     int navail, x, y, d, n;
     int hit = S_MISS;
@@ -1039,10 +1039,10 @@ cputurn(void)
            goto refire;        /* ...so we must random-fire */
        else {
            n = rnd(navail) + 1;
-           for (d = 0; used[d]; d++) ;
+           for (d = 0; d < 4 && used[d]; d++) ;
            /* used[d] is first that == 0 */
            for (; n > 1; n--)
-               while (used[++d]) ;
+               while (d < 4 && used[++d]) ;
            /* used[d] is next that == 0 */
 
            assert(d < 4);