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