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