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 this notice is preserved and that due credit is given 7 * to the University of California at Berkeley. The name of the University 8 * may not be used to endorse or promote products derived from this 9 * software without specific prior written permission. This software 10 * is provided ``as is'' without express or implied warranty. 11 */ 12 13 #ifndef lint 14 static char sccsid[] = "@(#)check.c 5.2 (Berkeley) 02/16/88"; 15 #endif /* not lint */ 16 17 #include "back.h" 18 19 getmove () { 20 register int i, c; 21 22 c = 0; 23 for (;;) { 24 i = checkmove(c); 25 26 switch (i) { 27 case -1: 28 if (movokay(mvlim)) { 29 if (tflag) 30 curmove (20,0); 31 else 32 writec ('\n'); 33 for (i = 0; i < mvlim; i++) 34 if (h[i]) 35 wrhit(g[i]); 36 nexturn(); 37 if (*offopp == 15) 38 cturn *= -2; 39 if (tflag && pnum) 40 bflag = pnum; 41 return; 42 } 43 44 case -4: 45 case 0: 46 if (tflag) 47 refresh(); 48 if (i != 0 && i != -4) 49 break; 50 if (tflag) 51 curmove (20,0); 52 else 53 writec ('\n'); 54 writel (*Colorptr); 55 if (i == -4) 56 writel (" must make "); 57 else 58 writel (" can only make "); 59 writec (mvlim+'0'); 60 writel (" move"); 61 if (mvlim > 1) 62 writec ('s'); 63 writec ('.'); 64 writec ('\n'); 65 break; 66 67 case -3: 68 if (quit()) 69 return; 70 } 71 72 if (! tflag) 73 proll (); 74 else { 75 curmove (cturn == -1? 18: 19,39); 76 cline (); 77 c = -1; 78 } 79 } 80 } 81 82 movokay (mv) 83 register int mv; 84 85 { 86 register int i, m; 87 88 if (d0) 89 swap; 90 91 for (i = 0; i < mv; i++) { 92 93 if (p[i] == g[i]) { 94 moverr (i); 95 curmove (20,0); 96 writel ("Attempt to move to same location.\n"); 97 return (0); 98 } 99 100 if (cturn*(g[i]-p[i]) < 0) { 101 moverr (i); 102 curmove (20,0); 103 writel ("Backwards move.\n"); 104 return (0); 105 } 106 107 if (abs(board[bar]) && p[i] != bar) { 108 moverr (i); 109 curmove (20,0); 110 writel ("Men still on bar.\n"); 111 return (0); 112 } 113 114 if ( (m = makmove(i)) ) { 115 moverr (i); 116 switch (m) { 117 118 case 1: 119 writel ("Move not rolled.\n"); 120 break; 121 122 case 2: 123 writel ("Bad starting position.\n"); 124 break; 125 126 case 3: 127 writel ("Destination occupied.\n"); 128 break; 129 130 case 4: 131 writel ("Can't remove men yet.\n"); 132 } 133 return (0); 134 } 135 } 136 return (1); 137 } 138