check.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /* $NetBSD: check.c,v 1.5 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[] = "@(#)check.c 8.1 (Berkeley) 5/31/93";
  34. #else
  35. __RCSID("$NetBSD: check.c,v 1.5 2003/08/07 09:36:57 agc Exp $");
  36. #endif
  37. #endif /* not lint */
  38. #include "back.h"
  39. void
  40. getmove()
  41. {
  42. int i, c;
  43. c = 0;
  44. for (;;) {
  45. i = checkmove(c);
  46. switch (i) {
  47. case -1:
  48. if (movokay(mvlim)) {
  49. if (tflag)
  50. curmove(20, 0);
  51. else
  52. writec('\n');
  53. for (i = 0; i < mvlim; i++)
  54. if (h[i])
  55. wrhit(g[i]);
  56. nexturn();
  57. if (*offopp == 15)
  58. cturn *= -2;
  59. if (tflag && pnum)
  60. bflag = pnum;
  61. return;
  62. }
  63. case -4:
  64. case 0:
  65. if (tflag)
  66. refresh();
  67. if (i != 0 && i != -4)
  68. break;
  69. if (tflag)
  70. curmove(20, 0);
  71. else
  72. writec('\n');
  73. writel(*Colorptr);
  74. if (i == -4)
  75. writel(" must make ");
  76. else
  77. writel(" can only make ");
  78. writec(mvlim + '0');
  79. writel(" move");
  80. if (mvlim > 1)
  81. writec('s');
  82. writec('.');
  83. writec('\n');
  84. break;
  85. case -3:
  86. if (quit())
  87. return;
  88. }
  89. if (!tflag)
  90. proll();
  91. else {
  92. curmove(cturn == -1 ? 18 : 19, 39);
  93. cline();
  94. c = -1;
  95. }
  96. }
  97. }
  98. int
  99. movokay(mv)
  100. int mv;
  101. {
  102. int i, m;
  103. if (d0)
  104. swap;
  105. for (i = 0; i < mv; i++) {
  106. if (p[i] == g[i]) {
  107. moverr(i);
  108. curmove(20, 0);
  109. writel("Attempt to move to same location.\n");
  110. return (0);
  111. }
  112. if (cturn * (g[i] - p[i]) < 0) {
  113. moverr(i);
  114. curmove(20, 0);
  115. writel("Backwards move.\n");
  116. return (0);
  117. }
  118. if (abs(board[bar]) && p[i] != bar) {
  119. moverr(i);
  120. curmove(20, 0);
  121. writel("Men still on bar.\n");
  122. return (0);
  123. }
  124. if ((m = makmove(i))) {
  125. moverr(i);
  126. switch (m) {
  127. case 1:
  128. writel("Move not rolled.\n");
  129. break;
  130. case 2:
  131. writel("Bad starting position.\n");
  132. break;
  133. case 3:
  134. writel("Destination occupied.\n");
  135. break;
  136. case 4:
  137. writel("Can't remove men yet.\n");
  138. }
  139. return (0);
  140. }
  141. }
  142. return (1);
  143. }