1 /*
2     Sjeng - a chess variants playing program
3     Copyright (C) 2000 Gian-Carlo Pascutto
4 
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 
19     File: partner.c
20     Purpose: handle partner communication
21 
22 */
23 
24 #include "sjeng.h"
25 #include "protos.h"
26 #include "extvars.h"
27 
28 int hand_value[] = { 0, 100, -100, 210, -210, 0, 0, 250, -250, 450, -450, 230, -230 };
29 int std_hand_value[] = { 0, 100, -100, 210, -210, 0, 0, 250, -250, 450, -450, 230, -230 };
30 
31 bool piecedead;
32 bool partnerdead;
33 
34 int must_go;
35 
ResetHandValue(void)36 void ResetHandValue(void)
37 {
38   memcpy(hand_value, std_hand_value, sizeof(hand_value));
39 }
40 
BegForPartner(void)41 void BegForPartner(void)
42 {
43   if (xb_mode)
44     {
45       /* printf("tellics tell 24 partner please\n"); */
46     }
47   return;
48 };
49 
GreetPartner()50 void GreetPartner()
51 {
52   printf("tellics ptell Hello! I am Sjeng and hope you enjoy playing with me.\n");
53   printf("tellics ptell For help on some commands that I understand, ptell me \'help\'\n");
54 
55   return;
56 };
57 
HandlePartner(char * input)58 void HandlePartner(char *input)
59 {
60   if (input[0] == ' ')
61     {
62       if (!have_partner)
63 	{
64 	  /* catch bogus xboard repartnering */
65 	  sscanf(input+1, "%s", my_partner);
66 	  have_partner = TRUE;
67 	  GreetPartner();
68 	  printf("tellics set f5 bughouse\n");
69 	  printf("tellics unseek\n");
70 	}
71     }
72   else
73     {
74       memset(my_partner, 0, sizeof(my_partner));
75       have_partner = FALSE;
76       BegForPartner();
77       printf("tellics set f5 1=1\n");
78     }
79 };
80 
HandlePtell(char * input)81 void HandlePtell(char *input)
82 {
83   int change = 0;
84   char howmuch[80] = "is...uh...what did you say?\n";
85 
86   if (!strncmp(input+6, "help", 4))
87       {
88 	printf("tellics ptell Commands that I understand are : sit, go, fast, slow, abort, flag, +/++/+++/-/--/---{p,n,b,r,q,d,h,trades}, x, dead, formula, help.\n");
89 	return;
90     }
91 
92   if (Variant != Bughouse && (strncmp(input+6, "sorry", 5)))
93   {
94     printf("tellics ptell Sorry, but I'm not playing a bughouse game.\n");
95     return;
96   }
97 
98   if (!strncmp(input+6, "sit", 3))
99     {
100       printf("tellics ptell Ok, I sit next move. Tell me when to go.\n");
101       must_sit = TRUE;
102       must_go = 0;
103     }
104   else if (!strncmp(input+6, "go", 2) || (!strncmp(input+6, "move", 4)))
105     {
106       printf("tellics ptell Ok, I'm moving.\n");
107       must_sit = FALSE;
108       must_go = 4;
109     }
110   else if (!strncmp(input+6, "fast", 4) || (!strncmp(input+6, "time", 4)))
111     {
112       printf("tellics ptell Ok, I'm going FAST!\n");
113       go_fast = TRUE;
114       must_sit = FALSE;
115     }
116   else if (!strncmp(input+6, "slow", 4))
117     {
118       printf("tellics ptell Ok, moving normally.\n");
119       go_fast = FALSE;
120       must_sit = FALSE;
121     }
122   else if (!strncmp(input+6, "abort", 5))
123     {
124       printf("tellics ptell Requesting abort...\n");
125       printf("tellics abort\n");
126     }
127   else if (!strncmp(input+6, "flag", 4))
128     {
129       printf("tellics ptell Flagging...\n");
130       printf("tellics flag\n");
131     }
132   else if (!strncmp(input+6, "+", 1))
133     {
134       /* trades are handled seperately */
135       if ((strstr(input+6, "trade") != NULL)   /* either an explicit trade request */
136 	  || (                                 /* or there's just no piece in the string */
137 	      (strstr(input+6, "n") == NULL) &&
138 	      (strstr(input+6, "b") == NULL) &&
139 	      (strstr(input+6, "p") == NULL) &&
140 	      (strstr(input+6, "r") == NULL) &&
141 	      (strstr(input+6, "q") == NULL) &&
142 	      (strstr(input+6, "d") == NULL) &&
143 	      (strstr(input+6, "h") == NULL)))
144 	{
145 	  if (comp_color == 1)
146 	    {
147 	      hand_value[wpawn] += 25;
148 	      hand_value[wknight] += 50;
149 	      hand_value[wbishop] += 50;
150 	      hand_value[wrook] += 50;
151 	      hand_value[wqueen] += 100;
152 	    }
153 	  else
154 	    {
155 	      hand_value[bpawn] -= 25;
156 	      hand_value[bknight] -= 50;
157 	      hand_value[bbishop] -= 50;
158 	      hand_value[brook] -= 50;
159 	      hand_value[bqueen] -= 100;
160 	    }
161 	  printf("tellics ptell Ok, trading is GOOD\n");
162 	}
163       /* first, find how much we want that piece */
164       else if (strstr(input+6, "+++") != NULL)
165 	{
166 	  change = 50000;
167 	  strcpy(howmuch, "mates");
168 	}
169       else if (strstr(input+6, "++") != NULL)
170 	{
171 	  change = 1000;
172 	  strcpy(howmuch, "is VERY good (ptell me 'x' to play normal again)");
173 	}
174       else if (strstr(input+6, "+") != NULL)
175 	{
176 	  change = 150;
177 	  strcpy(howmuch, "is good (ptell me 'x' to play normal again)");
178 	}
179       else
180 	DIE;
181 
182       /* now find which piece we want */
183       if (strstr(input+6, "n") != NULL)
184 	{
185 	  if (comp_color == 1)
186 	    /* we want a black knight-> the value for holding a white knight rises */
187 	    hand_value[wknight] = std_hand_value[wknight] + change;
188 	  else
189 	    /* we want a white knight */
190 	    hand_value[bknight] = std_hand_value[bknight] - change;
191 
192 	  printf("tellics ptell Ok, Knight %s\n", howmuch);
193 	}
194       if (strstr(input+6, "b") != NULL)
195 	{
196 	  if (comp_color == 1)
197 	    hand_value[wbishop] = std_hand_value[wbishop] + change;
198 	  else
199 	    hand_value[bbishop] = std_hand_value[bbishop] - change;
200 
201 	  /* b is good, so q is good too */
202 	  if (comp_color == 1)
203 	    hand_value[wqueen] = std_hand_value[wqueen] + change;
204 	  else
205 	    hand_value[bqueen] = std_hand_value[bqueen] - change;
206 
207 	  printf("tellics ptell Ok, Bishop %s\n", howmuch);
208 	}
209      if (strstr(input+6, "r") != NULL)
210 	{
211 	  if (comp_color == 1)
212 	    hand_value[wrook] = std_hand_value[wrook] + change;
213 	  else
214 	    hand_value[brook] = std_hand_value[brook] - change;
215 
216 	  /* r is good, so q is good too */
217 	  if (comp_color == 1)
218 	    hand_value[wqueen] = std_hand_value[wqueen] + change;
219 	  else
220 	    hand_value[bqueen] = std_hand_value[bqueen] - change;
221 
222 	  printf("tellics ptell Ok, Rook %s\n", howmuch);
223 	}
224      if (strstr(input+6, "q") != NULL)
225 	{
226 	  if (comp_color == 1)
227 	    hand_value[wqueen] = std_hand_value[wqueen] + change;
228 	  else
229 	    hand_value[bqueen] = std_hand_value[bqueen] - change;
230 
231 	  printf("tellics ptell Ok, Queen %s\n", howmuch);
232 	}
233      if (strstr(input+6, "p") != NULL)
234 	{
235 	  if (comp_color == 1)
236 	    hand_value[wpawn] = std_hand_value[wpawn] + change;
237 	  else
238 	    hand_value[bpawn] = std_hand_value[bpawn] - change;
239 
240 	  /* p is good, so b and q are good too */
241 	  if (comp_color == 1)
242 	    {
243 	      hand_value[wqueen] = std_hand_value[wqueen] + change;
244 	      hand_value[wbishop] = std_hand_value[wbishop] + change;
245 	    }
246 	  else
247 	    {
248 	      hand_value[bqueen] = std_hand_value[bqueen] - change;
249 	      hand_value[bbishop] = std_hand_value[bbishop] - change;
250 	    }
251 
252 	  printf("tellics ptell Ok, Pawn %s\n", howmuch);
253 	}
254      if (strstr(input+6, "d") != NULL)
255 	{
256 	  if (comp_color == 1)
257 	    {
258 	      hand_value[wpawn] = std_hand_value[wpawn] + change;
259 	      hand_value[wbishop] = std_hand_value[wbishop] + change;
260 	      hand_value[wqueen] = std_hand_value[wqueen] + change;
261 	    }
262 	  else
263 	    {
264 	      hand_value[bpawn] = std_hand_value[bpawn] - change;
265 	      hand_value[bbishop] = std_hand_value[bbishop] - change;
266 	      hand_value[bqueen] = std_hand_value[bqueen] - change;
267 	    }
268 
269 	  printf("tellics ptell Ok, Diagonal %s\n", howmuch);
270 	}
271      if (strstr(input+6, "h") != NULL)
272 	{
273 	  if (comp_color == 1)
274 	    {
275 	      hand_value[wrook] = std_hand_value[wrook] + change;
276 	      hand_value[wqueen] = std_hand_value[wqueen] + change;
277 	    }
278 	  else
279 	    {
280 	      hand_value[brook] = std_hand_value[brook] - change;
281 	      hand_value[bqueen] = std_hand_value[bqueen] - change;
282 	    }
283 
284 	  printf("tellics ptell Ok, Heavy %s\n", howmuch);
285 	}
286     }
287   else if (!strncmp(input+6, "-", 1))
288     {
289       /* trades are handled seperately */
290       if ((strstr(input+6, "trade") != NULL)   /* either an explicit trade request */
291 	  || (                                 /* or there's just no piece in the string */
292 	      (strstr(input+6, "n") == NULL) &&
293 	      (strstr(input+6, "b") == NULL) &&
294 	      (strstr(input+6, "p") == NULL) &&
295 	      (strstr(input+6, "r") == NULL) &&
296 	      (strstr(input+6, "q") == NULL) &&
297 	      (strstr(input+6, "d") == NULL) &&
298 	      (strstr(input+6, "h") == NULL)))
299 	{
300       	  if (comp_color == 1)
301 	    {
302 	      hand_value[bpawn] -= 20;
303 	      hand_value[bknight] -= 50;
304 	      hand_value[bbishop] -= 50;
305 	      hand_value[brook] -= 50;
306 	      hand_value[bqueen] -= 100;
307 	    }
308 	  else
309 	    {
310 	      hand_value[wpawn] += 20;
311 	      hand_value[wknight] += 50;
312 	      hand_value[wbishop] += 50;
313 	      hand_value[wrook] += 50;
314 	      hand_value[wqueen] += 100;
315 	    }
316 	  printf("tellics ptell Ok, trading is BAD\n");
317 	}
318       /* first, find how bad we want to avoid losing that piece */
319       else if (strstr(input+6, "---") != NULL)
320 	{
321 	  change = 50000;
322 	  strcpy(howmuch, "mates you (ptell me 'x' when it no longer mates you)");
323 	}
324       else if (strstr(input+6, "--") != NULL)
325 	{
326 	  change = 1000;
327 	  strcpy(howmuch, "is VERY bad (ptell me 'x' when it is no longer bad)");
328 	}
329       else if (strstr(input+6, "-") != NULL)
330 	{
331 	  change = 150;
332 	  strcpy(howmuch, "is bad (ptell me 'x' when it is no longer bad)");
333 	}
334       else
335 	DIE;
336 
337       if (strstr(input+6, "n") != NULL)
338 	{
339 	  if (comp_color == 1)
340 	    hand_value[bknight] = std_hand_value[bknight] - change;
341 	  else
342 	    hand_value[wknight] = std_hand_value[wknight] + change;
343 
344 	  printf("tellics ptell Ok, Knight %s\n", howmuch);
345 	}
346       if (strstr(input+6, "b") != NULL)
347 	{
348 	  if (comp_color == 1)
349 	    hand_value[bbishop] = std_hand_value[bbishop] - change;
350 	  else
351 	    hand_value[wbishop] = std_hand_value[wbishop] + change;
352 
353 	  /* b is bad, so q is bad too */
354 	  if (comp_color == 1)
355 	    hand_value[bqueen] = std_hand_value[bqueen] - change;
356 	  else
357 	    hand_value[wqueen] = std_hand_value[wqueen] + change;
358 
359 	  printf("tellics ptell Ok, Bishop %s\n", howmuch);
360 	}
361      if (strstr(input+6, "r") != NULL)
362 	{
363 	  if (comp_color == 1)
364 	    hand_value[brook] = std_hand_value[brook] - change;
365 	  else
366 	    hand_value[wrook] = std_hand_value[wrook] + change;
367 
368 	  /* r is bad, so q is bad too */
369 	  if (comp_color == 1)
370 	    hand_value[bqueen] = std_hand_value[bqueen] - change;
371 	  else
372 	    hand_value[wqueen] = std_hand_value[wqueen] + change;
373 
374 	  printf("tellics ptell Ok, Rook %s\n", howmuch);
375 	}
376      if (strstr(input+6, "q") != NULL)
377 	{
378 	  if (comp_color == 1)
379 	    hand_value[bqueen] = std_hand_value[bqueen] - change;
380 	  else
381 	    hand_value[wqueen] = std_hand_value[wqueen] + change;
382 
383 	  printf("tellics ptell Ok, Queen %s\n", howmuch);
384 	}
385      if (strstr(input+6, "p") != NULL)
386 	{
387 	  if (comp_color == 1)
388 	    hand_value[bpawn] = std_hand_value[bpawn] - change;
389 	  else
390 	    hand_value[wpawn] = std_hand_value[wpawn] + change;
391 
392 	  /* p is bad, so b and q are bad too */
393 	  if (comp_color == 1)
394 	    {
395 	      hand_value[bqueen] = std_hand_value[bqueen] - change;
396 	      hand_value[bbishop] = std_hand_value[bbishop] - change;
397 	    }
398 	  else
399 	    {
400 	      hand_value[wqueen] = std_hand_value[wqueen] + change;
401 	      hand_value[wbishop] = std_hand_value[wbishop] + change;
402 	    }
403 
404 	  printf("tellics ptell Ok, Pawn %s\n", howmuch);
405 	}
406      if (strstr(input+6, "d") != NULL)
407 	{
408 	  if (comp_color == 1)
409 	    {
410 	      hand_value[bpawn] = std_hand_value[bpawn] - change;
411 	      hand_value[bbishop] = std_hand_value[bbishop] - change;
412 	      hand_value[bqueen] = std_hand_value[bqueen] - change;
413 	    }
414 	  else
415 	    {
416 	      hand_value[wpawn] = std_hand_value[wpawn] + change;
417 	      hand_value[wbishop] = std_hand_value[wbishop] + change;
418 	      hand_value[wqueen] = std_hand_value[wqueen] + change;
419 	    }
420 
421 	  printf("tellics ptell Ok, Diagonal %s\n", howmuch);
422 	}
423      if (strstr(input+6, "h") != NULL)
424 	{
425 	  if (comp_color == 1)
426 	    {
427 	      hand_value[brook] = std_hand_value[brook] - change;
428 	      hand_value[bqueen] = std_hand_value[bqueen] - change;
429 	    }
430 	  else
431 	    {
432 	      hand_value[wrook] = std_hand_value[wrook] + change;
433 	      hand_value[wqueen] = std_hand_value[wqueen] + change;
434 	    }
435 
436 	  printf("tellics ptell Ok, Heavy %s\n", howmuch);
437 	}
438     }
439   else if (((!strncmp(input+6, "x", 1)
440        || (strstr(input+6, "mate me anymore") != NULL)
441        || ((strstr(input+6, "never") != NULL) && (strstr(input+6, "mind") != NULL)))
442        || (!strncmp(input+6, "=", 1))) && (strstr(input+6, "ptell me") == NULL))
443     {
444       printf("tellics ptell Ok, reverting to STANDARD piece values!\n");
445       ResetHandValue();
446       must_sit = FALSE;
447       partnerdead = FALSE;
448       piecedead = FALSE;
449     }
450   else if (!strncmp(input+6, "i'll have to sit...(dead)", 25) ||
451 	   !strncmp(input+6, "dead", 4))
452     {
453       /* fellow sjeng is dead -> give it all we've got */
454       go_fast = TRUE;
455       must_sit = FALSE;
456       partnerdead = TRUE;
457 
458       /* maybe also here tell go if partner is sjeng ? */
459     }
460   else if (!strncmp(input+6, "i'll have to sit...(piece)", 26))
461     {
462       /* fellow sjeng is dead -> get safe fast */
463       go_fast = TRUE;
464       must_sit = FALSE;
465       piecedead = TRUE;
466     }
467   else if (!strncmp(input+6, "sorry", 5))
468     {
469       return;
470     }
471   else if (!strncmp(input+6, "ok", 2))
472     {
473       return;
474     }
475   else if (!strncmp(input+6, "hi", 2) || (!strncmp(input+6, "hello", 5)))
476     {
477       printf("tellics ptell Greetings.\n");
478     }
479   else if (strstr(input+6, "formula") != NULL)
480   {
481      printf("tellics ptell Setting formula, if you are still interrupted, complain to my operator.\n");
482      printf("tellics set f5 bughouse\n");
483   }
484   else
485     {
486       printf("tellics ptell Sorry, but I don't understand that command.\n");
487     }
488   return;
489 }
490 
491 #define CANCEL_THRESH 3
492 
CheckBadFlow(bool reset)493 void CheckBadFlow(bool reset)
494 {
495   move_s hismoves[MOVE_BUFF];
496   move_s ourmoves[MOVE_BUFF];
497   int his_num_moves, our_num_moves, j, i, ic, icc;
498 
499   bool othermove = FALSE;
500 
501   int
502     pawnmates = FALSE,
503     knightmates = FALSE,
504     bishopmates = FALSE,
505     rookmates = FALSE,
506     queenmates = FALSE;
507 
508   static int
509     pawnmated = FALSE,
510     knightmated = FALSE,
511     bishopmated = FALSE,
512     rookmated = FALSE,
513     queenmated = FALSE;
514 
515   bool
516     pawnwarn = FALSE,
517     knightwarn = FALSE,
518     bishopwarn = FALSE,
519     rookwarn = FALSE,
520     queenwarn = FALSE;
521 
522   if (reset)
523     {
524       pawnmated = FALSE;
525       knightmated = FALSE;
526       bishopmated = FALSE;
527       rookmated = FALSE;
528       queenmated = FALSE;
529       return;
530     }
531 
532   ic = in_check();
533 
534   if (!holding[!white_to_move][(white_to_move ? wpawn : bpawn)])
535     {
536 
537       DropaddHolding((white_to_move ? wpawn : bpawn) , !white_to_move);
538 
539       gen(&hismoves[0]);
540       his_num_moves = numb_moves;
541 
542       for(i = 0; (i < his_num_moves) && (pawnmates == FALSE); i++)
543 	{
544 	  make(&hismoves[0], i);
545 
546 	  if (check_legal(&hismoves[0], i, ic))
547 	    {
548 	      pawnmates = CANCEL_THRESH;
549 
550 	      icc = in_check();
551 
552 	      gen(&ourmoves[0]);
553 	      our_num_moves = numb_moves;
554 
555 	      for (j = 0; (j < our_num_moves) && (pawnmates != FALSE); j++)
556 		{
557 
558 		  make(&ourmoves[0], j);
559 
560 		  if (check_legal(&ourmoves[0], j, icc))
561 		    pawnmates = FALSE;
562 
563 		  unmake(&ourmoves[0], j);
564 
565 		}
566 	    }
567 	  unmake(&hismoves[0], i);
568 	}
569       DropremoveHolding((white_to_move ? wpawn : bpawn), !white_to_move);
570     }
571 
572   if (!holding[!white_to_move][(white_to_move ? wknight : bknight)])
573     {
574 
575       DropaddHolding((white_to_move ? wknight : bknight) , !white_to_move);
576 
577       gen(&hismoves[0]);
578       his_num_moves = numb_moves;
579 
580       for(i = 0; (i < his_num_moves) && (knightmates == FALSE); i++)
581 	{
582 
583 	  make(&hismoves[0], i);
584 
585 	  if (check_legal(&hismoves[0], i, ic))
586 	    {
587 	      knightmates = CANCEL_THRESH;
588 
589 	      icc = in_check();
590 
591 	      gen(&ourmoves[0]);
592 	      our_num_moves = numb_moves;
593 
594 	      for (j = 0; (j < our_num_moves) && (knightmates != FALSE); j++)
595 		{
596 		  make(&ourmoves[0], j);
597 
598 		  if (check_legal(&ourmoves[0], j, icc))
599 		    knightmates = FALSE;
600 
601 		  unmake(&ourmoves[0], j);
602 		}
603 	    }
604 	  unmake(&hismoves[0], i);
605 	}
606       DropremoveHolding((white_to_move ? wknight : bknight), !white_to_move);
607     }
608 
609   if (!holding[!white_to_move][(white_to_move ? wbishop : bbishop)])
610     {
611 
612       DropaddHolding((white_to_move ? wbishop : bbishop) , !white_to_move);
613 
614       gen(&hismoves[0]);
615       his_num_moves = numb_moves;
616 
617       for(i = 0; (i < his_num_moves) && (bishopmates == FALSE); i++)
618 	{
619 	  make(&hismoves[0], i);
620 
621 	  if (check_legal(&hismoves[0], i, ic))
622 	    {
623 	      bishopmates = CANCEL_THRESH;
624 
625 	      icc = in_check();
626 
627 	      gen(&ourmoves[0]);
628 	      our_num_moves = numb_moves;
629 
630 	      for (j = 0; (j < our_num_moves) && (bishopmates != FALSE); j++)
631 		{
632 		  make(&ourmoves[0], j);
633 
634 		  if (check_legal(&ourmoves[0], j, icc))
635 		    bishopmates = FALSE;
636 
637 		  unmake(&ourmoves[0], j);
638 		}
639 	    }
640 	  unmake(&hismoves[0], i);
641 	}
642       DropremoveHolding((white_to_move ? wbishop : bbishop), !white_to_move);
643     }
644 
645   if (!holding[!white_to_move][(white_to_move ? wrook : brook)])
646     {
647 
648       DropaddHolding((white_to_move ? wrook : brook) , !white_to_move);
649 
650       gen(&hismoves[0]);
651       his_num_moves= numb_moves;
652 
653       for(i = 0; (i < his_num_moves) && (rookmates == FALSE); i++)
654 	{
655 	  make(&hismoves[0], i);
656 
657 	  if (check_legal(&hismoves[0], i, ic))
658 	    {
659 	      rookmates = CANCEL_THRESH;
660 
661 	      icc = in_check();
662 
663 	      gen(&ourmoves[0]);
664 	      our_num_moves = numb_moves;
665 
666 	      for (j = 0; (j < our_num_moves) && (rookmates != FALSE); j++)
667 		{
668 		  make(&ourmoves[0], j);
669 
670 		  if (check_legal(&ourmoves[0], j, icc))
671 		    rookmates = FALSE;
672 
673 		  unmake(&ourmoves[0], j);
674 		}
675 	    }
676 	  unmake(&hismoves[0], i);
677 	}
678       DropremoveHolding((white_to_move ? wrook : brook), !white_to_move);
679     }
680 
681   if (!holding[!white_to_move][(white_to_move ? wqueen : bqueen)])
682     {
683 
684       DropaddHolding((white_to_move ? wqueen : bqueen) , !white_to_move);
685 
686       gen(&hismoves[0]);
687       his_num_moves= numb_moves;
688 
689       for(i = 0; (i < his_num_moves) && (queenmates == FALSE); i++)
690 	{
691 	  make(&hismoves[0], i);
692 
693 	  if (check_legal(&hismoves[0], i, ic))
694 	    {
695 	      queenmates = CANCEL_THRESH;
696 
697 	      icc = in_check();
698 
699 	      gen(&ourmoves[0]);
700 	      our_num_moves = numb_moves;
701 
702 	      for (j = 0; (j < our_num_moves) && (queenmates != FALSE); j++)
703 		{
704 		  make(&ourmoves[0], j);
705 
706 		  if (check_legal(&ourmoves[0], j, icc))
707 		    queenmates = FALSE;
708 
709 		  unmake(&ourmoves[0], j);
710 		}
711 	    }
712 	  unmake(&hismoves[0], i);
713 	}
714       DropremoveHolding((white_to_move ? wqueen : bqueen), !white_to_move);
715     }
716 
717   /* order in which we tell things is important if we partner ourselves */
718 
719   /* only update if changed */
720   if (pawnmates != pawnmated)
721     {
722       if (pawnmates == CANCEL_THRESH)
723 	  pawnwarn = TRUE;
724       else if (pawnmates == 0 && pawnmated == 0)
725 	{
726 	  printf("tellics ptell p doesn't mate me anymore\n");
727 	  othermove = TRUE;
728 	}
729     }
730 
731   if (knightmates != knightmated)
732     {
733       if (knightmates == CANCEL_THRESH)
734 	  knightwarn = TRUE;
735       else if (knightmates == 0 && knightmated == 0)
736 	{
737 	  printf("tellics ptell n doesn't mate me anymore\n");
738 	  othermove = TRUE;
739 	}
740     }
741 
742   if (bishopmates != bishopmated)
743     {
744       if (bishopmates == CANCEL_THRESH)
745 	  bishopwarn = TRUE;
746       else if (bishopmates == 0 && bishopmated == 0)
747 	{
748 	  printf("tellics ptell b doesn't mate me anymore\n");
749 	  othermove = TRUE;
750 	}
751     }
752   if (rookmates != rookmated)
753     {
754       if (rookmates == CANCEL_THRESH)
755 	  rookwarn = TRUE;
756       else if (rookmates == 0 && rookmated == 0)
757 	{
758 	  printf("tellics ptell r doesn't mate me anymore\n");
759 	  othermove = TRUE;
760 	}
761     }
762   if (queenmates != queenmated)
763     {
764       if (queenmates == CANCEL_THRESH)
765 	  queenwarn = TRUE;
766       else if (queenmates == 0 && queenmated == 0)
767 	{
768 	  printf("tellics ptell q doesn't mate me anymore\n");
769 	  othermove = TRUE;
770 	}
771     }
772 
773   if (pawnwarn)
774 	printf("tellics ptell ---p\n");
775   if (knightwarn)
776 	printf("tellics ptell ---n\n");
777   if (bishopwarn)
778 	printf("tellics ptell ---b\n");
779   if (rookwarn)
780 	printf("tellics ptell ---r\n");
781   if (queenwarn)
782 	printf("tellics ptell ---q\n");
783 
784   /* if other sjeng had to sit because of piece-loss, he
785      may be able to go now */
786 
787   if (piecedead && othermove)
788     {
789       piecedead = FALSE;
790       printf("tellics ptell x\n");
791       printf("tellics ptell go\n");
792       go_fast = FALSE;
793     }
794 
795   (pawnmates) ? (pawnmated = pawnmates) : (pawnmated--);
796   (bishopmates) ? (bishopmated = bishopmates) : (bishopmated--);
797   (rookmates) ? (rookmated = rookmates) : (rookmated--);
798   (queenmates) ? (queenmated = queenmates) : (queenmated--);
799   (knightmates) ? (knightmated = knightmates) : (knightmated--);
800 
801   return;
802 }
803 
804