1 /*
2  * Copyright (c) 1980 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that this notice is preserved and that due credit is given
7  * to the University of California at Berkeley. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  */
12 
13 #ifndef lint
14 static char sccsid[] = "@(#)odds.c	5.2 (Berkeley) 02/16/88";
15 #endif /* not lint */
16 
17 #include "back.h"
18 
19 odds (r1,r2,val)
20 register int	r1;
21 int		r2, val;
22 {
23 	register int	i, j;
24 
25 	if (r1 == 0)  {
26 		for (i = 0; i < 6; i++)
27 			for (j = 0; j < 6; j++)
28 				table[i][j] = 0;
29 		return;
30 	} else  {
31 		r1--;
32 		if (r2-- == 0)
33 			for (i = 0; i < 6; i++)  {
34 				table[i][r1] += val;
35 				table[r1][i] += val;
36 			}
37 		else  {
38 			table[r2][r1] += val;
39 			table[r1][r2] += val;
40 		}
41 	}
42 }
43 
44 count ()  {
45 	register int	i;
46 	register int	j;
47 	register int	total;
48 
49 	total = 0;
50 	for (i = 0; i < 6; i++)
51 		for (j = 0; j < 6; j++)
52 			total += table[i][j];
53 	return (total);
54 }
55 
56 canhit (i,c)
57 int	i, c;
58 
59 {
60 	register int	j, k, b;
61 	int		a, d, diff, place, addon, menstuck;
62 
63 	if (c == 0)
64 		odds (0,0,0);
65 	if (board[i] > 0)  {
66 		a = -1;
67 		b = 25;
68 	} else  {
69 		a = 1;
70 		b = 0;
71 	}
72 	place = abs (25-b-i);
73 	menstuck = abs (board[b]);
74 	for (j = b; j != i; j += a)  {
75 		if (board[j]*a > 0)  {
76 			diff = abs(j-i);
77 			addon = place+((board[j]*a > 2 || j == b)? 5: 0);
78 			if ((j == b && menstuck == 1) &&
79 			    (j != b && menstuck == 0))
80 				for (k = 1; k < diff; k++)
81 					if (k < 7 && diff-k < 7 &&
82 					    (board[i+a*k]*a >= 0 ||
83 					    board[i+a*(diff-k)] >= 0))
84 						odds (k,diff-k,addon);
85 			if ((j == b || menstuck < 2) && diff < 7)
86 				odds (diff,0,addon);
87 		}
88 		if (j == b && menstuck > 1)
89 			break;
90 	}
91 	return (count());
92 }
93