]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - games/backgammon/common_source/board.c
This commit was generated by cvs2svn to compensate for changes in r53469,
[FreeBSD/FreeBSD.git] / games / backgammon / common_source / board.c
1 /*
2  * Copyright (c) 1980, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
20  *
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
31  * SUCH DAMAGE.
32  *
33  * $FreeBSD$
34  */
35
36 #ifndef lint
37 static char sccsid[] = "@(#)board.c     8.1 (Berkeley) 5/31/93";
38 #endif /* not lint */
39
40 #include <string.h>
41 #include "back.h"
42
43 static int      i, j, k;
44 static char     ln[60];
45
46 wrboard ()  {
47         int     l;
48         static const char       bl[] =
49                 "|                       |   |                       |\n";
50         static const char       sv[] =
51                 "|                       |   |                       |    \n";
52
53         fixtty (noech);
54         clear();
55
56         if (tflag)  {
57                 fboard();
58                 goto lastline;
59         }
60
61         writel ("_____________________________________________________\n");
62         writel (bl);
63         strcpy (ln,bl);
64         for (j = 1; j < 50; j += 4) {
65                 k = j/4+(j > 24? 12: 13);
66                 ln[j+1] = k%10+'0';
67                 ln[j] = k/10+'0';
68                 if (j == 21)
69                         j += 4;
70         }
71         writel (ln);
72         for (i = 0; i < 5; i++) {
73                 strcpy (ln,sv);
74                 for (j = 1; j < 50; j += 4) {
75                         k = j/4+(j > 24? 12: 13);
76                         wrbsub ();
77                         if (j == 21)
78                                 j += 4;
79                 }
80                 if (-board[25] > i)
81                         ln[26] = 'w';
82                 if (-board[25] > i+5)
83                         ln[25] = 'w';
84                 if (-board[25] > i+10)
85                         ln[27] = 'w';
86                 l = 53;
87                 if (off[1] > i || (off[1] < 0 && off[1]+15 > i))  {
88                         ln[54] = 'r';
89                         l = 55;
90                 }
91                 if (off[1] > i+5 || (off[1] < 0 && off[1]+15 > i+5))  {
92                         ln[55] = 'r';
93                         l = 56;
94                 }
95                 if (off[1] > i+10 || (off[1] < 0 && off[1]+15 > i+10))  {
96                         ln[56] = 'r';
97                         l = 57;
98                 }
99                 ln[l++] = '\n';
100                 ln[l] = '\0';
101                 writel (ln);
102         }
103         strcpy (ln,bl);
104         ln[25] = 'B';
105         ln[26] = 'A';
106         ln[27] = 'R';
107         writel (ln);
108         strcpy (ln,sv);
109         for (i = 4; i > -1; i--) {
110                 for (j = 1; j < 50; j += 4) {
111                         k = ((j > 24? 53: 49)-j)/4;
112                         wrbsub();
113                         if (j == 21)
114                                 j += 4;
115                 }
116                 if (board[0] > i)
117                         ln[26] = 'r';
118                 if (board[0] > i+5)
119                         ln[25] = 'r';
120                 if (board[0] > i+10)
121                         ln[27] = 'r';
122                 l = 53;
123                 if (off[0] > i || (off[0] < 0 && off[0]+15 > i))  {
124                         ln[54] = 'w';
125                         l = 55;
126                 }
127                 if (off[0] > i+5 || (off[0] < 0 && off[0]+15 > i+5))  {
128                         ln[55] = 'w';
129                         l = 56;
130                 }
131                 if (off[0] > i+10 || (off[0] < 0 && off[0]+15 > i+10))  {
132                         ln[56] = 'w';
133                         l = 57;
134                 }
135                 ln[l++] = '\n';
136                 ln[l] = '\0';
137                 writel (ln);
138         }
139         strcpy (ln,bl);
140         for (j = 1; j < 50; j += 4) {
141                 k = ((j > 24? 53: 49)-j)/4;
142                 ln[j+1] = k%10+'0';
143                 if (k > 9)
144                         ln[j] = k/10+'0';
145                 if (j == 21)
146                         j += 4;
147         }
148         writel (ln);
149         writel ("|_______________________|___|_______________________|\n");
150
151 lastline:
152         gwrite ();
153         if (tflag)
154                 curmove (18,0);
155         else  {
156                 writec ('\n');
157                 writec ('\n');
158         }
159         fixtty(raw);
160 }
161 \f
162 wrbsub () {
163         int             m;
164         char            d;
165
166         if (board[k] > 0)  {
167                 m = board[k];
168                 d = 'r';
169         } else {
170                 m = -board[k];
171                 d = 'w';
172         }
173         if (m>i)
174                 ln[j+1] = d;
175         if (m>i+5)
176                 ln[j] = d;
177         if (m>i+10)
178                 ln[j+2] = d;
179 }