board.c 4.3 KB

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