tutor.c revision 1.6 1 /* $NetBSD: tutor.c,v 1.6 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[] = "@(#)tutor.c 8.1 (Berkeley) 5/31/93";
36 #else
37 __RCSID("$NetBSD: tutor.c,v 1.6 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 static const char better[] = "That is a legal move, but there is a better one.\n";
45
46 void
47 tutor()
48 {
49 int i, j;
50
51 i = 0;
52 begscr = 18;
53 cturn = -1;
54 home = 0;
55 bar = 25;
56 inptr = &in[0];
57 inopp = &in[1];
58 offptr = &off[0];
59 offopp = &off[1];
60 Colorptr = &color[0];
61 colorptr = &color[2];
62 colen = 5;
63 wrboard();
64
65 while (1) {
66 if (!brdeq(test[i].brd, board)) {
67 if (tflag && curr == 23)
68 curmove(18, 0);
69 writel(better);
70 nexturn();
71 movback(mvlim);
72 if (tflag) {
73 refresh();
74 clrest();
75 }
76 if ((!tflag) || curr == 19) {
77 proll();
78 writec('\t');
79 } else
80 curmove(curr > 19 ? curr - 2 : curr + 4, 25);
81 getmove();
82 if (cturn == 0)
83 leave();
84 continue;
85 }
86 if (tflag)
87 curmove(18, 0);
88 text(*test[i].com);
89 if (!tflag)
90 writec('\n');
91 if (i == maxmoves)
92 break;
93 D0 = test[i].roll1;
94 D1 = test[i].roll2;
95 d0 = 0;
96 mvlim = 0;
97 for (j = 0; j < 4; j++) {
98 if (test[i].mp[j] == test[i].mg[j])
99 break;
100 p[j] = test[i].mp[j];
101 g[j] = test[i].mg[j];
102 mvlim++;
103 }
104 if (mvlim)
105 for (j = 0; j < mvlim; j++)
106 if (makmove(j))
107 writel("AARGH!!!\n");
108 if (tflag)
109 refresh();
110 nexturn();
111 D0 = test[i].new1;
112 D1 = test[i].new2;
113 d0 = 0;
114 i++;
115 mvlim = movallow();
116 if (mvlim) {
117 if (tflag)
118 clrest();
119 proll();
120 writec('\t');
121 getmove();
122 if (tflag)
123 refresh();
124 if (cturn == 0)
125 leave();
126 }
127 }
128 leave();
129 }
130
131 void
132 clrest()
133 {
134 int r, c, j;
135
136 r = curr;
137 c = curc;
138 for (j = r + 1; j < 24; j++) {
139 curmove(j, 0);
140 cline();
141 }
142 curmove(r, c);
143 }
144
145 int
146 brdeq(b1, b2)
147 const int *b1, *b2;
148 {
149 const int *e;
150
151 e = b1 + 26;
152 while (b1 < e)
153 if (*b1++ != *b2++)
154 return (0);
155 return (1);
156 }
157