2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
36 static char sccsid[] = "@(#)table.c 8.1 (Berkeley) 5/31/93";
38 static const char rcsid[] =
39 "$FreeBSD: src/games/backgammon/common_source/table.c,v 1.5 1999/11/30 03:48:28 billf Exp $";
44 const char *const help2[] = {
45 " Enter moves as <s>-<f> or <s>/<r> where <s> is the starting",
46 "position, <f> is the finishing position, and <r> is the roll.",
47 "Remember, each die roll must be moved separately.",
57 static const struct state atmata[] = {
59 'R', 1, 0, '?', 7, 0, 'Q', 0, -3, 'B', 8, 25,
60 '9', 2, 25, '8', 2, 25, '7', 2, 25, '6', 2, 25,
61 '5', 2, 25, '4', 2, 25, '3', 2, 25, '2', 2, 19,
62 '1', 2, 15, '0', 2, 25, '.', 0, 0, '9', 2, 25,
63 '8', 2, 25, '7', 2, 25, '6', 2, 25, '5', 2, 25,
65 '4', 2, 25, '3', 2, 25, '2', 2, 25, '1', 2, 25,
66 '0', 2, 25, '/', 0, 32, '-', 0, 39, '.', 0, 0,
67 '/', 5, 32, ' ', 6, 3, ',', 6, 3, '\n', 0, -1,
68 '6', 3, 28, '5', 3, 28, '4', 3, 28, '3', 3, 28,
69 '2', 3, 28, '1', 3, 28, '.', 0, 0, 'H', 9, 61,
71 '9', 4, 61, '8', 4, 61, '7', 4, 61, '6', 4, 61,
72 '5', 4, 61, '4', 4, 61, '3', 4, 61, '2', 4, 53,
73 '1', 4, 51, '0', 4, 61, '.', 0, 0, '9', 4, 61,
74 '8', 4, 61, '7', 4, 61, '6', 4, 61, '5', 4, 61,
75 '4', 4, 61, '3', 4, 61, '2', 4, 61, '1', 4, 61,
77 '0', 4, 61, ' ', 6, 3, ',', 6, 3, '-', 5, 39,
78 '\n', 0, -1, '.', 0, 0
99 for (j = 0; j < 5; j++)
109 curmove (cturn == -1? 18: 19,39);
119 if (c == tty.sg_erase && ncin > 0) {
121 curmove (curr,curc-1);
123 if (tty.sg_erase == '\010')
124 writel ("\010 \010");
126 writec (cin[ncin-1]);
140 if (c == tty.sg_kill && ncin > 0) {
146 } else if (tty.sg_erase == '\010') {
147 for (j = 0; j < ncin; j++)
148 writel ("\010 \010");
164 if ((! tflag) || c != '\n')
173 if (n == -1 && mvl >= mvlim)
175 if (n == -1 && mvl < mvlim-1)
180 if (movokay(mvl+1)) {
185 writel ("\t\tMove: ");
186 for (j = 0; j < ncin;)
189 if (movokay(mvl+1)) {
193 curmove (cturn == -1? 18:19,ncin+39);
215 while ( (a = atmata[i].ch) != '.') {
216 if (a == c || (test && a == '\n')) {
217 switch (atmata[i].fcode) {
222 curmove (cturn == -1? 18: 19,0);
233 p[mvl] = p[mvl]*10+c-'0';
242 g[mvl] = p[mvl]+cturn*(c-'0');
253 g[mvl] = g[mvl]*10+c-'0';
274 curmove (cturn == -1? 18: 19,39);
278 writel ("\t\tMove: ");
290 if (! test || a != '\n')
291 return (atmata[i].newst);
307 for (i = 0; i < 4; i++)
309 for (j = 0; j < ncin; j++)
310 n = dotable (cin[j],n);