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