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 34 #ifndef lint 35 #if 0 36 static char sccsid[] = "@(#)board.c 8.1 (Berkeley) 5/31/93"; 37 #endif 38 static const char rcsid[] = 39 "$FreeBSD: src/games/backgammon/common_source/board.c,v 1.6 1999/11/30 03:48:25 billf Exp $"; 40 #endif /* not lint */ 41 42 #include <string.h> 43 #include "back.h" 44 45 static int i, j, k; 46 static char ln[60]; 47 48 wrboard () { 49 int l; 50 static const char bl[] = 51 "| | | |\n"; 52 static const char sv[] = 53 "| | | | \n"; 54 55 fixtty (noech); 56 clear(); 57 58 if (tflag) { 59 fboard(); 60 goto lastline; 61 } 62 63 writel ("_____________________________________________________\n"); 64 writel (bl); 65 strcpy (ln,bl); 66 for (j = 1; j < 50; j += 4) { 67 k = j/4+(j > 24? 12: 13); 68 ln[j+1] = k%10+'0'; 69 ln[j] = k/10+'0'; 70 if (j == 21) 71 j += 4; 72 } 73 writel (ln); 74 for (i = 0; i < 5; i++) { 75 strcpy (ln,sv); 76 for (j = 1; j < 50; j += 4) { 77 k = j/4+(j > 24? 12: 13); 78 wrbsub (); 79 if (j == 21) 80 j += 4; 81 } 82 if (-board[25] > i) 83 ln[26] = 'w'; 84 if (-board[25] > i+5) 85 ln[25] = 'w'; 86 if (-board[25] > i+10) 87 ln[27] = 'w'; 88 l = 53; 89 if (off[1] > i || (off[1] < 0 && off[1]+15 > i)) { 90 ln[54] = 'r'; 91 l = 55; 92 } 93 if (off[1] > i+5 || (off[1] < 0 && off[1]+15 > i+5)) { 94 ln[55] = 'r'; 95 l = 56; 96 } 97 if (off[1] > i+10 || (off[1] < 0 && off[1]+15 > i+10)) { 98 ln[56] = 'r'; 99 l = 57; 100 } 101 ln[l++] = '\n'; 102 ln[l] = '\0'; 103 writel (ln); 104 } 105 strcpy (ln,bl); 106 ln[25] = 'B'; 107 ln[26] = 'A'; 108 ln[27] = 'R'; 109 writel (ln); 110 strcpy (ln,sv); 111 for (i = 4; i > -1; i--) { 112 for (j = 1; j < 50; j += 4) { 113 k = ((j > 24? 53: 49)-j)/4; 114 wrbsub(); 115 if (j == 21) 116 j += 4; 117 } 118 if (board[0] > i) 119 ln[26] = 'r'; 120 if (board[0] > i+5) 121 ln[25] = 'r'; 122 if (board[0] > i+10) 123 ln[27] = 'r'; 124 l = 53; 125 if (off[0] > i || (off[0] < 0 && off[0]+15 > i)) { 126 ln[54] = 'w'; 127 l = 55; 128 } 129 if (off[0] > i+5 || (off[0] < 0 && off[0]+15 > i+5)) { 130 ln[55] = 'w'; 131 l = 56; 132 } 133 if (off[0] > i+10 || (off[0] < 0 && off[0]+15 > i+10)) { 134 ln[56] = 'w'; 135 l = 57; 136 } 137 ln[l++] = '\n'; 138 ln[l] = '\0'; 139 writel (ln); 140 } 141 strcpy (ln,bl); 142 for (j = 1; j < 50; j += 4) { 143 k = ((j > 24? 53: 49)-j)/4; 144 ln[j+1] = k%10+'0'; 145 if (k > 9) 146 ln[j] = k/10+'0'; 147 if (j == 21) 148 j += 4; 149 } 150 writel (ln); 151 writel ("|_______________________|___|_______________________|\n"); 152 153 lastline: 154 gwrite (); 155 if (tflag) 156 curmove (18,0); 157 else { 158 writec ('\n'); 159 writec ('\n'); 160 } 161 fixtty(raw); 162 } 163 164 wrbsub () { 165 int m; 166 char d; 167 168 if (board[k] > 0) { 169 m = board[k]; 170 d = 'r'; 171 } else { 172 m = -board[k]; 173 d = 'w'; 174 } 175 if (m>i) 176 ln[j+1] = d; 177 if (m>i+5) 178 ln[j] = d; 179 if (m>i+10) 180 ln[j+2] = d; 181 } 182