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 the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  */
17 
18 #ifndef lint
19 static char sccsid[] = "@(#)allow.c	5.3 (Berkeley) 06/18/88";
20 #endif /* not lint */
21 
22 #include "back.h"
23 
24 movallow ()  {
25 
26 	register int	i, m, iold;
27 	int		r;
28 
29 	if (d0)
30 		swap;
31 	m = (D0 == D1? 4: 2);
32 	for (i = 0; i < 4; i++)
33 		p[i] = bar;
34 	i = iold = 0;
35 	while (i < m)  {
36 		if (*offptr == 15)
37 			break;
38 		h[i] = 0;
39 		if (board[bar])  {
40 			if (i == 1 || m == 4)
41 				g[i] = bar+cturn*D1;
42 			else
43 				g[i] = bar+cturn*D0;
44 			if (r = makmove(i))  {
45 				if (d0 || m == 4)
46 					break;
47 				swap;
48 				movback (i);
49 				if (i > iold)
50 					iold = i;
51 				for (i = 0; i < 4; i++)
52 					p[i] = bar;
53 				i = 0;
54 			} else
55 				i++;
56 			continue;
57 		}
58 		if ((p[i] += cturn) == home)  {
59 			if (i > iold)
60 				iold = i;
61 			if (m == 2 && i)  {
62 				movback(i);
63 				p[i--] = bar;
64 				if (p[i] != bar)
65 					continue;
66 				else
67 					break;
68 			}
69 			if (d0 || m == 4)
70 				break;
71 			swap;
72 			movback (i);
73 			for (i = 0; i < 4; i++)
74 				p[i] = bar;
75 			i = 0;
76 			continue;
77 		}
78 		if (i == 1 || m == 4)
79 			g[i] = p[i]+cturn*D1;
80 		else
81 			g[i] = p[i]+cturn*D0;
82 		if (g[i]*cturn > home)  {
83 			if (*offptr >= 0)
84 				g[i] = home;
85 			else
86 				continue;
87 		}
88 		if (board[p[i]]*cturn > 0 && (r = makmove(i)) == 0)
89 			i++;
90 	}
91 	movback (i);
92 	return (iold > i? iold: i);
93 }
94