1 /* $OpenBSD: board.c,v 1.5 2001/06/23 23:50:03 pjanzen 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. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by the University of 18 * California, Berkeley and its contributors. 19 * 4. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 */ 35 36 #ifndef lint 37 #if 0 38 static char sccsid[] = "@(#)board.c 8.1 (Berkeley) 5/31/93"; 39 #else 40 static char rcsid[] = "$OpenBSD: board.c,v 1.5 2001/06/23 23:50:03 pjanzen Exp $"; 41 #endif 42 #endif /* not lint */ 43 44 #include "back.h" 45 46 static int i, j, k; 47 static char ln[60]; 48 49 void 50 wrboard() 51 { 52 int l; 53 static const char bl[] = 54 "| | | |\n"; 55 static const char sv[] = 56 "| | | | \n"; 57 58 clear(); 59 60 fboard(); 61 goto lastline; 62 addstr("_____________________________________________________\n"); 63 addstr(bl); 64 strcpy(ln, bl); 65 for (j = 1; j < 50; j += 4) { 66 k = j / 4 + (j > 24 ? 12 : 13); 67 ln[j + 1] = k % 10 + '0'; 68 ln[j] = k / 10 + '0'; 69 if (j == 21) 70 j += 4; 71 } 72 addstr(ln); 73 for (i = 0; i < 5; i++) { 74 strcpy(ln, sv); 75 for (j = 1; j < 50; j += 4) { 76 k = j / 4 + (j > 24 ? 12 : 13); 77 wrbsub(); 78 if (j == 21) 79 j += 4; 80 } 81 if (-board[25] > i) 82 ln[26] = 'w'; 83 if (-board[25] > i + 5) 84 ln[25] = 'w'; 85 if (-board[25] > i + 10) 86 ln[27] = 'w'; 87 l = 53; 88 if (off[1] > i || (off[1] < 0 && off[1] + 15 > i)) { 89 ln[54] = 'r'; 90 l = 55; 91 } 92 if (off[1] > i + 5 || (off[1] < 0 && off[1] + 15 > i + 5)) { 93 ln[55] = 'r'; 94 l = 56; 95 } 96 if (off[1] > i + 10 || (off[1] < 0 && off[1] + 15 > i + 10)) { 97 ln[56] = 'r'; 98 l = 57; 99 } 100 ln[l++] = '\n'; 101 ln[l] = '\0'; 102 addstr(ln); 103 } 104 strcpy(ln, bl); 105 ln[25] = 'B'; 106 ln[26] = 'A'; 107 ln[27] = 'R'; 108 addstr(ln); 109 strcpy(ln, sv); 110 for (i = 4; i > -1; i--) { 111 for (j = 1; j < 50; j += 4) { 112 k = ((j > 24 ? 53 : 49) - j) / 4; 113 wrbsub(); 114 if (j == 21) 115 j += 4; 116 } 117 if (board[0] > i) 118 ln[26] = 'r'; 119 if (board[0] > i + 5) 120 ln[25] = 'r'; 121 if (board[0] > i + 10) 122 ln[27] = 'r'; 123 l = 53; 124 if (off[0] > i || (off[0] < 0 && off[0] + 15 > i)) { 125 ln[54] = 'w'; 126 l = 55; 127 } 128 if (off[0] > i + 5 || (off[0] < 0 && off[0] + 15 > i + 5)) { 129 ln[55] = 'w'; 130 l = 56; 131 } 132 if (off[0] > i + 10 || (off[0] < 0 && off[0] + 15 > i + 10)) { 133 ln[56] = 'w'; 134 l = 57; 135 } 136 ln[l++] = '\n'; 137 ln[l] = '\0'; 138 addstr(ln); 139 } 140 strcpy(ln, bl); 141 for (j = 1; j < 50; j += 4) { 142 k = ((j > 24 ? 53 : 49) - j) / 4; 143 ln[j + 1] = k % 10 + '0'; 144 if (k > 9) 145 ln[j] = k / 10 + '0'; 146 if (j == 21) 147 j += 4; 148 } 149 addstr(ln); 150 addstr("|_______________________|___|_______________________|\n"); 151 152 lastline: 153 gwrite(); 154 move(18, 0); 155 } 156 157 void 158 wrbsub() 159 { 160 int m; 161 char d; 162 163 if (board[k] > 0) { 164 m = board[k]; 165 d = 'r'; 166 } else { 167 m = -board[k]; 168 d = 'w'; 169 } 170 if (m > i) 171 ln[j + 1] = d; 172 if (m > i + 5) 173 ln[j] = d; 174 if (m > i + 10) 175 ln[j + 2] = d; 176 } 177