src/board.cpp
// This variant of CheckStatus sees if the last move made
// delivered check. It is generally faster than checkStatus
// with no param, because we can use the last move information
// to avoid calling anyAttacks, in many cases.
This variant of CheckStatus sees if the last move made
delivered check. It is generally faster than checkStatus
with no param, because we can use the last move information
to avoid calling anyAttacks, in many cases.
This variant of CheckStatus sees if the last move made delivered check . It is generally faster than checkStatus with no param because we can use the last move information to avoid calling anyAttacks in many cases .
CheckStatusType Board::checkStatus(Move lastMove) const {
   if (state.checkStatus != CheckUnknown) {
      return state.checkStatus;
   }
   if (IsNull(lastMove)) {
      return checkStatus();
   }
   Square kp = kingPos[side];
   Square checker = DestSquare(lastMove);
   int d = Attacks::directions[checker][kp];
   Board &b = (Board&)*this;
   switch(PieceMoved(lastMove)) {
   case Pawn: {
      if (TypeOfMove(lastMove) != Normal)
         return checkStatus();
      if (Attacks::pawn_attacks[kp][oppositeSide()].isSet(checker)) {
         b.state.checkStatus = InCheck;
      }
      else if (Attacks::directions[kp][StartSquare(lastMove)] == 0) {
         b.state.checkStatus = NotInCheck;
      }
      if (state.checkStatus == CheckUnknown)
         return checkStatus();
      else
         return state.checkStatus;
   }
   case Rook:
      switch(d) {
      case 1:
      case -1:
      case 8:
      case -8:
         if (clear(checker,kp)) {
            b.state.checkStatus = InCheck;
         }
      default:
         break;
      }
      if (state.checkStatus == CheckUnknown) {
         if (discAttackDiag(StartSquare(lastMove),kp,oppositeSide())) {
            b.state.checkStatus = InCheck;
         }
         else {
            b.state.checkStatus = NotInCheck;
         }
      }
      break;
   case Bishop: 
      switch(d) {
      case 7:
      case -7:
      case 9:
      case -9:
         if (clear(checker,kp)) {
            b.state.checkStatus = InCheck;
         }
      default:
         break;
      }
      if (state.checkStatus == CheckUnknown) {
         if (discAttackRankFile(StartSquare(lastMove),kp,oppositeSide())) {
            b.state.checkStatus = InCheck;
         }
         else {
            b.state.checkStatus = NotInCheck;
         }
      }
      break;
   case Knight:
      if (Attacks::knight_attacks[checker].isSet(kp)) {
         b.state.checkStatus = InCheck;
      }
      else {    
         if (state.checkStatus == CheckUnknown) {
            if (discAttack(StartSquare(lastMove),kp,oppositeSide())) {
               b.state.checkStatus = InCheck;
            }
            else {
               b.state.checkStatus = NotInCheck;
            }
         }
      }
      break;
   case Queen: 
      if (d && clear(checker,kp)) {
         b.state.checkStatus = InCheck;
      } else {
         b.state.checkStatus = NotInCheck;
      }
      break;
   case King: 
      if (TypeOfMove(lastMove) != Normal) 
         return checkStatus();
      if (Attacks::king_attacks[checker].isSet(kp)) {
         b.state.checkStatus = InCheck;
         return InCheck;
      }
      else if (Attacks::directions[StartSquare(lastMove)][kp] == 0) {
         b.state.checkStatus = NotInCheck;
         return NotInCheck;
      }
      else {
         if (discAttack(StartSquare(lastMove),kp,oppositeSide())) {
            b.state.checkStatus = InCheck;
         }
         else {
            b.state.checkStatus = NotInCheck;
         }
      }
      break;
   default:
      break;
   } 
   return checkStatus();
}
CheckStatusType Board :: checkStatus ( Move lastMove ) const { if ( state . checkStatus != CheckUnknown ) { return state . checkStatus ; } if ( IsNull ( lastMove ) ) { return checkStatus ( ) ; } Square kp = kingPos [ side ] ; Square checker = DestSquare ( lastMove ) ; int d = Attacks :: directions [ checker ] [ kp ] ; Board & b = ( Board & ) * this ; switch ( PieceMoved ( lastMove ) ) { case Pawn : { if ( TypeOfMove ( lastMove ) != Normal ) return checkStatus ( ) ; if ( Attacks :: pawn_attacks [ kp ] [ oppositeSide ( ) ] . isSet ( checker ) ) { b . state . checkStatus = InCheck ; } else if ( Attacks :: directions [ kp ] [ StartSquare ( lastMove ) ] == 0 ) { b . state . checkStatus = NotInCheck ; } if ( state . checkStatus == CheckUnknown ) return checkStatus ( ) ; else return state . checkStatus ; } case Rook : switch ( d ) { case 1 : case -1 : case 8 : case -8 : if ( clear ( checker , kp ) ) { b . state . checkStatus = InCheck ; } default : break ; } if ( state . checkStatus == CheckUnknown ) { if ( discAttackDiag ( StartSquare ( lastMove ) , kp , oppositeSide ( ) ) ) { b . state . checkStatus = InCheck ; } else { b . state . checkStatus = NotInCheck ; } } break ; case Bishop : switch ( d ) { case 7 : case -7 : case 9 : case -9 : if ( clear ( checker , kp ) ) { b . state . checkStatus = InCheck ; } default : break ; } if ( state . checkStatus == CheckUnknown ) { if ( discAttackRankFile ( StartSquare ( lastMove ) , kp , oppositeSide ( ) ) ) { b . state . checkStatus = InCheck ; } else { b . state . checkStatus = NotInCheck ; } } break ; case Knight : if ( Attacks :: knight_attacks [ checker ] . isSet ( kp ) ) { b . state . checkStatus = InCheck ; } else { if ( state . checkStatus == CheckUnknown ) { if ( discAttack ( StartSquare ( lastMove ) , kp , oppositeSide ( ) ) ) { b . state . checkStatus = InCheck ; } else { b . state . checkStatus = NotInCheck ; } } } break ; case Queen : if ( d && clear ( checker , kp ) ) { b . state . checkStatus = InCheck ; } else { b . state . checkStatus = NotInCheck ; } break ; case King : if ( TypeOfMove ( lastMove ) != Normal ) return checkStatus ( ) ; if ( Attacks :: king_attacks [ checker ] . isSet ( kp ) ) { b . state . checkStatus = InCheck ; return InCheck ; } else if ( Attacks :: directions [ StartSquare ( lastMove ) ] [ kp ] == 0 ) { b . state . checkStatus = NotInCheck ; return NotInCheck ; } else { if ( discAttack ( StartSquare ( lastMove ) , kp , oppositeSide ( ) ) ) { b . state . checkStatus = InCheck ; } else { b . state . checkStatus = NotInCheck ; } } break ; default : break ; } return checkStatus ( ) ; }
This variant of CheckStatus sees if the last move made
delivered check.
This variant of CheckStatus sees if the last move made delivered check .
// check for discovered attack // check for discovered attack // check for discovered attack /* castling */ // end switch