1: #include "old.h"
   2: 
   3: play(f)
   4: int f;
   5: {
   6:     int t, i, ts[9];
   7: 
   8:     clock();
   9:     ts[8] = 0;
  10:     if(f) goto first;
  11: loop:
  12:     intrp = 0;
  13:     move();
  14: 
  15: first:
  16:     if(manflg)
  17:         goto loop;
  18:     i = mantom;
  19:     t = clktim[i];
  20:     if(!bookm())
  21:     if(!mate(mdepth, 1))
  22:         xplay();
  23:     if(intrp) {
  24:         decrem();
  25:         mantom? bremove(): wremove();
  26:         goto loop;
  27:     }
  28:     if(!abmove) {
  29:         printf("Resign\n");
  30:         onhup();
  31:     }
  32:     makmov(abmove);
  33:     i = clktim[i];
  34:     t = i-t;
  35:     times(ts);
  36:     ts[8] = ts[1];
  37:     if(i/moveno > 150) {
  38:         if(depth > 1)
  39:             goto decr;
  40:         goto loop;
  41:     }
  42:     if(depth==3 && t>180)
  43:         goto decr;
  44:     if(depth==1 && t<60)
  45:         goto incr;
  46:     if(game==3 && t<60 && depth==2)
  47:         goto incr;
  48:     goto loop;
  49: 
  50: incr:
  51:     depth++;
  52:     goto loop;
  53: 
  54: decr:
  55:     goto loop;
  56: }
  57: 
  58: move()
  59: {
  60:     int a, *p, *p1;
  61: 
  62: loop:
  63:     lmp = (int *) done();
  64:     a = manual();
  65:     p = (int *) done();
  66:     p1 = p;
  67:     while(p1 != lmp) {
  68:         p1++;
  69:         if(*p1++ == a) {
  70:             lmp = p;
  71:             makmov(a);
  72:             return;
  73:         }
  74:     }
  75:     printf("Illegal move\n");
  76:     lmp = p;
  77:     goto loop;
  78: }
  79: 
  80: manual()
  81: {
  82:     int a, b, c;
  83:     char *p1;
  84:     extern out1;
  85: 
  86: loop:
  87:     intrp = 0;
  88:     stage();
  89:     rline();
  90:     sbufp = sbuf;
  91:     if(match("save")) {
  92:         save();
  93:         goto loop;
  94:     }
  95:     if(match("test")) {
  96:         testf = !testf;
  97:         goto loop;
  98:     }
  99:     if(match("remove")) {
 100:         if(amp[-1] != -1) {
 101:             decrem();
 102:             mantom? bremove(): wremove();
 103:         }
 104:         if(amp[-1] != -1) {
 105:             decrem();
 106:             mantom? bremove(): wremove();
 107:         }
 108:         goto loop;
 109:     }
 110:     if(match("exit"))
 111:         exit();
 112:     if(match("manual")) {
 113:         manflg = !manflg;
 114:         goto loop;
 115:     }
 116:     if(match("resign"))
 117:         onhup();
 118:     if(moveno == 1 && mantom == 0) {
 119:         if(match("first"))
 120:             play(1);
 121:         if(match("alg")) {
 122:             mfmt = 1;
 123:             goto loop;
 124:         }
 125:         if(match("restore")) {
 126:             restore();
 127:             goto loop;
 128:         }
 129:     }
 130:     if(match("clock")) {
 131:         clktim[mantom] += clock();
 132:         ctime("white", clktim[0]);
 133:         ctime("black", clktim[1]);
 134:         goto loop;
 135:     }
 136:     if(match("score")) {
 137:         score();
 138:         goto loop;
 139:     }
 140:     if(match("setup")) {
 141:         setup();
 142:         goto loop;
 143:     }
 144:     if(match("hint")) {
 145:         a = xplay();
 146:         out(abmove);
 147:         printf(" %d\n", a);
 148:         goto loop;
 149:     }
 150:     if(match("repeat")) {
 151:         if(amp[-1] != -1) {
 152:             a = (int) amp;
 153:             mantom? wremove(): bremove();
 154:             decrem();
 155:             posit(&out1, a);
 156:         }
 157:         goto loop;
 158:     }
 159:     if(*sbufp == '\0') {
 160:         pboard();
 161:         goto loop;
 162:     }
 163:     if((a=algin()) != 0) {
 164:         mfmt = 1;
 165:         return(a);
 166:     }
 167:     if((a=stdin()) != 0) {
 168:         mfmt = 0;
 169:         return(a);
 170:     }
 171:     printf("eh?\n");
 172:     goto loop;
 173: }
 174: 
 175: algin()
 176: {
 177:     int from, to;
 178: 
 179:     from = cooin();
 180:     to = cooin();
 181:     if(*sbufp != '\0') return(0);
 182:     return((from<<8)|to);
 183: }
 184: 
 185: cooin()
 186: {
 187:     int a, b;
 188: 
 189:     a = sbufp[0];
 190:     if(a<'a' || a>'h') return(0);
 191:     b = sbufp[1];
 192:     if(b<'1' || b>'8') return(0);
 193:     sbufp += 2;
 194:     a = (a-'a')+8*('8'-b);
 195:     return(a);
 196: }
 197: 
 198: match(s)
 199: char *s;
 200: {
 201:     char *p1;
 202:     int c;
 203: 
 204:     p1 = sbufp;
 205:     while((c = *s++) != '\0')
 206:         if(*p1++ != c) return(0);
 207:     sbufp = p1;
 208:     return(1);
 209: }
 210: 
 211: done()
 212: {
 213:     int *p;
 214: 
 215:     if(rept() > 3) {
 216:         printf("Draw by repetition\n");
 217:         onhup();
 218:     }
 219:     p = lmp;
 220:     mantom? bagen(): wagen();
 221:     if(p == lmp) {
 222:         if(check())
 223:             if(mantom)
 224:                 printf("White wins\n"); else
 225:                 printf("Black wins\n"); else
 226:         printf("Stale mate\n");
 227:         onhup();
 228:     }
 229:     return((int)p);
 230: }
 231: 
 232: xplay()
 233: {
 234:     int a;
 235: 
 236:     stage();
 237:     abmove = 0;
 238:     a = mantom? bplay(): wplay();
 239:     ivalue = a;
 240:     return(a);
 241: }
 242: 
 243: term()
 244: {
 245: 
 246:     exit(0);
 247: }

Defined functions

algin defined in line 175; used 1 times
cooin defined in line 185; used 2 times
done defined in line 211; used 2 times
manual defined in line 80; used 1 times
  • in line 64
match defined in line 198; used 18 times
move defined in line 58; used 1 times
  • in line 13
play defined in line 3; used 2 times
term defined in line 243; used 2 times
xplay defined in line 232; used 2 times
Last modified: 1993-01-18
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3077
Valid CSS Valid XHTML 1.0 Strict