Set(int size, SetElement *Elements) { int counter; ClearSet(); for(counter = 0; counter < size; counter++) { AddElem(Elements[counter]); } }
void __fastcall TfrmMain::btnAddClick(TObject *Sender) { if(ListView3->Selected==NULL) { Application->MessageBoxA("请选择一个设备!","提示",MB_ICONINFORMATION); return; } dwAdd = 1; iCaseVtoG = 0; iCaseVID = -1; iCaseDef = ""; setEdit(true); ClearSet(); lblAdd->Caption ="正在添加"; }
void TfrmMain::init() { ListView1->Clear(); ListView2->Clear(); ListView3->Clear(); ListView4->Clear(); ClearSet(); Reload(); if(FADO->Connected) { ADOQuery1->SQL->Text="select * from Devices order by DevID"; ADOQuery1->Open(); AnsiString szSwitchName=""; int fldidx=-1; while(!ADOQuery1->Eof) { TListItem *Item=ListView1->Items->Add(); szSwitchName = ADOQuery1->FieldByName("DevName")->AsString; fldidx = FieldExists(ADOQuery1,"switchname"); if(fldidx>-1) szSwitchName = ADOQuery1->Fields->Fields[fldidx]->AsString; Item->Caption= ADOQuery1->FieldByName("DevName")->AsString;//厂商 Item->SubItems->Add(szSwitchName); //型号 Item->SubItems->Add(ADOQuery1->FieldByName("Name")->AsString);//原来的名称改为识别符号 Item->SubItems->Add(ADOQuery1->FieldByName("supportSNMP")->AsInteger==1?"支持":"不支持"); Item->SubItems->Add(ADOQuery1->FieldByName("typOID")->AsString); Item->SubItems->Add(ADOQuery1->FieldByName("saveOID")->AsString); Item->SubItems->Add(ADOQuery1->FieldByName("saveValue")->AsString); Item->SubItems->Add(ADOQuery1->FieldByName("Telnet")->AsString); Item->SubItems->Add(ADOQuery1->FieldByName("maxportnum")->AsString); Item->SubItems->Add(ADOQuery1->FieldByName("DevID")->AsString);//DevID ADOQuery1->Next(); } //OperaMode ADOQuery1->SQL->Text="select * from OperaMode order by ModeID"; ADOQuery1->Open(); while(!ADOQuery1->Eof) { TListItem *Item=ListView2->Items->Add(); Item->Caption=ADOQuery1->FieldByName("ModeID")->AsString; Item->SubItems->Add(ADOQuery1->FieldByName("remark")->AsString); ADOQuery1->Next(); } } }
VisibleSet::VisibleSet() { dl_TieOff(&m_Sets); ClearSet(); }
Set(SetElement Element) { ClearSet(); AddElem(Element); }
Set() { ClearSet(); }
void UnMakeMove(int ply, int move, int wtm) { register int piece, from, to, captured, promote; /* ---------------------------------------------------------- | | | first, take care of the hash key if there's a possible | | enpassant pawn capture. | | | ---------------------------------------------------------- */ HashKey=save_hash_key[ply]; PawnHashKey=save_pawn_hash_key[ply]; /* ---------------------------------------------------------- | | | now do the piece-specific things by calling the | | appropriate routine. | | | ---------------------------------------------------------- */ piece=Piece(move); from=From(move); to=To(move); captured=Captured(move); promote=Promote(move); UnMakePieceMove: SetRL90(from,OccupiedRL90); SetRL45(from,OccupiedRL45); SetRR45(from,OccupiedRR45); ClearRL90(to,OccupiedRL90); ClearRL45(to,OccupiedRL45); ClearRR45(to,OccupiedRR45); bit_move=Or(set_mask[from],set_mask[to]); PieceOnSquare(to)=0; switch (piece) { /* ******************************************************************************** * * * unmake pawn moves. * * * ******************************************************************************** */ case pawn: if (wtm) { ClearSet(bit_move,WhitePawns); ClearSet(bit_move,WhitePieces); PieceOnSquare(from)=pawn; if (captured == 1) { if(EnPassant(ply) == to) { TotalPieces++; SetRL90(to-8,OccupiedRL90); SetRL45(to-8,OccupiedRL45); SetRR45(to-8,OccupiedRR45); Set(to-8,BlackPawns); Set(to-8,BlackPieces); PieceOnSquare(to-8)=-pawn; Material-=PAWN_VALUE; TotalBlackPawns++; captured=0; } } /* -------------------------------------------------------------------- | | | if this is a pawn promotion, remove the pawn from the counts | | then update the correct piece board to reflect the piece just | | created. | | | -------------------------------------------------------------------- */ if (promote) { TotalWhitePawns++; Material+=PAWN_VALUE; Clear(to,WhitePawns); Clear(to,WhitePieces); switch (promote) { case knight: Clear(to,WhiteKnights); TotalWhitePieces-=knight_v; Material-=KNIGHT_VALUE; break; case bishop: Clear(to,WhiteBishops); Clear(to,BishopsQueens); TotalWhitePieces-=bishop_v; Material-=BISHOP_VALUE; break; case rook: Clear(to,WhiteRooks); Clear(to,RooksQueens); TotalWhitePieces-=rook_v; Material-=ROOK_VALUE; break; case queen: Clear(to,WhiteQueens); Clear(to,BishopsQueens); Clear(to,RooksQueens); TotalWhitePieces-=queen_v; Material-=QUEEN_VALUE; break; } } } else { ClearSet(bit_move,BlackPawns); ClearSet(bit_move,BlackPieces); PieceOnSquare(from)=-pawn; if (captured == 1) { if(EnPassant(ply) == to) { TotalPieces++; SetRL90(to+8,OccupiedRL90); SetRL45(to+8,OccupiedRL45); SetRR45(to+8,OccupiedRR45); Set(to+8,WhitePawns); Set(to+8,WhitePieces); PieceOnSquare(to+8)=pawn; Material+=PAWN_VALUE; TotalWhitePawns++; captured=0; } } /* -------------------------------------------------------------------- | | | if this is a pawn promotion, remove the pawn from the counts | | then update the correct piece board to reflect the piece just | | created. | | | -------------------------------------------------------------------- */ if (promote) { TotalBlackPawns++; Material-=PAWN_VALUE; Clear(to,BlackPawns); Clear(to,BlackPieces); switch (promote) { case knight: Clear(to,BlackKnights); TotalBlackPieces-=knight_v; Material+=KNIGHT_VALUE; break; case bishop: Clear(to,BlackBishops); Clear(to,BishopsQueens); TotalBlackPieces-=bishop_v; Material+=BISHOP_VALUE; break; case rook: Clear(to,BlackRooks); Clear(to,RooksQueens); TotalBlackPieces-=rook_v; Material+=ROOK_VALUE; break; case queen: Clear(to,BlackQueens); Clear(to,BishopsQueens); Clear(to,RooksQueens); TotalBlackPieces-=queen_v; Material+=QUEEN_VALUE; break; } } } break; /* ******************************************************************************** * * * unmake knight moves. * * * ******************************************************************************** */ case knight: if (wtm) { ClearSet(bit_move,WhiteKnights); ClearSet(bit_move,WhitePieces); PieceOnSquare(from)=knight; } else { ClearSet(bit_move,BlackKnights); ClearSet(bit_move,BlackPieces); PieceOnSquare(from)=-knight; } break; /* ******************************************************************************** * * * unmake bishop moves. * * * ******************************************************************************** */ case bishop: ClearSet(bit_move,BishopsQueens); if (wtm) { ClearSet(bit_move,WhiteBishops); ClearSet(bit_move,WhitePieces); PieceOnSquare(from)=bishop; } else { ClearSet(bit_move,BlackBishops); ClearSet(bit_move,BlackPieces); PieceOnSquare(from)=-bishop; } break; /* ******************************************************************************** * * * unmake rook moves. * * * ******************************************************************************** */ case rook: ClearSet(bit_move,RooksQueens); if (wtm) { ClearSet(bit_move,WhiteRooks); ClearSet(bit_move,WhitePieces); PieceOnSquare(from)=rook; } else { ClearSet(bit_move,BlackRooks); ClearSet(bit_move,BlackPieces); PieceOnSquare(from)=-rook; } break; /* ******************************************************************************** * * * unmake queen moves. * * * ******************************************************************************** */ case queen: ClearSet(bit_move,BishopsQueens); ClearSet(bit_move,RooksQueens); if (wtm) { ClearSet(bit_move,WhiteQueens); ClearSet(bit_move,WhitePieces); PieceOnSquare(from)=queen; } else { ClearSet(bit_move,BlackQueens); ClearSet(bit_move,BlackPieces); PieceOnSquare(from)=-queen; } break; /* ******************************************************************************** * * * unmake king moves. * * * ******************************************************************************** */ case king: if (wtm) { ClearSet(bit_move,WhitePieces); PieceOnSquare(from)=king; WhiteKingSQ=from; if (abs(to-from) == 2) { if (to == 6) { from=H1; to=F1; piece=rook; goto UnMakePieceMove; } else { from=A1; to=D1; piece=rook; goto UnMakePieceMove; } } } else { ClearSet(bit_move,BlackPieces); PieceOnSquare(from)=-king; BlackKingSQ=from; if (abs(to-from) == 2) { if (to == 62) { from=H8; to=F8; piece=rook; goto UnMakePieceMove; } else { from=A8; to=D8; piece=rook; goto UnMakePieceMove; } } } break; } /* ******************************************************************************** * * * now it is time to restore a piece that was captured. * * * ******************************************************************************** */ if(captured) { TotalPieces++; SetRL90(to,OccupiedRL90); SetRL45(to,OccupiedRL45); SetRR45(to,OccupiedRR45); switch (captured) { /* ---------------------------------------------------------- | | | restore a captured pawn. | | | ---------------------------------------------------------- */ case pawn: if (wtm) { Set(to,BlackPawns); Set(to,BlackPieces); PieceOnSquare(to)=-pawn; Material-=PAWN_VALUE; TotalBlackPawns++; } else { Set(to,WhitePawns); Set(to,WhitePieces); PieceOnSquare(to)=pawn; Material+=PAWN_VALUE; TotalWhitePawns++; } break; /* ---------------------------------------------------------- | | | restore a captured knight. | | | ---------------------------------------------------------- */ case knight: if (wtm) { Set(to,BlackKnights); Set(to,BlackPieces); PieceOnSquare(to)=-knight; TotalBlackPieces+=knight_v; Material-=KNIGHT_VALUE; } else { Set(to,WhiteKnights); Set(to,WhitePieces); PieceOnSquare(to)=knight; TotalWhitePieces+=knight_v; Material+=KNIGHT_VALUE; } break; /* ---------------------------------------------------------- | | | restore a captured bishop. | | | ---------------------------------------------------------- */ case bishop: Set(to,BishopsQueens); if (wtm) { Set(to,BlackBishops); Set(to,BlackPieces); PieceOnSquare(to)=-bishop; TotalBlackPieces+=bishop_v; Material-=BISHOP_VALUE; } else { Set(to,WhiteBishops); Set(to,WhitePieces); PieceOnSquare(to)=bishop; TotalWhitePieces+=bishop_v; Material+=BISHOP_VALUE; } break; /* ---------------------------------------------------------- | | | restore a captured rook. | | | ---------------------------------------------------------- */ case rook: Set(to,RooksQueens); if (wtm) { Set(to,BlackRooks); Set(to,BlackPieces); PieceOnSquare(to)=-rook; TotalBlackPieces+=rook_v; Material-=ROOK_VALUE; } else { Set(to,WhiteRooks); Set(to,WhitePieces); PieceOnSquare(to)=rook; TotalWhitePieces+=rook_v; Material+=ROOK_VALUE; } break; /* ---------------------------------------------------------- | | | restore a captured queen. | | | ---------------------------------------------------------- */ case queen: Set(to,BishopsQueens); Set(to,RooksQueens); if (wtm) { Set(to,BlackQueens); Set(to,BlackPieces); PieceOnSquare(to)=-queen; TotalBlackPieces+=queen_v; Material-=QUEEN_VALUE; } else { Set(to,WhiteQueens); Set(to,WhitePieces); PieceOnSquare(to)=queen; TotalWhitePieces+=queen_v; Material+=QUEEN_VALUE; } break; /* ---------------------------------------------------------- | | | restore a captured king. [this is an error condition] | | | ---------------------------------------------------------- */ case king: printf("captured a king\n"); printf("piece=%d,from=%d,to=%d,captured=%d\n", piece,from,to,captured); printf("ply=%d\n",ply); if (log_file) DisplayChessBoard(log_file,search); } } #if defined(DEBUG) ValidatePosition(ply,move,"UnMakeMove(2)"); #endif return; }
void PrintReduceOp( void * invec, void * inoutvec, int * len, MPI_Datatype * datatype ) { LineData * src_data = (LineData *)((char*)invec + 2 * sizeof(int)); LineData * dest_data = (LineData *)((char*)inoutvec + 2 * sizeof(int)); LineData * psrcline, * pdestline; int i, j; int count = ((int *)invec)[0]; int linesize = ((int *)invec)[1]; datatype = datatype; len = len; /* Run through each (valid) entry in dest_data and compare it with * each valid entry in src_data. */ for( pdestline = dest_data, i = 0; i < count; pdestline += linesize, i++ ) { /* An empty set indicates that the string is blank; skip it */ if( IsEmpty( pdestline+SET ) ) continue; /* We have a valid string; compare it with each of the * strings in the incoming vector. */ for( psrcline = src_data, j = 0; j < count; psrcline += linesize, j++ ) { /* Skip blank entries */ if( IsEmpty( psrcline+SET ) ) continue; /* If they match, remove this string (because it * won't match any other entries), and mark the * nodes where it appeared. Once we've found a * match to this dest string, there won't be any * more in the source array because it should * contain only one copy of each string, so we * can quit this inner loop after the first match. */ if( strcmp( pdestline+TEXT, psrcline+TEXT ) == 0 ) { UnionSet( pdestline+SET, psrcline+SET ); ClearSet( psrcline+SET ); /* We want to put the result in the * lowest-numbered position in the destination * array so items will come out in the order * of the lowest-numbered node in the set when * we print the sets out. */ if( j < i ) { /* Move to lower-numbered position */ LineData * lower = dest_data + (j * linesize); UnionSet( lower+SET, pdestline+SET ); ClearSet( pdestline+SET ); strcpy( lower+TEXT, pdestline+TEXT ); } break; } } } /* All the matching strings should now be copied into the source. * Those remaining are unique, so we can copy them all into the * dest array. Since each node sends only one string, there's no * danger of overwriting an entry in dest when we copy an entry * from source. */ for( pdestline = dest_data, psrcline = src_data, i = 0; i < count; pdestline += linesize, psrcline += linesize, i++ ) { /* If we find a string whose entry hasn't been cleared, * copy it and its list of nodes. */ if( !IsEmpty( psrcline+SET ) ) { UnionSet( pdestline+SET, psrcline+SET ); strcpy( pdestline+TEXT, psrcline+TEXT ); } } }