BSD 4_4 release
[unix-history] / usr / src / games / canfield / canfield / canfield.c
index 3155998..492f04a 100644 (file)
@@ -1,18 +1,45 @@
 /*
 /*
- * Copyright (c) 1982 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+ * Copyright (c) 1980, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1980 Regents of the University of California.\n\
- All rights reserved.\n";
-#endif not lint
+static char copyright[] =
+"@(#) Copyright (c) 1980, 1993\n\
      The Regents of the University of California.  All rights reserved.\n";
+#endif /* not lint */
 
 #ifndef lint
 
 #ifndef lint
-static char sccsid[] = "@(#)canfield.c 5.2 (Berkeley) %G%";
-#endif not lint
+static char sccsid[] = "@(#)canfield.c 8.1 (Berkeley) 5/31/93";
+#endif /* not lint */
 
 /*
  * The canfield program
 
 /*
  * The canfield program
@@ -25,10 +52,14 @@ static char sccsid[] = "@(#)canfield.c      5.2 (Berkeley) %G%";
  *     Betting by Kirk McKusick
  */
 
  *     Betting by Kirk McKusick
  */
 
+#include <sys/types.h>
+
 #include <curses.h>
 #include <ctype.h>
 #include <signal.h>
 #include <curses.h>
 #include <ctype.h>
 #include <signal.h>
-#include <sys/types.h>
+#include <termios.h>
+
+#include "pathnames.h"
 
 #define        decksize        52
 #define originrow      0
 
 #define        decksize        52
 #define originrow      0
@@ -129,6 +160,7 @@ bool mtfdone, Cflag = FALSE;
 #define BETTINGBOX     2
 #define NOBOX          3
 int status = INSTRUCTIONBOX;
 #define BETTINGBOX     2
 #define NOBOX          3
 int status = INSTRUCTIONBOX;
+int uid;
 
 /*
  * Basic betting costs
 
 /*
  * Basic betting costs
@@ -154,7 +186,7 @@ struct betinfo {
        long    wins;           /* total winnings */
        long    worth;          /* net worth after costs */
 };
        long    wins;           /* total winnings */
        long    worth;          /* net worth after costs */
 };
-struct betinfo this, total;
+struct betinfo this, game, total;
 bool startedgame = FALSE, infullgame = FALSE;
 time_t acctstart;
 int dbfd = -1;
 bool startedgame = FALSE, infullgame = FALSE;
 time_t acctstart;
 int dbfd = -1;
@@ -180,9 +212,9 @@ movebox()
                break;
        }
        move(moverow, boxcol);
                break;
        }
        move(moverow, boxcol);
-       printw("|                          |");
+       printw("|                                  |");
        move(msgrow, boxcol);
        move(msgrow, boxcol);
