1*21205Sdist /*
2*21205Sdist  * Copyright (c) 1980 Regents of the University of California.
3*21205Sdist  * All rights reserved.  The Berkeley software License Agreement
4*21205Sdist  * specifies the terms and conditions for redistribution.
5*21205Sdist  */
66751Srrh 
7*21205Sdist #ifndef lint
8*21205Sdist static char sccsid[] = "@(#)allow.c	5.1 (Berkeley) 05/29/85";
9*21205Sdist #endif not lint
10*21205Sdist 
116751Srrh #include "back.h"
126751Srrh 
136751Srrh movallow ()  {
146751Srrh 
156751Srrh 	register int	i, m, iold;
166751Srrh 	int		r;
176751Srrh 
186751Srrh 	if (d0)
196751Srrh 		swap;
206751Srrh 	m = (D0 == D1? 4: 2);
216751Srrh 	for (i = 0; i < 4; i++)
226751Srrh 		p[i] = bar;
236751Srrh 	i = iold = 0;
246751Srrh 	while (i < m)  {
256751Srrh 		if (*offptr == 15)
266751Srrh 			break;
276751Srrh 		h[i] = 0;
286751Srrh 		if (board[bar])  {
296751Srrh 			if (i == 1 || m == 4)
306751Srrh 				g[i] = bar+cturn*D1;
316751Srrh 			else
326751Srrh 				g[i] = bar+cturn*D0;
336751Srrh 			if (r = makmove(i))  {
346751Srrh 				if (d0 || m == 4)
356751Srrh 					break;
366751Srrh 				swap;
376751Srrh 				movback (i);
386751Srrh 				if (i > iold)
396751Srrh 					iold = i;
406751Srrh 				for (i = 0; i < 4; i++)
416751Srrh 					p[i] = bar;
426751Srrh 				i = 0;
436751Srrh 			} else
446751Srrh 				i++;
456751Srrh 			continue;
466751Srrh 		}
476751Srrh 		if ((p[i] += cturn) == home)  {
486751Srrh 			if (i > iold)
496751Srrh 				iold = i;
506751Srrh 			if (m == 2 && i)  {
516751Srrh 				movback(i);
526751Srrh 				p[i--] = bar;
536751Srrh 				if (p[i] != bar)
546751Srrh 					continue;
556751Srrh 				else
566751Srrh 					break;
576751Srrh 			}
586751Srrh 			if (d0 || m == 4)
596751Srrh 				break;
606751Srrh 			swap;
616751Srrh 			movback (i);
626751Srrh 			for (i = 0; i < 4; i++)
636751Srrh 				p[i] = bar;
646751Srrh 			i = 0;
656751Srrh 			continue;
666751Srrh 		}
676751Srrh 		if (i == 1 || m == 4)
686751Srrh 			g[i] = p[i]+cturn*D1;
696751Srrh 		else
706751Srrh 			g[i] = p[i]+cturn*D0;
716751Srrh 		if (g[i]*cturn > home)  {
726751Srrh 			if (*offptr >= 0)
736751Srrh 				g[i] = home;
746751Srrh 			else
756751Srrh 				continue;
766751Srrh 		}
776751Srrh 		if (board[p[i]]*cturn > 0 && (r = makmove(i)) == 0)
786751Srrh 			i++;
796751Srrh 	}
806751Srrh 	movback (i);
816751Srrh 	return (iold > i? iold: i);
826751Srrh }
83