121214Sdist /*
2*60746Sbostic  * Copyright (c) 1980, 1993
3*60746Sbostic  *	The Regents of the University of California.  All rights reserved.
433487Sbostic  *
542565Sbostic  * %sccs.include.redist.c%
621214Sdist  */
76763Srrh 
821214Sdist #ifndef lint
9*60746Sbostic static char sccsid[] = "@(#)odds.c	8.1 (Berkeley) 05/31/93";
1033487Sbostic #endif /* not lint */
1121214Sdist 
126763Srrh #include "back.h"
136763Srrh 
odds(r1,r2,val)146763Srrh odds (r1,r2,val)
156763Srrh register int	r1;
166763Srrh int		r2, val;
176763Srrh {
186763Srrh 	register int	i, j;
196763Srrh 
206763Srrh 	if (r1 == 0)  {
216763Srrh 		for (i = 0; i < 6; i++)
226763Srrh 			for (j = 0; j < 6; j++)
236763Srrh 				table[i][j] = 0;
246763Srrh 		return;
256763Srrh 	} else  {
266763Srrh 		r1--;
276763Srrh 		if (r2-- == 0)
286763Srrh 			for (i = 0; i < 6; i++)  {
296763Srrh 				table[i][r1] += val;
306763Srrh 				table[r1][i] += val;
316763Srrh 			}
326763Srrh 		else  {
336763Srrh 			table[r2][r1] += val;
346763Srrh 			table[r1][r2] += val;
356763Srrh 		}
366763Srrh 	}
376763Srrh }
386763Srrh 
count()396763Srrh count ()  {
406763Srrh 	register int	i;
416763Srrh 	register int	j;
426763Srrh 	register int	total;
436763Srrh 
446763Srrh 	total = 0;
456763Srrh 	for (i = 0; i < 6; i++)
466763Srrh 		for (j = 0; j < 6; j++)
476763Srrh 			total += table[i][j];
486763Srrh 	return (total);
496763Srrh }
506763Srrh 
canhit(i,c)516763Srrh canhit (i,c)
526763Srrh int	i, c;
536763Srrh 
546763Srrh {
556763Srrh 	register int	j, k, b;
566763Srrh 	int		a, d, diff, place, addon, menstuck;
576763Srrh 
586763Srrh 	if (c == 0)
596763Srrh 		odds (0,0,0);
606763Srrh 	if (board[i] > 0)  {
616763Srrh 		a = -1;
626763Srrh 		b = 25;
636763Srrh 	} else  {
646763Srrh 		a = 1;
656763Srrh 		b = 0;
666763Srrh 	}
676763Srrh 	place = abs (25-b-i);
686763Srrh 	menstuck = abs (board[b]);
696763Srrh 	for (j = b; j != i; j += a)  {
706763Srrh 		if (board[j]*a > 0)  {
716763Srrh 			diff = abs(j-i);
726763Srrh 			addon = place+((board[j]*a > 2 || j == b)? 5: 0);
736763Srrh 			if ((j == b && menstuck == 1) &&
746763Srrh 			    (j != b && menstuck == 0))
756763Srrh 				for (k = 1; k < diff; k++)
766763Srrh 					if (k < 7 && diff-k < 7 &&
776763Srrh 					    (board[i+a*k]*a >= 0 ||
786763Srrh 					    board[i+a*(diff-k)] >= 0))
796763Srrh 						odds (k,diff-k,addon);
806763Srrh 			if ((j == b || menstuck < 2) && diff < 7)
816763Srrh 				odds (diff,0,addon);
826763Srrh 		}
836763Srrh 		if (j == b && menstuck > 1)
846763Srrh 			break;
856763Srrh 	}
866763Srrh 	return (count());
876763Srrh }
88