Home | History | Annotate | Line # | Download | only in common_source
check.c revision 1.2
      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[] = "from: @(#)check.c	5.4 (Berkeley) 6/1/90";*/
     36 static char rcsid[] = "$Id: check.c,v 1.2 1993/08/01 18:56:44 mycroft Exp $";
     37 #endif /* not lint */
     38 
     39 #include "back.h"
     40 
     41 getmove ()  {
     42 	register int	i, c;
     43 
     44 	c = 0;
     45 	for (;;)  {
     46 		i = checkmove(c);
     47 
     48 		switch (i)  {
     49 		case -1:
     50 			if (movokay(mvlim))  {
     51 				if (tflag)
     52 					curmove (20,0);
     53 				else
     54 					writec ('\n');
     55 				for (i = 0; i < mvlim; i++)
     56 					if (h[i])
     57 						wrhit(g[i]);
     58 				nexturn();
     59 				if (*offopp == 15)
     60 					cturn *= -2;
     61 				if (tflag && pnum)
     62 					bflag = pnum;
     63 				return;
     64 			}
     65 
     66 		case -4:
     67 		case 0:
     68 			if (tflag)
     69 				refresh();
     70 			if (i != 0 && i != -4)
     71 				break;
     72 			if (tflag)
     73 				curmove (20,0);
     74 			else
     75 				writec ('\n');
     76 			writel (*Colorptr);
     77 			if (i == -4)
     78 				writel (" must make ");
     79 			else
     80 				writel (" can only make ");
     81 			writec (mvlim+'0');
     82 			writel (" move");
     83 			if (mvlim > 1)
     84 				writec ('s');
     85 			writec ('.');
     86 			writec ('\n');
     87 			break;
     88 
     89 		case -3:
     90 			if (quit())
     91 				return;
     92 		}
     93 
     94 		if (! tflag)
     95 			proll ();
     96 		else  {
     97 			curmove (cturn == -1? 18: 19,39);
     98 			cline ();
     99 			c = -1;
    100 		}
    101 	}
    102 }
    103 
    104 movokay (mv)
    106 register int	mv;
    107 
    108 {
    109 	register int	i, m;
    110 
    111 	if (d0)
    112 		swap;
    113 
    114 	for (i = 0; i < mv; i++)  {
    115 
    116 		if (p[i] == g[i])  {
    117 			moverr (i);
    118 			curmove (20,0);
    119 			writel ("Attempt to move to same location.\n");
    120 			return (0);
    121 		}
    122 
    123 		if (cturn*(g[i]-p[i]) < 0)  {
    124 			moverr (i);
    125 			curmove (20,0);
    126 			writel ("Backwards move.\n");
    127 			return (0);
    128 		}
    129 
    130 		if (abs(board[bar]) && p[i] != bar)  {
    131 			moverr (i);
    132 			curmove (20,0);
    133 			writel ("Men still on bar.\n");
    134 			return (0);
    135 		}
    136 
    137 		if ( (m = makmove(i)) )  {
    138 			moverr (i);
    139 			switch (m)  {
    140 
    141 			case 1:
    142 				writel ("Move not rolled.\n");
    143 				break;
    144 
    145 			case 2:
    146 				writel ("Bad starting position.\n");
    147 				break;
    148 
    149 			case 3:
    150 				writel ("Destination occupied.\n");
    151 				break;
    152 
    153 			case 4:
    154 				writel ("Can't remove men yet.\n");
    155 			}
    156 			return (0);
    157 		}
    158 	}
    159 	return (1);
    160 }
    161