Home | History | Annotate | Line # | Download | only in common_source
check.c revision 1.1
      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, 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 
     34 #ifndef lint
     35 static char sccsid[] = "@(#)check.c	5.4 (Berkeley) 6/1/90";
     36 #endif /* not lint */
     37 
     38 #include "back.h"
     39 
     40 getmove ()  {
     41 	register 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 
    103 movokay (mv)
    105 register int	mv;
    106 
    107 {
    108 	register int	i, m;
    109 
    110 	if (d0)
    111 		swap;
    112 
    113 	for (i = 0; i < mv; i++)  {
    114 
    115 		if (p[i] == g[i])  {
    116 			moverr (i);
    117 			curmove (20,0);
    118 			writel ("Attempt to move to same location.\n");
    119 			return (0);
    120 		}
    121 
    122 		if (cturn*(g[i]-p[i]) < 0)  {
    123 			moverr (i);
    124 			curmove (20,0);
    125 			writel ("Backwards move.\n");
    126 			return (0);
    127 		}
    128 
    129 		if (abs(board[bar]) && p[i] != bar)  {
    130 			moverr (i);
    131 			curmove (20,0);
    132 			writel ("Men still on bar.\n");
    133 			return (0);
    134 		}
    135 
    136 		if ( (m = makmove(i)) )  {
    137 			moverr (i);
    138 			switch (m)  {
    139 
    140 			case 1:
    141 				writel ("Move not rolled.\n");
    142 				break;
    143 
    144 			case 2:
    145 				writel ("Bad starting position.\n");
    146 				break;
    147 
    148 			case 3:
    149 				writel ("Destination occupied.\n");
    150 				break;
    151 
    152 			case 4:
    153 				writel ("Can't remove men yet.\n");
    154 			}
    155 			return (0);
    156 		}
    157 	}
    158 	return (1);
    159 }
    160