odds.c revision 1.3 1 /* $NetBSD: odds.c,v 1.3 1995/03/21 15:05:47 cgd 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[] = "@(#)odds.c 8.1 (Berkeley) 5/31/93";
39 #else
40 static char rcsid[] = "$NetBSD: odds.c,v 1.3 1995/03/21 15:05:47 cgd Exp $";
41 #endif
42 #endif /* not lint */
43
44 #include "back.h"
45
46 odds (r1,r2,val)
47 register int r1;
48 int r2, val;
49 {
50 register int i, j;
51
52 if (r1 == 0) {
53 for (i = 0; i < 6; i++)
54 for (j = 0; j < 6; j++)
55 table[i][j] = 0;
56 return;
57 } else {
58 r1--;
59 if (r2-- == 0)
60 for (i = 0; i < 6; i++) {
61 table[i][r1] += val;
62 table[r1][i] += val;
63 }
64 else {
65 table[r2][r1] += val;
66 table[r1][r2] += val;
67 }
68 }
69 }
70
71 count () {
72 register int i;
73 register int j;
74 register int total;
75
76 total = 0;
77 for (i = 0; i < 6; i++)
78 for (j = 0; j < 6; j++)
79 total += table[i][j];
80 return (total);
81 }
82
83 canhit (i,c)
85 int i, c;
86
87 {
88 register int j, k, b;
89 int a, d, diff, place, addon, menstuck;
90
91 if (c == 0)
92 odds (0,0,0);
93 if (board[i] > 0) {
94 a = -1;
95 b = 25;
96 } else {
97 a = 1;
98 b = 0;
99 }
100 place = abs (25-b-i);
101 menstuck = abs (board[b]);
102 for (j = b; j != i; j += a) {
103 if (board[j]*a > 0) {
104 diff = abs(j-i);
105 addon = place+((board[j]*a > 2 || j == b)? 5: 0);
106 if ((j == b && menstuck == 1) &&
107 (j != b && menstuck == 0))
108 for (k = 1; k < diff; k++)
109 if (k < 7 && diff-k < 7 &&
110 (board[i+a*k]*a >= 0 ||
111 board[i+a*(diff-k)] >= 0))
112 odds (k,diff-k,addon);
113 if ((j == b || menstuck < 2) && diff < 7)
114 odds (diff,0,addon);
115 }
116 if (j == b && menstuck > 1)
117 break;
118 }
119 return (count());
120 }
121