-       printw("|                          |");
+       printw("|                                  |");
        switch (status) {
        case BETTINGBOX:
                printbottombettingbox();
        switch (status) {
        case BETTINGBOX:
                printbottombettingbox();
@@ -203,31 +235,31 @@ movebox()
 printtopinstructions()
 {
            move(tboxrow, boxcol);
 printtopinstructions()
 {
            move(tboxrow, boxcol);
-           printw("*--------------------------*");
+           printw("*----------------------------------*");
            move(tboxrow + 1, boxcol);
            move(tboxrow + 1, boxcol);
-           printw("|         MOVES            |");
+           printw("|         MOVES                    |");
            move(tboxrow + 2, boxcol);
            move(tboxrow + 2, boxcol);
-           printw("|s# = stock to tableau     |");
+           printw("|s# = stock to tableau             |");
            move(tboxrow + 3, boxcol);
            move(tboxrow + 3, boxcol);
-           printw("|sf = stock to foundation  |");
+           printw("|sf = stock to foundation          |");
            move(tboxrow + 4, boxcol);
            move(tboxrow + 4, boxcol);
-           printw("|t# = talon to tableau     |");
+           printw("|t# = talon to tableau             |");
            move(tboxrow + 5, boxcol);
            move(tboxrow + 5, boxcol);
-           printw("|tf = talon to foundation  |");
+           printw("|tf = talon to foundation          |");
            move(tboxrow + 6, boxcol);
            move(tboxrow + 6, boxcol);
-           printw("|## = tableau to tableau   |");
+           printw("|## = tableau to tableau           |");
            move(tboxrow + 7, boxcol);
            move(tboxrow + 7, boxcol);
-           printw("|#f = tableau to foundation|");
+           printw("|#f = tableau to foundation        |");
            move(tboxrow + 8, boxcol);
            move(tboxrow + 8, boxcol);
-           printw("|ht = hand to talon        |");
+           printw("|ht = hand to talon                |");
            move(tboxrow + 9, boxcol);
            move(tboxrow + 9, boxcol);
-           printw("|c = toggle card counting  |");
+           printw("|c = toggle card counting          |");
            move(tboxrow + 10, boxcol);
            move(tboxrow + 10, boxcol);
-           printw("|b = present betting info  |");
+           printw("|b = present betting information   |");
            move(tboxrow + 11, boxcol);
            move(tboxrow + 11, boxcol);
-           printw("|q = quit to end the game  |");
+           printw("|q = quit to end the game          |");
            move(tboxrow + 12, boxcol);
            move(tboxrow + 12, boxcol);
-           printw("|==========================|");
+           printw("|==================================|");
 }
 
 /*
 }
 
 /*
@@ -237,31 +269,31 @@ printtopbettingbox()
 {
 
            move(tboxrow, boxcol);
 {
 
            move(tboxrow, boxcol);
-           printw("                            ");
+           printw("*----------------------------------*");
            move(tboxrow + 1, boxcol);
            move(tboxrow + 1, boxcol);
-           printw("*--------------------------*");
+           printw("|Costs        Hand   Game    Total |");
            move(tboxrow + 2, boxcol);
            move(tboxrow + 2, boxcol);
-           printw("|Costs        Hand   Total |");
+           printw("| Hands                            |");
            move(tboxrow + 3, boxcol);
            move(tboxrow + 3, boxcol);
-           printw("| Hands                    |");
+           printw("| Inspections                      |");
            move(tboxrow + 4, boxcol);
            move(tboxrow + 4, boxcol);
-           printw("| Inspections              |");
+           printw("| Games                            |");
            move(tboxrow + 5, boxcol);
            move(tboxrow + 5, boxcol);
-           printw("| Games                    |");
+           printw("| Runs                             |");
            move(tboxrow + 6, boxcol);
            move(tboxrow + 6, boxcol);
-           printw("| Runs                     |");
+           printw("| Information                      |");
            move(tboxrow + 7, boxcol);
            move(tboxrow + 7, boxcol);
-           printw("| Information              |");
+           printw("| Think time                       |");
            move(tboxrow + 8, boxcol);
            move(tboxrow + 8, boxcol);
-           printw("| Think time               |");
+           printw("|Total Costs                       |");
            move(tboxrow + 9, boxcol);
            move(tboxrow + 9, boxcol);
-           printw("|Total Costs               |");
+           printw("|Winnings                          |");
            move(tboxrow + 10, boxcol);
            move(tboxrow + 10, boxcol);
-           printw("|Winnings                  |");
+           printw("|Net Worth                         |");
            move(tboxrow + 11, boxcol);
            move(tboxrow + 11, boxcol);
-           printw("|Net Worth                 |");
+           printw("|Return                            |");
            move(tboxrow + 12, boxcol);
            move(tboxrow + 12, boxcol);
-           printw("|==========================|");
+           printw("|==================================|");
 }
 
 /*
 }
 
 /*
@@ -273,10 +305,10 @@ clearabovemovebox()
 
        for (i = 0; i <= 11; i++) {
                move(tboxrow + i, boxcol);
 
        for (i = 0; i <= 11; i++) {
                move(tboxrow + i, boxcol);
-               printw("                            ");
+               printw("                                    ");
        }
        move(tboxrow + 12, boxcol);
        }
        move(tboxrow + 12, boxcol);
-       printw("*--------------------------*");
+       printw("*----------------------------------*");
 }
 
 /*
 }
 
 /*
@@ -285,11 +317,11 @@ clearabovemovebox()
 printbottominstructions()
 {
            move(bboxrow, boxcol);
 printbottominstructions()
 {
            move(bboxrow, boxcol);
-           printw("|Replace # with the number |");
+           printw("|Replace # with the number of the  |");
            move(bboxrow + 1, boxcol);
            move(bboxrow + 1, boxcol);
-           printw("|of the tableau you want.  |");
+           printw("|tableau you want.                 |");
            move(bboxrow + 2, boxcol);
            move(bboxrow + 2, boxcol);
-           printw("*--------------------------*");
+           printw("*----------------------------------*");
 }
 
 /*
 }
 
 /*
@@ -298,11 +330,11 @@ printbottominstructions()
 printbottombettingbox()
 {
            move(bboxrow, boxcol);
 printbottombettingbox()
 {
            move(bboxrow, boxcol);
-           printw("|x = toggle information box|");
+           printw("|x = toggle information box        |");
            move(bboxrow + 1, boxcol);
            move(bboxrow + 1, boxcol);
-           printw("|i = list instructions     |");
+           printw("|i = list playing instructions     |");
            move(bboxrow + 2, boxcol);
            move(bboxrow + 2, boxcol);
-           printw("*--------------------------*");
+           printw("*----------------------------------*");
 }
 
 /*
 }
 
 /*
@@ -313,10 +345,10 @@ clearbelowmovebox()
        int i;
 
        move(bboxrow, boxcol);
        int i;
 
        move(bboxrow, boxcol);
-       printw("*--------------------------*");
+       printw("*----------------------------------*");
        for (i = 1; i <= 2; i++) {
                move(bboxrow + i, boxcol);
        for (i = 1; i <= 2; i++) {
                move(bboxrow + i, boxcol);
-               printw("                            ");
+               printw("                                    ");
        }
 }
 
        }
 }
 
@@ -581,6 +613,7 @@ fndbase(cp, column, row)
                                cardsoff++;
                                if (infullgame) {
                                        this.wins += valuepercardup;
                                cardsoff++;
                                if (infullgame) {
                                        this.wins += valuepercardup;
+                                       game.wins += valuepercardup;
                                        total.wins += valuepercardup;
                                }
                        } else 
                                        total.wins += valuepercardup;
                                }
                        } else 
@@ -643,6 +676,7 @@ startgame()
        shuffle(deck);
        initgame();
        this.hand = costofhand;
        shuffle(deck);
        initgame();
        this.hand = costofhand;
+       game.hand += costofhand;
        total.hand += costofhand;
        this.inspection = 0;
        this.game = 0;
        total.hand += costofhand;
        this.inspection = 0;
        this.game = 0;
@@ -765,7 +799,9 @@ tabok(cp, des)
        if ((cp == stock) && (tableau[des] == NIL))
                return (TRUE);
        else if (tableau[des] == NIL)
        if ((cp == stock) && (tableau[des] == NIL))
                return (TRUE);
        else if (tableau[des] == NIL)
-               if (stock == NIL)
+               if (stock == NIL && 
+                   cp != bottom[0] && cp != bottom[1] && 
+                   cp != bottom[2] && cp != bottom[3])
                        return (TRUE);
                else 
                        return (FALSE);
                        return (TRUE);
                else 
                        return (FALSE);
@@ -782,6 +818,10 @@ movetotalon()
 {
        int i, fin;
 
 {
        int i, fin;
 
+       if (cinhand <= 3 && cinhand > 0) {
+               move(msgrow, msgcol);
+               printw("Hand is now empty        ");
+       }
        if (cinhand >= 3)
                fin = 3;
        else if (cinhand > 0)
        if (cinhand >= 3)
                fin = 3;
        else if (cinhand > 0)
@@ -793,6 +833,7 @@ movetotalon()
                if (timesthru != 4) {
                        printw("Talon is now the new hand");
                        this.runs += costofrunthroughhand;
                if (timesthru != 4) {
                        printw("Talon is now the new hand");
                        this.runs += costofrunthroughhand;
+                       game.runs += costofrunthroughhand;
                        total.runs += costofrunthroughhand;
                        while (talon != NIL) {
                                transit(&talon, &hand);
                        total.runs += costofrunthroughhand;
                        while (talon != NIL) {
                                transit(&talon, &hand);
@@ -832,6 +873,7 @@ movetotalon()
                if (Cflag) {
                        if (talon->paid == FALSE && talon->visible == TRUE) {
                                this.information += costofinformation;
                if (Cflag) {
                        if (talon->paid == FALSE && talon->visible == TRUE) {
                                this.information += costofinformation;
+                               game.information += costofinformation;
                                total.information += costofinformation;
                                talon->paid = TRUE;
                        }
                                total.information += costofinformation;
                                talon->paid = TRUE;
                        }
@@ -875,6 +917,7 @@ showstat()
                if (ptr->paid == FALSE && ptr->visible == TRUE) {
                        ptr->paid = TRUE;
                        this.information += costofinformation;
                if (ptr->paid == FALSE && ptr->visible == TRUE) {
                        ptr->paid = TRUE;
                        this.information += costofinformation;
+                       game.information += costofinformation;
                        total.information += costofinformation;
                }
                printcard(col, row, ptr);
                        total.information += costofinformation;
                }
                printcard(col, row, ptr);
@@ -886,6 +929,7 @@ showstat()
                if (ptr->paid == FALSE && ptr->visible == TRUE) {
                        ptr->paid = TRUE;
                        this.information += costofinformation;
                if (ptr->paid == FALSE && ptr->visible == TRUE) {
                        ptr->paid = TRUE;
                        this.information += costofinformation;
+                       game.information += costofinformation;
                        total.information += costofinformation;
                }
                INCRHAND(row, col);
                        total.information += costofinformation;
                }
                INCRHAND(row, col);
@@ -923,6 +967,7 @@ usedtalon()
                talon->visible = TRUE;
                if (Cflag) {
                        this.information += costofinformation;
                talon->visible = TRUE;
                if (Cflag) {
                        this.information += costofinformation;
+                       game.information += costofinformation;
                        total.information += costofinformation;
                        talon->paid = TRUE;
                        printcard(coldcol, coldrow, talon);
                        total.information += costofinformation;
                        talon->paid = TRUE;
                        printcard(coldcol, coldrow, talon);
@@ -990,7 +1035,8 @@ showcards()
        printw("          ");
        move(row, stockcol - 1);
        printw("=---=");
        printw("          ");
        move(row, stockcol - 1);
        printw("=---=");
-       getcmd(moverow, movecol, "Hit return to exit");
+       if ( cardsoff == 52 )
+               getcmd(moverow, movecol, "Hit return to exit");
 }
 
 /*
 }
 
 /*
@@ -998,7 +1044,8 @@ showcards()
  */
 updatebettinginfo()
 {
  */
 updatebettinginfo()
 {
-       long thiscosts, totalcosts;
+       long thiscosts, gamecosts, totalcosts;
+       double thisreturn, gamereturn, totalreturn;
        time_t now;
        register long dollars;
 
        time_t now;
        register long dollars;
 
@@ -1009,34 +1056,44 @@ updatebettinginfo()
                if (dollars > maxtimecharge)
                        dollars = maxtimecharge;
                this.thinktime += dollars;
                if (dollars > maxtimecharge)
                        dollars = maxtimecharge;
                this.thinktime += dollars;
+               game.thinktime += dollars;
                total.thinktime += dollars;
        }
        thiscosts = this.hand + this.inspection + this.game +
                this.runs + this.information + this.thinktime;
                total.thinktime += dollars;
        }
        thiscosts = this.hand + this.inspection + this.game +
                this.runs + this.information + this.thinktime;
+       gamecosts = game.hand + game.inspection + game.game +
+               game.runs + game.information + game.thinktime;
        totalcosts = total.hand + total.inspection + total.game +
                total.runs + total.information + total.thinktime;
        this.worth = this.wins - thiscosts;
        totalcosts = total.hand + total.inspection + total.game +
                total.runs + total.information + total.thinktime;
        this.worth = this.wins - thiscosts;
+       game.worth = game.wins - gamecosts;
        total.worth = total.wins - totalcosts;
        total.worth = total.wins - totalcosts;
+       thisreturn = ((double)this.wins / (double)thiscosts - 1.0) * 100.0;
+       gamereturn = ((double)game.wins / (double)gamecosts - 1.0) * 100.0;
+       totalreturn = ((double)total.wins / (double)totalcosts - 1.0) * 100.0;
        if (status != BETTINGBOX)
                return;
        if (status != BETTINGBOX)
                return;
+       move(tboxrow + 2, boxcol + 13);
+       printw("%4d%8d%9d", this.hand, game.hand, total.hand);
        move(tboxrow + 3, boxcol + 13);
        move(tboxrow + 3, boxcol + 13);
-       printw("%4d%9d", this.hand, total.hand);
+       printw("%4d%8d%9d", this.inspection, game.inspection, total.inspection);
        move(tboxrow + 4, boxcol + 13);
        move(tboxrow + 4, boxcol + 13);
-       printw("%4d%9d", this.inspection, total.inspection);
+       printw("%4d%8d%9d", this.game, game.game, total.game);
        move(tboxrow + 5, boxcol + 13);
        move(tboxrow + 5, boxcol + 13);
-       printw("%4d%9d", this.game, total.game);
+       printw("%4d%8d%9d", this.runs, game.runs, total.runs);
        move(tboxrow + 6, boxcol + 13);
        move(tboxrow + 6, boxcol + 13);
-       printw("%4d%9d", this.runs, total.runs);
+       printw("%4d%8d%9d", this.information, game.information,
+               total.information);
        move(tboxrow + 7, boxcol + 13);
        move(tboxrow + 7, boxcol + 13);
-       printw("%4d%9d", this.information, total.information);
+       printw("%4d%8d%9d", this.thinktime, game.thinktime, total.thinktime);
        move(tboxrow + 8, boxcol + 13);
        move(tboxrow + 8, boxcol + 13);
-       printw("%4d%9d", this.thinktime, total.thinktime);
+       printw("%4d%8d%9d", thiscosts, gamecosts, totalcosts);
        move(tboxrow + 9, boxcol + 13);
        move(tboxrow + 9, boxcol + 13);
-       printw("%4d%9d", thiscosts, totalcosts);
+       printw("%4d%8d%9d", this.wins, game.wins, total.wins);
        move(tboxrow + 10, boxcol + 13);
        move(tboxrow + 10, boxcol + 13);
-       printw("%4d%9d", this.wins, total.wins);
+       printw("%4d%8d%9d", this.worth, game.worth, total.worth);
        move(tboxrow + 11, boxcol + 13);
        move(tboxrow + 11, boxcol + 13);
-       printw("%4d%9d", this.worth, total.worth);
+       printw("%4.0f%%%7.1f%%%8.1f%%", thisreturn, gamereturn, totalreturn);
 }
 
 /*
 }
 
 /*
@@ -1188,6 +1245,7 @@ movetofound(cp, source)
                                        cardsoff++;
                                        if (infullgame) {
                                                this.wins += valuepercardup;
                                        cardsoff++;
                                        if (infullgame) {
                                                this.wins += valuepercardup;
+                                               game.wins += valuepercardup;
                                                total.wins += valuepercardup;
                                        }
                                        mtfdone = TRUE;
                                                total.wins += valuepercardup;
                                        }
                                        mtfdone = TRUE;
@@ -1224,14 +1282,14 @@ getcmd(row, col, cp)
                if (ch == '\f') {
                        wrefresh(curscr);
                        refresh();
                if (ch == '\f') {
                        wrefresh(curscr);
                        refresh();
-               } else if (i >= 2 && ch != _tty.sg_erase && ch != _tty.sg_kill) {
+               } else if (i >= 2 && ch != erasechar() && ch != killchar()) {
                        if (ch != '\n' && ch != '\r' && ch != ' ')
                                write(1, "\007", 1);
                        if (ch != '\n' && ch != '\r' && ch != ' ')
                                write(1, "\007", 1);
-               } else if (ch == _tty.sg_erase && i > 0) {
+               } else if (ch == erasechar() && i > 0) {
                        printw("\b \b");
                        refresh();
                        i--;
                        printw("\b \b");
                        refresh();
                        i--;
-               } else if (ch == _tty.sg_kill && i > 0) {
+               } else if (ch == killchar() && i > 0) {
                        while (i > 0) {
                                printw("\b \b");
                                i--;
                        while (i > 0) {
                                printw("\b \b");
                                i--;
@@ -1260,16 +1318,14 @@ suspend()
        char *sh;
 #endif
 
        char *sh;
 #endif
 
+       updatebettinginfo();
        move(21, 0);
        refresh();
        move(21, 0);
        refresh();
-#ifdef SIGTSTP
+       if (dbfd != -1) {
+               lseek(dbfd, uid * sizeof(struct betinfo), 0);
+               write(dbfd, (char *)&total, sizeof(total));
+       }
        kill(getpid(), SIGTSTP);
        kill(getpid(), SIGTSTP);
-#else
-       sh = getenv("SHELL");
-       if (sh == NULL)
-               sh = "/bin/sh";
-       system(sh);
-#endif
        raw();
        noecho();
 }
        raw();
        noecho();
 }
@@ -1290,6 +1346,24 @@ movecard()
                if (cardsoff == 52) {
                        refresh();
                        srcpile = 'q';
                if (cardsoff == 52) {
                        refresh();
                        srcpile = 'q';
+               } else if (!startedgame) {
+                       move(msgrow, msgcol);
+                       errmsg = TRUE;
+                       switch (34 - taloncnt - cinhand) {
+                       default:
+                               errmsg = FALSE;
+                               break;
+                       case 1:
+                               printw("One card used from talon  ");
+                               break;
+                       case 2:
+                               printw("Two cards used from talon ");
+                               break;
+                       case 3:
+                               printw(">3< cards used from talon ");
+                               break;
+                       }
+                       getcmd(moverow, movecol, "Move:");
                } else
                        getcmd(moverow, movecol, "Move:");
                clearmsg();
                } else
                        getcmd(moverow, movecol, "Move:");
                clearmsg();
@@ -1313,6 +1387,7 @@ movecard()
                                srcpile = 'q';
                        } else {
                                this.inspection += costofinspection;
                                srcpile = 'q';
                        } else {
                                this.inspection += costofinspection;
+                               game.inspection += costofinspection;
                                total.inspection += costofinspection;
                                srcpile = osrcpile;
                                destpile = odestpile;
                                total.inspection += costofinspection;
                                srcpile = osrcpile;
                                destpile = odestpile;
@@ -1357,8 +1432,10 @@ movecard()
                                }
                                infullgame = TRUE;
                                this.wins += valuepercardup * cardsoff;
                                }
                                infullgame = TRUE;
                                this.wins += valuepercardup * cardsoff;
+                               game.wins += valuepercardup * cardsoff;
                                total.wins += valuepercardup * cardsoff;
                                this.game += costofgame;
                                total.wins += valuepercardup * cardsoff;
                                this.game += costofgame;
+                               game.game += costofgame;
                                total.game += costofgame;
                                movetotalon();
                                break;
                                total.game += costofgame;
                                movetotalon();
                                break;
@@ -1488,15 +1565,15 @@ instruct()
  */
 initall()
 {
  */
 initall()
 {
-       int uid, i;
+       int i;
 
        srandom(getpid());
        time(&acctstart);
        initdeck(deck);
        uid = getuid();
        if (uid < 0)
 
        srandom(getpid());
        time(&acctstart);
        initdeck(deck);
        uid = getuid();
        if (uid < 0)
-               return;
-       dbfd = open("/usr/games/lib/cfscores", 2);
+               uid = 0;
+       dbfd = open(_PATH_SCORE, 2);
        if (dbfd < 0)
                return;
        i = lseek(dbfd, uid * sizeof(struct betinfo), 0);
        if (dbfd < 0)
                return;
        i = lseek(dbfd, uid * sizeof(struct betinfo), 0);
@@ -1511,7 +1588,6 @@ initall()
                dbfd = -1;
                return;
        }
                dbfd = -1;
                return;
        }
-       lseek(dbfd, uid * sizeof(struct betinfo), 0);
 }
 
 /*
 }
 
 /*
@@ -1529,8 +1605,6 @@ finish()
                move(originrow, origincol);
                printw("CONGRATULATIONS!\n");
                printw("You won the game. That is a feat to be proud of.\n");
                move(originrow, origincol);
                printw("CONGRATULATIONS!\n");
                printw("You won the game. That is a feat to be proud of.\n");
-               move(originrow + 4, origincol);
-               printw("Wish to play again?     ");
                row = originrow + 5;
                col = origincol;
        } else {
                row = originrow + 5;
                col = origincol;
        } else {
@@ -1539,14 +1613,12 @@ finish()
                if (cardsoff > 1)
                        printw("s");
                printw(" off    ");
                if (cardsoff > 1)
                        printw("s");
                printw(" off    ");
-               getcmd(moverow, movecol, "Hit return to continue");
                move(msgrow, msgcol);
                move(msgrow, msgcol);
-               printw("Wish to play again?     ");
                row = moverow;
                col = movecol;
        }
        do {
                row = moverow;
                col = movecol;
        }
        do {
-               getcmd(row, col, "y or n?");
+               getcmd(row, col, "Play again (y or n)?");
        } while (srcpile != 'y' && srcpile != 'n');
        errmsg = TRUE;
        clearmsg();
        } while (srcpile != 'y' && srcpile != 'n');
        errmsg = TRUE;
        clearmsg();
@@ -1556,25 +1628,10 @@ finish()
                return (TRUE);
 }
 
                return (TRUE);
 }
 
-/*
- * Field an interrupt.
- */
-askquit()
-{
-       move(msgrow, msgcol);
-       printw("Really wish to quit?    ");
-       do {
-               getcmd(moverow, movecol, "y or n?");
-       } while (srcpile != 'y' && srcpile != 'n');
-       clearmsg();
-       if (srcpile == 'y')
-               cleanup();
-       signal(SIGINT, askquit);
-}
-
 /*
  * procedure to clean up and exit
  */
 /*
  * procedure to clean up and exit
  */
+void
 cleanup()
 {
 
 cleanup()
 {
 
@@ -1582,6 +1639,7 @@ cleanup()
        status = NOBOX;
        updatebettinginfo();
        if (dbfd != -1) {
        status = NOBOX;
        updatebettinginfo();
        if (dbfd != -1) {
+               lseek(dbfd, uid * sizeof(struct betinfo), 0);
                write(dbfd, (char *)&total, sizeof(total));
                close(dbfd);
        }
                write(dbfd, (char *)&total, sizeof(total));
                close(dbfd);
        }
@@ -1593,6 +1651,23 @@ cleanup()
        /* NOTREACHED */
 }
 
        /* NOTREACHED */
 }
 
+/*
+ * Field an interrupt.
+ */
+void
+askquit()
+{
+       move(msgrow, msgcol);
+       printw("Really wish to quit?    ");
+       do {
+               getcmd(moverow, movecol, "y or n?");
+       } while (srcpile != 'y' && srcpile != 'n');
+       clearmsg();
+       if (srcpile == 'y')
+               cleanup();
+       signal(SIGINT, askquit);
+}
+
 /*
  * Can you tell that this used to be a Pascal program?
  */
 /*
  * Can you tell that this used to be a Pascal program?
  */