]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - gomoku/bdisp.c
fix NetBSD RCS ID headers
[bsdgames-darwin.git] / gomoku / bdisp.c
1 /* $NetBSD: bdisp.c,v 1.4 1997/01/03 01:35:25 cgd Exp $ */
2
3 /*
4 * Copyright (c) 1994
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Ralph Campbell.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 */
38
39 #ifndef lint
40 #if 0
41 static char sccsid[] = "@(#)bdisp.c 8.2 (Berkeley) 5/3/95";
42 #else
43 static char rcsid[] = "$NetBSD: bdisp.c,v 1.4 1997/01/03 01:35:25 cgd Exp $";
44 #endif
45 #endif /* not lint */
46
47 #include "gomoku.h"
48 #include <stdio.h>
49 #include <string.h>
50 #include <curses.h>
51
52 #define SCRNH 24 /* assume 24 lines for the moment */
53 #define SCRNW 80 /* assume 80 chars for the moment */
54
55 static int lastline;
56 static char pcolor[] = "*O.?";
57
58 /*
59 * Initialize screen display.
60 */
61 cursinit()
62 {
63
64 initscr();
65 noecho();
66 cbreak();
67 leaveok(stdscr, TRUE);
68 }
69
70 /*
71 * Restore screen display.
72 */
73 cursfini()
74 {
75
76 leaveok(stdscr, FALSE);
77 move(23, 0);
78 clrtoeol();
79 refresh();
80 endwin();
81 }
82
83 /*
84 * Initialize board display.
85 */
86 bdisp_init()
87 {
88 register int i, j;
89
90 /* top border */
91 for (i = 1; i < BSZ1; i++) {
92 move(0, 2 * i + 1);
93 addch(letters[i]);
94 }
95 /* left and right edges */
96 for (j = BSZ1; --j > 0; ) {
97 move(20 - j, 0);
98 printw("%2d ", j);
99 move(20 - j, 2 * BSZ1 + 1);
100 printw("%d ", j);
101 }
102 /* bottom border */
103 for (i = 1; i < BSZ1; i++) {
104 move(20, 2 * i + 1);
105 addch(letters[i]);
106 }
107 bdwho(0);
108 move(0, 47);
109 addstr("# black white");
110 lastline = 0;
111 bdisp();
112 }
113
114 /*
115 * Update who is playing whom.
116 */
117 bdwho(update)
118 int update;
119 {
120 int i;
121 extern char *plyr[];
122
123 move(21, 0);
124 clrtoeol();
125 i = 6 - strlen(plyr[BLACK]) / 2;
126 move(21, i > 0 ? i : 0);
127 printw("BLACK/%s", plyr[BLACK]);
128 i = 30 - strlen(plyr[WHITE]) / 2;
129 move(21, i);
130 printw("WHITE/%s", plyr[WHITE]);
131 move(21, 19);
132 addstr(" vs. ");
133 if (update)
134 refresh();
135 }
136
137 /*
138 * Update the board display after a move.
139 */
140 bdisp()
141 {
142 register int i, j, c;
143 register struct spotstr *sp;
144
145 for (j = BSZ1; --j > 0; ) {
146 for (i = 1; i < BSZ1; i++) {
147 move(BSZ1 - j, 2 * i + 1);
148 sp = &board[i + j * BSZ1];
149 if (debug > 1 && sp->s_occ == EMPTY) {
150 if (sp->s_flg & IFLAGALL)
151 c = '+';
152 else if (sp->s_flg & CFLAGALL)
153 c = '-';
154 else
155 c = '.';
156 } else
157 c = pcolor[sp->s_occ];
158 addch(c);
159 }
160 }
161 refresh();
162 }
163
164 #ifdef DEBUG
165 /*
166 * Dump board display to a file.
167 */
168 bdump(fp)
169 FILE *fp;
170 {
171 register int i, j, c;
172 register struct spotstr *sp;
173
174 /* top border */
175 fprintf(fp, " A B C D E F G H J K L M N O P Q R S T\n");
176
177 for (j = BSZ1; --j > 0; ) {
178 /* left edge */
179 fprintf(fp, "%2d ", j);
180 for (i = 1; i < BSZ1; i++) {
181 sp = &board[i + j * BSZ1];
182 if (debug > 1 && sp->s_occ == EMPTY) {
183 if (sp->s_flg & IFLAGALL)
184 c = '+';
185 else if (sp->s_flg & CFLAGALL)
186 c = '-';
187 else
188 c = '.';
189 } else
190 c = pcolor[sp->s_occ];
191 putc(c, fp);
192 putc(' ', fp);
193 }
194 /* right edge */
195 fprintf(fp, "%d\n", j);
196 }
197
198 /* bottom border */
199 fprintf(fp, " A B C D E F G H J K L M N O P Q R S T\n");
200 }
201 #endif /* DEBUG */
202
203 /*
204 * Display a transcript entry
205 */
206 dislog(str)
207 char *str;
208 {
209
210 if (++lastline >= SCRNH - 1) {
211 /* move 'em up */
212 lastline = 1;
213 }
214 if (strlen(str) >= SCRNW - 46)
215 str[SCRNW - 46 - 1] = '\0';
216 move(lastline, 46);
217 addstr(str);
218 clrtoeol();
219 move(lastline + 1, 46);
220 clrtoeol();
221 }
222
223 /*
224 * Display a question.
225 */
226 ask(str)
227 char *str;
228 {
229 int len = strlen(str);
230
231 move(23, 0);
232 addstr(str);
233 clrtoeol();
234 move(23, len);
235 refresh();
236 }
237
238 getline(buf, size)
239 char *buf;
240 int size;
241 {
242 register char *cp, *end;
243 register int c;
244 extern int interactive;
245
246 cp = buf;
247 end = buf + size - 1; /* save room for the '\0' */
248 while (cp < end && (c = getchar()) != EOF && c != '\n' && c != '\r') {
249 *cp++ = c;
250 if (interactive) {
251 switch (c) {
252 case 0x0c: /* ^L */
253 wrefresh(curscr);
254 cp--;
255 continue;
256 case 0x15: /* ^U */
257 case 0x18: /* ^X */
258 while (cp > buf) {
259 cp--;
260 addch('\b');
261 }
262 clrtoeol();
263 break;
264 case '\b':
265 case 0x7f: /* DEL */
266 if (cp == buf + 1) {
267 cp--;
268 continue;
269 }
270 cp -= 2;
271 addch('\b');
272 c = ' ';
273 /* FALLTHROUGH */
274 default:
275 addch(c);
276 }
277 refresh();
278 }
279 }
280 *cp = '\0';
281 return(c != EOF);
282 }