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[] = "@(#)allow.c	5.2 (Berkeley) 02/16/88";
15 #endif /* not lint */
16 
17 #include "back.h"
18 
19 movallow ()  {
20 
21 	register int	i, m, iold;
22 	int		r;
23 
24 	if (d0)
25 		swap;
26 	m = (D0 == D1? 4: 2);
27 	for (i = 0; i < 4; i++)
28 		p[i] = bar;
29 	i = iold = 0;
30 	while (i < m)  {
31 		if (*offptr == 15)
32 			break;
33 		h[i] = 0;
34 		if (board[bar])  {
35 			if (i == 1 || m == 4)
36 				g[i] = bar+cturn*D1;
37 			else
38 				g[i] = bar+cturn*D0;
39 			if (r = makmove(i))  {
40 				if (d0 || m == 4)
41 					break;
42 				swap;
43 				movback (i);
44 				if (i > iold)
45 					iold = i;
46 				for (i = 0; i < 4; i++)
47 					p[i] = bar;
48 				i = 0;
49 			} else
50 				i++;
51 			continue;
52 		}
53 		if ((p[i] += cturn) == home)  {
54 			if (i > iold)
55 				iold = i;
56 			if (m == 2 && i)  {
57 				movback(i);
58 				p[i--] = bar;
59 				if (p[i] != bar)
60 					continue;
61 				else
62 					break;
63 			}
64 			if (d0 || m == 4)
65 				break;
66 			swap;
67 			movback (i);
68 			for (i = 0; i < 4; i++)
69 				p[i] = bar;
70 			i = 0;
71 			continue;
72 		}
73 		if (i == 1 || m == 4)
74 			g[i] = p[i]+cturn*D1;
75 		else
76 			g[i] = p[i]+cturn*D0;
77 		if (g[i]*cturn > home)  {
78 			if (*offptr >= 0)
79 				g[i] = home;
80 			else
81 				continue;
82 		}
83 		if (board[p[i]]*cturn > 0 && (r = makmove(i)) == 0)
84 			i++;
85 	}
86 	movback (i);
87 	return (iold > i? iold: i);
88 }
89