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