121205Sdist /*
221205Sdist  * 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.
1121205Sdist  */
126751Srrh 
1321205Sdist #ifndef lint
14*33487Sbostic static char sccsid[] = "@(#)allow.c	5.2 (Berkeley) 02/16/88";
15*33487Sbostic #endif /* not lint */
1621205Sdist 
176751Srrh #include "back.h"
186751Srrh 
196751Srrh movallow ()  {
206751Srrh 
216751Srrh 	register int	i, m, iold;
226751Srrh 	int		r;
236751Srrh 
246751Srrh 	if (d0)
256751Srrh 		swap;
266751Srrh 	m = (D0 == D1? 4: 2);
276751Srrh 	for (i = 0; i < 4; i++)
286751Srrh 		p[i] = bar;
296751Srrh 	i = iold = 0;
306751Srrh 	while (i < m)  {
316751Srrh 		if (*offptr == 15)
326751Srrh 			break;
336751Srrh 		h[i] = 0;
346751Srrh 		if (board[bar])  {
356751Srrh 			if (i == 1 || m == 4)
366751Srrh 				g[i] = bar+cturn*D1;
376751Srrh 			else
386751Srrh 				g[i] = bar+cturn*D0;
396751Srrh 			if (r = makmove(i))  {
406751Srrh 				if (d0 || m == 4)
416751Srrh 					break;
426751Srrh 				swap;
436751Srrh 				movback (i);
446751Srrh 				if (i > iold)
456751Srrh 					iold = i;
466751Srrh 				for (i = 0; i < 4; i++)
476751Srrh 					p[i] = bar;
486751Srrh 				i = 0;
496751Srrh 			} else
506751Srrh 				i++;
516751Srrh 			continue;
526751Srrh 		}
536751Srrh 		if ((p[i] += cturn) == home)  {
546751Srrh 			if (i > iold)
556751Srrh 				iold = i;
566751Srrh 			if (m == 2 && i)  {
576751Srrh 				movback(i);
586751Srrh 				p[i--] = bar;
596751Srrh 				if (p[i] != bar)
606751Srrh 					continue;
616751Srrh 				else
626751Srrh 					break;
636751Srrh 			}
646751Srrh 			if (d0 || m == 4)
656751Srrh 				break;
666751Srrh 			swap;
676751Srrh 			movback (i);
686751Srrh 			for (i = 0; i < 4; i++)
696751Srrh 				p[i] = bar;
706751Srrh 			i = 0;
716751Srrh 			continue;
726751Srrh 		}
736751Srrh 		if (i == 1 || m == 4)
746751Srrh 			g[i] = p[i]+cturn*D1;
756751Srrh 		else
766751Srrh 			g[i] = p[i]+cturn*D0;
776751Srrh 		if (g[i]*cturn > home)  {
786751Srrh 			if (*offptr >= 0)
796751Srrh 				g[i] = home;
806751Srrh 			else
816751Srrh 				continue;
826751Srrh 		}
836751Srrh 		if (board[p[i]]*cturn > 0 && (r = makmove(i)) == 0)
846751Srrh 			i++;
856751Srrh 	}
866751Srrh 	movback (i);
876751Srrh 	return (iold > i? iold: i);
886751Srrh }
89