tutor.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* $NetBSD: tutor.c,v 1.6 2003/08/07 09:36:58 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[] = "@(#)tutor.c 8.1 (Berkeley) 5/31/93";
  34. #else
  35. __RCSID("$NetBSD: tutor.c,v 1.6 2003/08/07 09:36:58 agc Exp $");
  36. #endif
  37. #endif /* not lint */
  38. #include "back.h"
  39. #include "tutor.h"
  40. static const char better[] = "That is a legal move, but there is a better one.\n";
  41. void
  42. tutor()
  43. {
  44. int i, j;
  45. i = 0;
  46. begscr = 18;
  47. cturn = -1;
  48. home = 0;
  49. bar = 25;
  50. inptr = &in[0];
  51. inopp = &in[1];
  52. offptr = &off[0];
  53. offopp = &off[1];
  54. Colorptr = &color[0];
  55. colorptr = &color[2];
  56. colen = 5;
  57. wrboard();
  58. while (1) {
  59. if (!brdeq(test[i].brd, board)) {
  60. if (tflag && curr == 23)
  61. curmove(18, 0);
  62. writel(better);
  63. nexturn();
  64. movback(mvlim);
  65. if (tflag) {
  66. refresh();
  67. clrest();
  68. }
  69. if ((!tflag) || curr == 19) {
  70. proll();
  71. writec('\t');
  72. } else
  73. curmove(curr > 19 ? curr - 2 : curr + 4, 25);
  74. getmove();
  75. if (cturn == 0)
  76. leave();
  77. continue;
  78. }
  79. if (tflag)
  80. curmove(18, 0);
  81. text(*test[i].com);
  82. if (!tflag)
  83. writec('\n');
  84. if (i == maxmoves)
  85. break;
  86. D0 = test[i].roll1;
  87. D1 = test[i].roll2;
  88. d0 = 0;
  89. mvlim = 0;
  90. for (j = 0; j < 4; j++) {
  91. if (test[i].mp[j] == test[i].mg[j])
  92. break;
  93. p[j] = test[i].mp[j];
  94. g[j] = test[i].mg[j];
  95. mvlim++;
  96. }
  97. if (mvlim)
  98. for (j = 0; j < mvlim; j++)
  99. if (makmove(j))
  100. writel("AARGH!!!\n");
  101. if (tflag)
  102. refresh();
  103. nexturn();
  104. D0 = test[i].new1;
  105. D1 = test[i].new2;
  106. d0 = 0;
  107. i++;
  108. mvlim = movallow();
  109. if (mvlim) {
  110. if (tflag)
  111. clrest();
  112. proll();
  113. writec('\t');
  114. getmove();
  115. if (tflag)
  116. refresh();
  117. if (cturn == 0)
  118. leave();
  119. }
  120. }
  121. leave();
  122. }
  123. void
  124. clrest()
  125. {
  126. int r, c, j;
  127. r = curr;
  128. c = curc;
  129. for (j = r + 1; j < 24; j++) {
  130. curmove(j, 0);
  131. cline();
  132. }
  133. curmove(r, c);
  134. }
  135. int
  136. brdeq(b1, b2)
  137. const int *b1, *b2;
  138. {
  139. const int *e;
  140. e = b1 + 26;
  141. while (b1 < e)
  142. if (*b1++ != *b2++)
  143. return (0);
  144. return (1);
  145. }