]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - gomoku/main.c
- remove duplicate comment
[bsdgames-darwin.git] / gomoku / main.c
index 769bfef75e8a6eaa17f9ca3359952dbddfc26d34..4d9acb26d065bad6eb93512e67f8a1702a54a83d 100644 (file)
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.23 2010/03/29 03:51:55 dholland Exp $       */
+/*     $NetBSD: main.c,v 1.27 2016/06/12 02:15:26 dholland Exp $       */
 
 /*
  * Copyright (c) 1994
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1994\
 #if 0
 static char sccsid[] = "@(#)main.c     8.4 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: main.c,v 1.23 2010/03/29 03:51:55 dholland Exp $");
+__RCSID("$NetBSD: main.c,v 1.27 2016/06/12 02:15:26 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -94,10 +94,6 @@ main(int argc, char **argv)
        char *tmp;
        int color, curmove, i, ch;
        int input[2];
-       static const char *const fmt[2] = {
-               "%3d %-6s",
-               "%3d        %-6s"
-       };
 
        /* Revoke setgid privileges */
        setgid(getgid());
@@ -145,11 +141,7 @@ main(int argc, char **argv)
        }
 
        if (!debug)
-#ifdef SVR4
-               srand(time(0));
-#else
                srandom(time(0));
-#endif
        if (interactive)
                cursinit();             /* initialize curses */
 again:
@@ -165,9 +157,11 @@ again:
 #endif
 
                if (inputfp == NULL && test == 0) {
-                       ask("black or white? ");
+                       move(BSZ3, 0);
+                       printw("Black moves first. ");
+                       ask("(B)lack or (W)hite? ");
                        for (;;) {
-                               ch = getchar();
+                               ch = get_key(NULL);
                                if (ch == 'b' || ch == 'B') {
                                        color = BLACK;
                                        break;
@@ -176,8 +170,11 @@ again:
                                        color = WHITE;
                                        break;
                                }
-                               move(BSZ3, 0);
-                               printw("Black moves first. Please enter `black' or `white'\n");
+                               if (ch == 'q' || ch == 'Q') {
+                                       quit();
+                               }
+                               beep();
+                               ask("Please choose (B)lack or (W)hite: ");
                        }
                        move(BSZ3, 0);
                        clrtoeol();
@@ -253,12 +250,12 @@ again:
                case USER: /* input comes from standard input */
                getinput:
                        if (interactive) {
-                               ask("move? ");
+                               ask("Select move, (S)ave or (Q)uit.");
                                curmove = get_coord();
                                if (curmove == SAVE) {
                                        FILE *fp;
 
-                                       ask("save file name? ");
+                                       ask("Save file name? ");
                                        (void)get_line(fname, sizeof(fname));
                                        if ((fp = fopen(fname, "w")) == NULL) {
                                                misclog("cannot create save file");
@@ -294,7 +291,8 @@ again:
                        break;
                }
                if (interactive) {
-                       misclog(fmt[color], movenum, stoc(curmove));
+                       misclog("%3d%s%-6s", movenum, color ? "        " : " ",
+                           stoc(curmove));
                }
                if ((i = makemove(color, curmove)) != MOVEOK)
                        break;
@@ -313,7 +311,7 @@ again:
                                addstr("Rats! you won");
                        break;
                case TIE:
-                       addstr("Wow! its a tie");
+                       addstr("Wow! It's a tie");
                        break;
                case ILLEGAL:
                        addstr("Illegal move");
@@ -323,14 +321,14 @@ again:
                bdisp();
                if (i != RESIGN) {
                replay:
-                       ask("replay? ");
-                       if (get_line(buf, sizeof(buf)) &&
-                           (buf[0] == 'y' || buf[0] == 'Y'))
+                       ask("Play again? ");
+                       ch = get_key("YyNnQqSs"); 
+                       if (ch == 'Y' || ch == 'y')
                                goto again;
-                       if (strcmp(buf, "save") == 0) {
+                       if (ch == 'S') {
                                FILE *fp;
 
-                               ask("save file name? ");
+                               ask("Save file name? ");
                                (void)get_line(fname, sizeof(fname));
                                if ((fp = fopen(fname, "w")) == NULL) {
                                        misclog("cannot create save file");
@@ -382,7 +380,7 @@ whatsup(int signum)
        if (!interactive)
                quit();
 top:
-       ask("cmd? ");
+       ask("debug command: ");
        if (!get_line(input, sizeof(input)))
                quit();
        switch (*input) {
@@ -564,12 +562,17 @@ panic(const char *fmt, ...)
 {
        va_list ap;
 
+       if (interactive) {
+               bdisp();
+               cursfini();
+       }
+
        fprintf(stderr, "%s: ", prog);
        va_start(ap, fmt);
        vfprintf(stderr, fmt, ap);
        va_end(ap);
        fprintf(stderr, "\n");
 
-       fputs("resign\n", stdout);
-       quit();
+       fputs("resign\n", stdout);
+       exit(1);
 }