1*6763Srrh static char sccsid[] = "	odds.c	1.1	82/05/11	";
2*6763Srrh 
3*6763Srrh #include "back.h"
4*6763Srrh 
5*6763Srrh odds (r1,r2,val)
6*6763Srrh register int	r1;
7*6763Srrh int		r2, val;
8*6763Srrh {
9*6763Srrh 	register int	i, j;
10*6763Srrh 
11*6763Srrh 	if (r1 == 0)  {
12*6763Srrh 		for (i = 0; i < 6; i++)
13*6763Srrh 			for (j = 0; j < 6; j++)
14*6763Srrh 				table[i][j] = 0;
15*6763Srrh 		return;
16*6763Srrh 	} else  {
17*6763Srrh 		r1--;
18*6763Srrh 		if (r2-- == 0)
19*6763Srrh 			for (i = 0; i < 6; i++)  {
20*6763Srrh 				table[i][r1] += val;
21*6763Srrh 				table[r1][i] += val;
22*6763Srrh 			}
23*6763Srrh 		else  {
24*6763Srrh 			table[r2][r1] += val;
25*6763Srrh 			table[r1][r2] += val;
26*6763Srrh 		}
27*6763Srrh 	}
28*6763Srrh }
29*6763Srrh 
30*6763Srrh count ()  {
31*6763Srrh 	register int	i;
32*6763Srrh 	register int	j;
33*6763Srrh 	register int	total;
34*6763Srrh 
35*6763Srrh 	total = 0;
36*6763Srrh 	for (i = 0; i < 6; i++)
37*6763Srrh 		for (j = 0; j < 6; j++)
38*6763Srrh 			total += table[i][j];
39*6763Srrh 	return (total);
40*6763Srrh }
41*6763Srrh 
42*6763Srrh canhit (i,c)
43*6763Srrh int	i, c;
44*6763Srrh 
45*6763Srrh {
46*6763Srrh 	register int	j, k, b;
47*6763Srrh 	int		a, d, diff, place, addon, menstuck;
48*6763Srrh 
49*6763Srrh 	if (c == 0)
50*6763Srrh 		odds (0,0,0);
51*6763Srrh 	if (board[i] > 0)  {
52*6763Srrh 		a = -1;
53*6763Srrh 		b = 25;
54*6763Srrh 	} else  {
55*6763Srrh 		a = 1;
56*6763Srrh 		b = 0;
57*6763Srrh 	}
58*6763Srrh 	place = abs (25-b-i);
59*6763Srrh 	menstuck = abs (board[b]);
60*6763Srrh 	for (j = b; j != i; j += a)  {
61*6763Srrh 		if (board[j]*a > 0)  {
62*6763Srrh 			diff = abs(j-i);
63*6763Srrh 			addon = place+((board[j]*a > 2 || j == b)? 5: 0);
64*6763Srrh 			if ((j == b && menstuck == 1) &&
65*6763Srrh 			    (j != b && menstuck == 0))
66*6763Srrh 				for (k = 1; k < diff; k++)
67*6763Srrh 					if (k < 7 && diff-k < 7 &&
68*6763Srrh 					    (board[i+a*k]*a >= 0 ||
69*6763Srrh 					    board[i+a*(diff-k)] >= 0))
70*6763Srrh 						odds (k,diff-k,addon);
71*6763Srrh 			if ((j == b || menstuck < 2) && diff < 7)
72*6763Srrh 				odds (diff,0,addon);
73*6763Srrh 		}
74*6763Srrh 		if (j == b && menstuck > 1)
75*6763Srrh 			break;
76*6763Srrh 	}
77*6763Srrh 	return (count());
78*6763Srrh }
79