Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / games / backgammon / common_source / check.c
1 /*
2  * Copyright (c) 1980, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by the University of
16  *      California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * @(#)check.c  8.1 (Berkeley) 5/31/93
34  * $FreeBSD: src/games/backgammon/common_source/check.c,v 1.4 1999/11/30 03:48:25 billf Exp $
35  * $DragonFly: src/games/backgammon/common_source/check.c,v 1.2 2003/06/17 04:25:22 dillon Exp $
36  */
37
38 #include "back.h"
39
40 getmove ()  {
41         int     i, c;
42
43         c = 0;
44         for (;;)  {
45                 i = checkmove(c);
46
47                 switch (i)  {
48                 case -1:
49                         if (movokay(mvlim))  {
50                                 if (tflag)
51                                         curmove (20,0);
52                                 else
53                                         writec ('\n');
54                                 for (i = 0; i < mvlim; i++)
55                                         if (h[i])
56                                                 wrhit(g[i]);
57                                 nexturn();
58                                 if (*offopp == 15)
59                                         cturn *= -2;
60                                 if (tflag && pnum)
61                                         bflag = pnum;
62                                 return;
63                         }
64
65                 case -4:
66                 case 0:
67                         if (tflag)
68                                 refresh();
69                         if (i != 0 && i != -4)
70                                 break;
71                         if (tflag)
72                                 curmove (20,0);
73                         else
74                                 writec ('\n');
75                         writel (*Colorptr);
76                         if (i == -4)
77                                 writel (" must make ");
78                         else
79                                 writel (" can only make ");
80                         writec (mvlim+'0');
81                         writel (" move");
82                         if (mvlim > 1)
83                                 writec ('s');
84                         writec ('.');
85                         writec ('\n');
86                         break;
87
88                 case -3:
89                         if (quit())
90                                 return;
91                 }
92
93                 if (! tflag)
94                         proll ();
95                 else  {
96                         curmove (cturn == -1? 18: 19,39);
97                         cline ();
98                         c = -1;
99                 }
100         }
101 }
102 \f
103 movokay (mv)
104 int     mv;
105
106 {
107         int     i, m;
108
109         if (d0)
110                 swap;
111
112         for (i = 0; i < mv; i++)  {
113
114                 if (p[i] == g[i])  {
115                         moverr (i);
116                         curmove (20,0);
117                         writel ("Attempt to move to same location.\n");
118                         return (0);
119                 }
120
121                 if (cturn*(g[i]-p[i]) < 0)  {
122                         moverr (i);
123                         curmove (20,0);
124                         writel ("Backwards move.\n");
125                         return (0);
126                 }
127
128                 if (abs(board[bar]) && p[i] != bar)  {
129                         moverr (i);
130                         curmove (20,0);
131                         writel ("Men still on bar.\n");
132                         return (0);
133                 }
134
135                 if ( (m = makmove(i)) )  {
136                         moverr (i);
137                         switch (m)  {
138
139                         case 1:
140                                 writel ("Move not rolled.\n");
141                                 break;
142
143                         case 2:
144                                 writel ("Bad starting position.\n");
145                                 break;
146
147                         case 3:
148                                 writel ("Destination occupied.\n");
149                                 break;
150
151                         case 4:
152                                 writel ("Can't remove men yet.\n");
153                         }
154                         return (0);
155                 }
156         }
157         return (1);
158 }