allow.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* $NetBSD: allow.c,v 1.5 2003/08/07 09:36:56 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[] = "@(#)allow.c 8.1 (Berkeley) 5/31/93";
  34. #else
  35. __RCSID("$NetBSD: allow.c,v 1.5 2003/08/07 09:36:56 agc Exp $");
  36. #endif
  37. #endif /* not lint */
  38. #include "back.h"
  39. int
  40. movallow()
  41. {
  42. int i, m, iold;
  43. int r;
  44. if (d0)
  45. swap;
  46. m = (D0 == D1 ? 4 : 2);
  47. for (i = 0; i < 4; i++)
  48. p[i] = bar;
  49. i = iold = 0;
  50. while (i < m) {
  51. if (*offptr == 15)
  52. break;
  53. h[i] = 0;
  54. if (board[bar]) {
  55. if (i == 1 || m == 4)
  56. g[i] = bar + cturn * D1;
  57. else
  58. g[i] = bar + cturn * D0;
  59. if ((r = makmove(i)) != 0) {
  60. if (d0 || m == 4)
  61. break;
  62. swap;
  63. movback(i);
  64. if (i > iold)
  65. iold = i;
  66. for (i = 0; i < 4; i++)
  67. p[i] = bar;
  68. i = 0;
  69. } else
  70. i++;
  71. continue;
  72. }
  73. if ((p[i] += cturn) == home) {
  74. if (i > iold)
  75. iold = i;
  76. if (m == 2 && i) {
  77. movback(i);
  78. p[i--] = bar;
  79. if (p[i] != bar)
  80. continue;
  81. else
  82. break;
  83. }
  84. if (d0 || m == 4)
  85. break;
  86. swap;
  87. movback(i);
  88. for (i = 0; i < 4; i++)
  89. p[i] = bar;
  90. i = 0;
  91. continue;
  92. }
  93. if (i == 1 || m == 4)
  94. g[i] = p[i] + cturn * D1;
  95. else
  96. g[i] = p[i] + cturn * D0;
  97. if (g[i] * cturn > home) {
  98. if (*offptr >= 0)
  99. g[i] = home;
  100. else
  101. continue;
  102. }
  103. if (board[p[i]] * cturn > 0 && (r = makmove(i)) == 0)
  104. i++;
  105. }
  106. movback(i);
  107. return (iold > i ? iold : i);
  108. }