static int CheckExtend(struct Position *p) { int kp = p->kingSq[p->turn]; BitBoard att; att = p->atkFr[kp] & p->mask[OPP(p->turn)][0]; if (CountBits(att) > 1) { /* * double check, the king has to move * count no. of flight squares, if only one, extend deeper * */ BitBoard ff; int i; int cnt = 0; DblExt++; ff = KingEPM[kp] & ~p->mask[p->turn][0]; att &= p->slidingPieces; while (att) { i=FindSetBit(att); ClrBit(att, i); ff &= ~Ray[i][kp]; } while (ff) { i=FindSetBit(ff); ClrBit(ff, i); if (!(p->atkFr[i] & p->mask[OPP(p->turn)][0])) cnt++; if (cnt > 1) return ExtendDoubleCheck; } } else { BitBoard ff; BitBoard def; BitBoard tmp; int atp = FindSetBit(att); int cnt = 0; int i; int nd = 0; /* discovered check */ if (atp != M_TO((p->actLog-1)->gl_Move)) { DiscExt++; nd = ExtendDiscoveredCheck; } ff = KingEPM[kp] & ~p->mask[p->turn][0]; i = FindSetBit(att); if (Sliding[TYPE(p->piece[i])]) ff &= ~Ray[i][kp]; /* check for king flight squares */ while (ff) { i=FindSetBit(ff); ClrBit(ff, i); if (!(p->atkFr[i] & p->mask[OPP(p->turn)][0])) cnt++; if (cnt > 1) return nd; } /* Find all non-pinned defenders */ def = p->mask[p->turn][0] & ~p->mask[p->turn][King]; tmp = (p->mask[OPP(p->turn)][Bishop] | p->mask[OPP(p->turn)][Queen]) & BishopEPM[kp]; while (tmp) { BitBoard tmp2; i=FindSetBit(tmp); ClrBit(tmp, i); tmp2= InterPath[i][kp]; if (tmp2 && !(p->mask[OPP(p->turn)][0] & tmp2)) { tmp2 &= p->mask[p->turn][0]; if (CountBits(tmp2) == 1) { ClrBit(def, FindSetBit(tmp2)); } } } tmp = (p->mask[OPP(p->turn)][Rook] | p->mask[OPP(p->turn)][Queen]) & RookEPM[kp]; while (tmp) { BitBoard tmp2; i=FindSetBit(tmp); ClrBit(tmp, i); tmp2= InterPath[i][kp]; if (tmp2 && !(p->mask[OPP(p->turn)][0] & tmp2)) { tmp2 &= p->mask[p->turn][0]; if (CountBits(tmp2) == 1) { ClrBit(def, FindSetBit(tmp2)); } } } /* All non-pinned defenders are in 'def' */ tmp = p->atkFr[atp] & def; cnt += CountBits(tmp); if (cnt > 1) return nd; /* if possible, try an interposition */ if (Sliding[TYPE(p->piece[atp])]) { tmp = InterPath[atp][kp]; while (tmp) { BitBoard tmp2; i=FindSetBit(tmp); ClrBit(tmp, i); if ((tmp2 = p->atkFr[i] & def)) { cnt+=CountBits(tmp2); } if (p->turn == White && (i-8) > 0 && TstBit(p->mask[White][Pawn], i-8) && TstBit(def, i-8)) cnt++; if (p->turn == Black && (i+8) < 64 && TstBit(p->mask[Black][Pawn], i+8) && TstBit(def, i+8)) cnt++; if (cnt > 1) return nd; } } } /* If we get here, we have only one legal move. */ SingExt++; return ExtendSingularReply; }
/*-----------------------------------------------------------------------------* * Function Description: * * LED处理进程. * * Parameters: * * None * * Return * * None * *----------------------------------------------------------------------------*/ void LedProc(void) { g_u8LedTxDAT1 = 0; g_u8LedTxDAT2 = 0; if(bSys_1000MS) { if(bLEDBlank) bLEDBlank = 0; else bLEDBlank = 1; } if(bLEDBlank) { g_u8LedBuf = g_u8LedVal; } else { g_u8LedBuf = g_u8LedVal & (~g_u8LedBlank); } if((bPwroffline==1)||(bLidOCDEn==0)) //掉电或开盖时关闭指示灯 { Enter_Bank1; IO_LED_BKL = 0; Enter_Bank0; } else { if(TstBit(g_u8LedBuf,NUM_LED_START)) { SetBit(g_u8LedTxDAT1, NUM_LED_START); } if(TstBit(g_u8LedBuf,NUM_LED_STOP)) { SetBit(g_u8LedTxDAT1, NUM_LED_STOP); } if(TstBit(g_u8LedBuf,NUM_LED_REHEAT)) { SetBit(g_u8LedTxDAT1, NUM_LED_REHEAT); } if(TstBit(g_u8LedBuf,NUM_LED_WARM)) { SetBit(g_u8LedTxDAT1, NUM_LED_WARM); } if(TstBit(g_u8LedBuf,NUM_LED_DELAY)) { SetBit(g_u8LedTxDAT1, NUM_LED_DELAY); } if(TstBit(g_u8LedBuf,NUM_LED_BKL)) { Enter_Bank1; IO_LED_BKL = 1; Enter_Bank0; } else { Enter_Bank1; IO_LED_BKL = 0; Enter_Bank0; } g_u8LedTxDAT2 = g_u8LedTxDAT1<<3; } }