1: #include "old.h"
   2: 
   3: mate(n, f)
   4: {
   5:     int a, b;
   6: 
   7:     mantom = !mantom;
   8:     if(f == 0) {
   9:         b = mater(n);
  10:         mantom = !mantom;
  11:         return(b);
  12:     }
  13:     b = 0;
  14:     if(matflg) {
  15:         a = 1;
  16:         while(!mater(a)) {
  17:             if(a >= n) {
  18:                 matflg = 0;
  19:                 return(0);
  20:             }
  21:             a++;
  22:         }
  23:         b = abmove;
  24:         goto out;
  25:     }
  26:     a = n;
  27:     while(mater(a)) {
  28:         if(a == mdepth) {
  29:             printf("Forced mate\n");
  30:             matflg++;
  31:         }
  32:         b = abmove;
  33:         if(a == 0)
  34:             break;
  35:         a--;
  36:     }
  37: out:
  38:     mantom = !mantom;
  39:     if(b) {
  40:         abmove = b;
  41:         return(1);
  42:     }
  43:     return(0);
  44: }
  45: 
  46: mater(ns)
  47: {
  48:     int *p1, *p2, *p3, f;
  49: 
  50:     if(intrp || --ns < 0)
  51:         return(0);
  52:     p1 = lmp;
  53:     p2 = p1;
  54:     p3 = p1;
  55:     mantom? wgen(): bgen();
  56:     while(p2 != lmp) {
  57:         p2++;
  58:         mantom? wmove(*p2): bmove(*p2);
  59:         if((!mantom && !battack(wkpos) && wattack(bkpos)) ||
  60:           (mantom && !wattack(bkpos) && battack(wkpos))) {
  61:             *p3 = *p2;
  62:             p3++;
  63:         }
  64:         mantom? wremove(): bremove();
  65:         p2++;
  66:     }
  67:     lmp = p3;
  68:     p2 = p1;
  69:     while(p2 != lmp) {
  70:         mantom? wmove(*p2): bmove(*p2);
  71:         f = xmater(ns);
  72:         mantom? wremove(): bremove();
  73:         if(f) {
  74:             abmove = *p2;
  75:             lmp = p1;
  76:             return(1);
  77:         }
  78:         p2++;
  79:     }
  80:     lmp = p1;
  81:     return(0);
  82: }
  83: 
  84: xmater(ns)
  85: {
  86:     int *p1, *p2, f;
  87: 
  88:     p1 = lmp;
  89:     p2 = p1;
  90:     mantom? bagen(): wagen();
  91:     if(p2+2 == lmp && rept() == 0)
  92:         ns++;
  93:     while(p2 != lmp) {
  94:         p2++;
  95:         mantom? bmove(*p2): wmove(*p2);
  96:         f = mater(ns);
  97:         mantom? bremove(): wremove();
  98:         if(!f) {
  99:             lmp = p1;
 100:             return(0);
 101:         }
 102:         p2++;
 103:     }
 104:     lmp = p1;
 105:     return(1);
 106: }

Defined functions

mater defined in line 46; used 4 times
xmater defined in line 84; used 1 times
  • in line 71
Last modified: 1979-05-05
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2377
Valid CSS Valid XHTML 1.0 Strict