Merge from vendor branch GROFF:
[dragonfly.git] / games / backgammon / teachgammon / ttext2.c
1 /*
2  * Copyright (c) 1980, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by the University of
16  *      California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * @(#)ttext2.c 8.1 (Berkeley) 5/31/93
34  * $FreeBSD: src/games/backgammon/teachgammon/ttext2.c,v 1.3.2.1 2001/10/15 13:46:32 dd Exp $
35  * $DragonFly: src/games/backgammon/teachgammon/ttext2.c,v 1.2 2003/06/17 04:25:22 dillon Exp $
36  */
37
38 #include "back.h"
39
40 extern const char *const list[];
41 char *prompt, *opts;
42
43 const char      *const doubl[] = {
44     "\nDoubling:",
45     "\n   If a player thinks he is in a good position, he may double the",
46     "value of the game.  However, his opponent may not accept the pro-",
47     "posal and forfeit the game before the price gets too high.  A",
48     "player must double before he rolls, and once his double has been",
49     "accepted, he cannot double again, until his opponent has doubled.",
50     "Thus, unless the game swings back and forth in advantage between",
51     "the two players a great deal, the value of the game should be",
52     "low.  At any rate, the value of the game will never go above 64,",
53     "or six doubles.  However, if a player wins a backgammon at 64",
54     "points, he wins 192 points!",
55     "",
56     0};
57
58 const char      *const stragy[] = {
59     "\nStrategy:",
60     "\n   Some general hints when playing:  Try not to leave men open",
61     "unless absolutely necessary.  Also, it is good to make as many",
62     "points as possible.  Often, two men from different positions can",
63     "be brought together to form a new point.  Although walls (six",
64     "points in a row) are difficult to form, many points nestled close-",
65     "ly together produce a formidable barrier.  Also, while it is good",
66     "to move back men forward, doing so lessens the opportunity for you",
67     "to hit men.  Finally, remember that once the two player's have",
68     "passed each other on the board, there is no chance of either team",
69     "being hit, so the game reduces to a race off the board.  Addi-",
70     "tional hints on strategy are presented in the practice game.",
71     "",
72     0};
73 \f
74 const char      *const prog[] = {
75    "\nThe Program and How It Works:",
76    "\n   A general rule of thumb is when you don't know what to do,",
77    "type a question mark, and you should get some help.  When it is",
78    "your turn, only your color will be printed out, with nothing",
79    "after it.  You may double by typing a 'd', but if you type a",
80    "space or newline, you will get your roll.  (Remember, you must",
81    "double before you roll.)  Also, typing a 'r' will reprint the",
82    "board, and a 'q' will quit the game.  The program will type",
83    "'Move:' when it wants your move, and you may indicate each die's",
84    "move with <s>-<f>, where <s> is the starting position and <f> is",
85    "the finishing position, or <s>/<r> where <r> is the roll made.",
86    "<s>-<f1>-<f2> is short for <s>-<f1>,<f1>-<f2> and <s>/<r1><r2> is",
87    "short for <s>/<r1>,<s>/<r2>.  Moves may be separated by a comma",
88    "or a space.",
89    "",
90    "\n   While typing, any input which does not make sense will not be",
91    "echoed, and a bell will sound instead.  Also, backspacing and",
92    "killing lines will echo differently than normal.  You may examine",
93    "the board by typing a 'r' if you have made a partial move, or be-",
94    "fore you type a newline, to see what the board looks like.  You",
95    "must end your move with a newline.  If you cannot double, your",
96    "roll will always be printed, and you will not be given the oppor-",
97    "tunity to double.  Home and bar are represented by the appropri-",
98    "ate number, 0 or 25 as the case may be, or by the letters 'h' or",
99    "'b' as appropriate.  You may also type 'r' or 'q' when the program",
100    "types 'Move:', which has the same effect as above.  Finally, you",
101    "will get to decide if you want to play red or white (or both if you",
102    "want to play a friend) at the beginning of the session, and you",
103    "will not get to change your mind later, since the computer keeps",
104    "score.",
105    "",
106    0};
107
108 const char      *const lastch[] = {
109    "\nTutorial (Practice Game):",
110    "\n   This tutorial, for simplicity's sake, will let you play one",
111    "predetermined game.  All the rolls have been pre-arranged, and",
112    "only one response will let you advance to the next move.",
113    "Although a given roll will may have several legal moves, the tu-",
114    "torial will only accept one (not including the same moves in a",
115    "different order), claiming that that move is 'best.'  Obviously,",
116    "a subjective statement.  At any rate, be patient with it and have",
117    "fun learning about backgammon.  Also, to speed things up a lit-",
118    "tle, doubling will not take place in the tutorial, so you will",
119    "never get that opportunity, and quitting only leaves the tutori-",
120    "al, not the game.  You will still be able to play backgammon",
121    "after quitting.",
122    "\n   This is your last chance to look over the rules before the tu-",
123    "torial starts.",
124    "",
125    0};
126 \f
127 int
128 text (txt)
129 const char      *const *txt;
130
131 {
132         const char      *const *begin;
133         const char      *a;
134         char    b;
135         const char      *c;
136         int     i;
137
138         fixtty (noech);
139         begin = txt;
140         while (*txt)  {
141                 a = *(txt++);
142                 if (*a != '\0')  {
143                         c = a;
144                         for (i = 0; *(c++) != '\0'; i--);
145                         writel (a);
146                         writec ('\n');
147                 } else  {
148                         fixtty (raw);
149                         writel (prompt);
150                         for (;;)  {
151                                 if ((b = readc()) == '?')  {
152                                         if (tflag)  {
153                                                 if (begscr)  {
154                                                         curmove (18,0);
155                                                         clend();
156                                                 } else
157                                                         clear();
158                                         } else
159                                                 writec ('\n');
160                                         text (list);
161                                         writel (prompt);
162                                         continue;
163                                 }
164                                 i = 0;
165                                 if (b == '\n')
166                                         break;
167                                 while (i < 11)  {
168                                         if (b == opts[i])
169                                                 break;
170                                         i++;
171                                 }
172                                 if (i == 11)
173                                         writec ('\007');
174                                 else
175                                         break;
176                         }
177                         if (tflag)  {
178                                 if (begscr)  {
179                                         curmove (18,0);
180                                         clend();
181                                 } else
182                                         clear();
183                         } else
184                                 writec ('\n');
185                         if (i)
186                                 return(i);
187                         fixtty (noech);
188                         if (tflag)
189                                 curmove (curr,0);
190                         begin = txt;
191                 }
192         }
193         fixtty (raw);
194         return (0);
195 }