PolicyBucket PolicyBucket::filtered(const PolicyKey &key) const { PolicyBucket result(m_id + "_filtered"); const auto &policies = m_policyCollection; const auto variants = PolicyKeyHelpers::keyVariants(key); for (const auto &variant : variants) { const auto policyIter = policies.find(variant); if (policyIter != policies.end()) { result.m_policyCollection[policyIter->first] = policyIter->second; } } // Inherit original policy result.setDefaultPolicy(defaultPolicy()); return result; }
//se precisa de começar e tem mais 3's pode n ter nenhuma jogada e passa, daí os 4 passos //jogadasN, vai sempre com o mm sametype, para1, 2 ou 3 cartas int main(){ char input[100]; int flag = 0, i; int flag2[1] = {0}; int flag3 = 0; char output[100]; int n, v; int io_count = 0; int counter = 0; int jog = 3; int jog_temp = 0; int a = 0; MAO mao_temp = 0; MAO usadas_temp[3] = {0}; MCtree temp; char mao[13][2]; DATABASE data = {{0},0,0,0,{0},0}; DATABASE simulacao; MCtree tree = NULL; clock_t start; memset(mao,0,26); srand(time(0)); fgets(input, 100, stdin); while(input[0] != 'A'){ switch(input[0]){ case 'J': if(input[3] == 'A'){ if((flag3 != 0 )|| (carta_existe(data.mao[0],0,0))){ flag3 = 1; start = clock(); if(data.firstplay == 0){ data.firstplay = 1; for(jog_temp = jog_temp -1, counter = 0; counter <= jog_temp; counter++) data.usadas[counter +(3-jog_temp)] = usadas_temp[counter]; if(usadas_temp[0] != 0) data.firstplay = 2; } while(((clock()-start)/CLOCKS_PER_SEC) < 2.0){ simulacao = data; while(flag == 0){ temp = treePolicy(tree, &simulacao, flag2); flag = defaultPolicy(temp, &simulacao, flag2); flag2[0] = 0; a++; } flag = 0; } jog = 1; if(data.firstplay != 2) checkFirst(tree, &data); temp = choosePlay(tree,&data); if(temp != NULL) convertejogstr(temp->estado,output); else{ strcpy(output, "PASSO"); } printf("%s\n", output); if(output[0] != 'P') fgets(input, 100, stdin); else input[0] = 'O'; if(input[0] == 'O'){ if(temp == NULL || temp->estado == 0){ data.passar++; if(data.passar == 3){ data.nc = 0; data.jogada = 0; } } else{ data.passar = 0; data.jogada = temp->estado; data.nc = 0; for(i = 0; i < 52; i++){ n = i / 13; v = i % 13; if(carta_existe(temp->estado,n,v)) data.nc++; } free_nodes(tree,temp); tree = temp; tree->prev = NULL; data.usadas[0] = data.usadas[0] | tree-> estado; data.mao[0] = (data.mao[0]) ^ (tree->estado); } } else if(input[0] == 'N'){ data.passar++; if(data.passar == 3){ data.nc = 0; data.jogada = 0; } } } else{ printf("PASSO\n"); } } else{ mao_temp = 0; io_count = sscanf(input, JOGADA, &mao[0][0],&mao[0][1],&mao[1][0],&mao[1][1],&mao[2][0],&mao[2][1],&mao[3][0],&mao[3][1],&mao[4][0],&mao[4][1],&mao[5][0],&mao[5][1],&mao[6][0],&mao[6][1],&mao[7][0],&mao[7][1],&mao[8][0],&mao[8][1],&mao[9][0],&mao[9][1],&mao[10][0],&mao[10][1],&mao[11][0],&mao[11][1],&mao[12][0],&mao[12][1]); for(i = 0; i < io_count/2; i++){ if(mao[i][0] >= '3' && mao[i][0] <='9') v = mao[i][0] - '3'; else{ switch(mao[i][0]){ case '2': v = 12; break; case 'A': v = 11; break; case 'K': v = 10; break; case 'Q': v = 9; break; case 'J': v = 8; break; case 'T': v = 7; break; } } switch (mao[i][1]){ case 'D': n = 0; break; case 'C': n = 1; break; case 'H': n = 2; break; case 'S': n = 3; break; } mao_temp = add_carta(mao_temp,n,v); } if(data.firstplay != 0){ jog = (jog + 1) % 4; data.usadas[jog] = data.usadas[jog] | mao_temp; } else{ usadas_temp[jog_temp] = mao_temp; jog_temp++; } data.jogada = mao_temp; data.nc = i; if(data.nc == 5) data.nc = 4; data.passar = 0; flag3 = 1; } break; case 'P': if(flag3 != 0){ data.passar++; if(data.firstplay == 0){ if(jog_temp != 0) jog_temp++; } else{ jog = (jog + 1) % 4; } if(data.passar == 3){ data.nc = 0; data.jogada = 0; } } break; case 'M': sscanf(input, MAO_INICIAL, &mao[0][0],&mao[0][1],&mao[1][0],&mao[1][1],&mao[2][0],&mao[2][1],&mao[3][0],&mao[3][1],&mao[4][0],&mao[4][1],&mao[5][0],&mao[5][1],&mao[6][0],&mao[6][1],&mao[7][0],&mao[7][1],&mao[8][0],&mao[8][1],&mao[9][0],&mao[9][1],&mao[10][0],&mao[10][1],&mao[11][0],&mao[11][1],&mao[12][0],&mao[12][1]); for(i = 0; i < 13; i++){ if(mao[i][0] >= '3' && mao[i][0] <='9') v = mao[i][0] - '3'; else{ switch(mao[i][0]){ case '2': v = 12; break; case 'A': v = 11; break; case 'K': v = 10; break; case 'Q': v = 9; break; case 'J': v = 8; break; case 'T': v = 7; break; } } switch (mao[i][1]){ case 'D': n = 0; break; case 'C': n = 1; break; case 'H': n = 2; break; case 'S': n = 3; break; } data.mao[0] = add_carta(data.mao[0],n,v); } tree = createTree(data.mao[0]); temp = tree; flag3 = 0; break; } fgets(input, 100, stdin); } return 0; }
void JSSecurityPolicy::setDefaultPolicy( JSSecurityPolicy *pol ) { if ( policy ) delete policy; policy = pol ? pol : defaultPolicy(); }
bool HeaderStrategy::showHeader( const QString & header ) const { if ( headersToDisplay().contains( header.lower() ) ) return true; if ( headersToHide().contains( header.lower() ) ) return false; return defaultPolicy() == Display; }
void CMdSSqLiteConnection::OpenDbL( const TDesC& aDbFileName ) { _LIT8( KMdsSqlDbaConfig, "cache_size=2000; page_size=2048; encoding=\"UTF-16\";"); _LIT8( KBlacklistSqlDbaConfig, "cache_size=1500; page_size=1024; encoding=\"UTF-16\";"); delete iDbFileName; iDbFileName = NULL; // in case AllocL leaves iDbFileName = aDbFileName.AllocL(); TBool setupForMdsServer( EFalse ); // Check if it is MDS server DB that is accessed, otherwise setup will be for Blacklist Server if( iDbFileName->Des().FindF( KMdsSqlDbDefaultName ) != KErrNotFound ) { setupForMdsServer = ETrue; } TInt err = KErrNone; // we need to set up policy, because we use secure database TSecurityPolicy defaultPolicy(TSecurityPolicy::EAlwaysPass); RSqlSecurityPolicy sqlSecurityPolicy; CleanupClosePushL( sqlSecurityPolicy ); err = sqlSecurityPolicy.Create( defaultPolicy ); if ( err != KErrNone ) { _LIT( KMdsSecurityCheckFail, "Security check fail" ); TraceAndLeaveL( KMdsSecurityCheckFail, err ); } /** * Open database: * First we try to open db. If this fails because db not creater yer, then * try to create it. Otherwise we cannot open it and we leave */ if( setupForMdsServer ) { err = iMdeSqlDb.Open( *iDbFileName, &KMdsSqlDbaConfig ); } else { err = iMdeSqlDb.Open( *iDbFileName, &KBlacklistSqlDbaConfig ); } if ( err != KErrNone ) { __LOG1( ELogDb, "Cannot open database %d", err ); if( err == KErrNotFound ) { __LOG1( ELogDb, "Cannot find database %d", err ); if( setupForMdsServer ) { err = iMdeSqlDb.Create( *iDbFileName, sqlSecurityPolicy, &KMdsSqlDbaConfig ); } else { err = iMdeSqlDb.Create( *iDbFileName, sqlSecurityPolicy, &KBlacklistSqlDbaConfig ); } if( err != KErrNone ) { __LOG1( ELogDb, "Unknown error while creating %d", err ); User::LeaveIfError( err ); } } else if( err == KErrCorrupt || err == KSqlErrCorrupt ) { __LOGLB( ELogDb, "Warning: Database is corrupted, will delete and re-create it." ); if( setupForMdsServer ) { err = DeleteAndReCreateDB( iDbFileName, sqlSecurityPolicy, &KMdsSqlDbaConfig ); } else { err = DeleteAndReCreateDB( iDbFileName, sqlSecurityPolicy, &KBlacklistSqlDbaConfig ); } if ( KErrNone == err ) { if( setupForMdsServer ) { err = iMdeSqlDb.Open( *iDbFileName, &KMdsSqlDbaConfig ); } else { err = iMdeSqlDb.Open( *iDbFileName, &KBlacklistSqlDbaConfig ); } if ( err != KErrNone ) { __LOG1( ELogDb, "Cannot open database again after delete and re-create %d", err ); User::LeaveIfError( err ); } } } else { __LOG1( ELogDb, "Unknown error while accessing database %d", err ); User::LeaveIfError( err ); } } CleanupStack::PopAndDestroy( &sqlSecurityPolicy ); }