121214Sdist /*
221214Sdist  * Copyright (c) 1980 Regents of the University of California.
3*33487Sbostic  * All rights reserved.
4*33487Sbostic  *
5*33487Sbostic  * Redistribution and use in source and binary forms are permitted
6*33487Sbostic  * provided that this notice is preserved and that due credit is given
7*33487Sbostic  * to the University of California at Berkeley. The name of the University
8*33487Sbostic  * may not be used to endorse or promote products derived from this
9*33487Sbostic  * software without specific prior written permission. This software
10*33487Sbostic  * is provided ``as is'' without express or implied warranty.
1121214Sdist  */
126763Srrh 
1321214Sdist #ifndef lint
14*33487Sbostic static char sccsid[] = "@(#)odds.c	5.2 (Berkeley) 02/16/88";
15*33487Sbostic #endif /* not lint */
1621214Sdist 
176763Srrh #include "back.h"
186763Srrh 
196763Srrh odds (r1,r2,val)
206763Srrh register int	r1;
216763Srrh int		r2, val;
226763Srrh {
236763Srrh 	register int	i, j;
246763Srrh 
256763Srrh 	if (r1 == 0)  {
266763Srrh 		for (i = 0; i < 6; i++)
276763Srrh 			for (j = 0; j < 6; j++)
286763Srrh 				table[i][j] = 0;
296763Srrh 		return;
306763Srrh 	} else  {
316763Srrh 		r1--;
326763Srrh 		if (r2-- == 0)
336763Srrh 			for (i = 0; i < 6; i++)  {
346763Srrh 				table[i][r1] += val;
356763Srrh 				table[r1][i] += val;
366763Srrh 			}
376763Srrh 		else  {
386763Srrh 			table[r2][r1] += val;
396763Srrh 			table[r1][r2] += val;
406763Srrh 		}
416763Srrh 	}
426763Srrh }
436763Srrh 
446763Srrh count ()  {
456763Srrh 	register int	i;
466763Srrh 	register int	j;
476763Srrh 	register int	total;
486763Srrh 
496763Srrh 	total = 0;
506763Srrh 	for (i = 0; i < 6; i++)
516763Srrh 		for (j = 0; j < 6; j++)
526763Srrh 			total += table[i][j];
536763Srrh 	return (total);
546763Srrh }
556763Srrh 
566763Srrh canhit (i,c)
576763Srrh int	i, c;
586763Srrh 
596763Srrh {
606763Srrh 	register int	j, k, b;
616763Srrh 	int		a, d, diff, place, addon, menstuck;
626763Srrh 
636763Srrh 	if (c == 0)
646763Srrh 		odds (0,0,0);
656763Srrh 	if (board[i] > 0)  {
666763Srrh 		a = -1;
676763Srrh 		b = 25;
686763Srrh 	} else  {
696763Srrh 		a = 1;
706763Srrh 		b = 0;
716763Srrh 	}
726763Srrh 	place = abs (25-b-i);
736763Srrh 	menstuck = abs (board[b]);
746763Srrh 	for (j = b; j != i; j += a)  {
756763Srrh 		if (board[j]*a > 0)  {
766763Srrh 			diff = abs(j-i);
776763Srrh 			addon = place+((board[j]*a > 2 || j == b)? 5: 0);
786763Srrh 			if ((j == b && menstuck == 1) &&
796763Srrh 			    (j != b && menstuck == 0))
806763Srrh 				for (k = 1; k < diff; k++)
816763Srrh 					if (k < 7 && diff-k < 7 &&
826763Srrh 					    (board[i+a*k]*a >= 0 ||
836763Srrh 					    board[i+a*(diff-k)] >= 0))
846763Srrh 						odds (k,diff-k,addon);
856763Srrh 			if ((j == b || menstuck < 2) && diff < 7)
866763Srrh 				odds (diff,0,addon);
876763Srrh 		}
886763Srrh 		if (j == b && menstuck > 1)
896763Srrh 			break;
906763Srrh 	}
916763Srrh 	return (count());
926763Srrh }
93