void ICACHE_FLASH_ATTR processPump(void) { // Every 100mS updatePressure(); checkLevel(); switch (pumpState()) { case MANUAL_OFF: easygpio_outputSet(PUMP, 0); pumpOnCount = 0; checkNotFlowing(); break; case MANUAL_ON: if (secondsNotFlowing() > 30) { pumpState_OffManual(); easygpio_outputSet(PUMP, 0); sounderAlarm(3); // No flow for 30S in Manual } else { easygpio_outputSet(PUMP, 1); } break; case AUTO_OFF: if (getCurrentPressure() < sysCfg.settings[SET_PUMP_ON]) { startCheckIsFlowing(); pumpState_OnAuto(); easygpio_outputSet(PUMP, 1); } else { easygpio_outputSet(PUMP, 0); pumpOnCount = 0; checkNotFlowing(); } sounderClear(); break; case AUTO_ON: if (getCurrentPressure() > sysCfg.settings[SET_PUMP_OFF]) { pumpState_OffAuto(); easygpio_outputSet(PUMP, 0); } else { if (secondsNotFlowing() > sysCfg.settings[SET_NO_FLOW_AUTO_ERROR]) { publishAlarm(1, flowAverageReading()); // No flow for SET_NO_FLOW_AUTO_ERROR (10S) in Auto sounderAlarm(1); publishAlarm(6, secondsNotFlowing()); // No flow for SET_NO_FLOW_AUTO_ERROR (10S) in Auto pumpState_OffManual(); } else { pumpOnCount++; if (pumpOnCount >= sysCfg.settings[SET_MAX_PUMP_ON_WARNING] && getCurrentPressure() < sysCfg.settings[SET_LOW_PRESSURE_WARNING]) { publishError(3, getCurrentPressure()); // Low pressure and Pump On > SET_MAX_PUMP_ON_WARNING } if (pumpOnCount >= sysCfg.settings[SET_MAX_PUMP_ON_WARNING]) { // 1 minute publishError(1, sysCfg.settings[SET_MAX_PUMP_ON_WARNING]); } else if (pumpOnCount == sysCfg.settings[SET_MAX_PUMP_ON_ERROR]) { // 5 minutes publishAlarm(2, pumpOnCount); // Running for SET_MAX_PUMP_ON_ERROR (5 Minutes) in Auto sounderAlarm(2); } else if (pumpOnCount > sysCfg.settings[SET_MAX_PUMP_ON_ERROR]) { pumpOnCount = sysCfg.settings[SET_MAX_PUMP_ON_ERROR] + 1; } } } break; } }
int main(void) { int arr[MAX_SIZE]; int level = 1; // Ensure the seed is different in every execution srand(time(NULL)); do { printNextLevel(arr, level); int check = checkLevel(arr, level); if (check == WRONG) { printf("You lost in level %d\n", level); return EXIT_FAILURE; } level++; } while (level <= MAX_SIZE); printf("You won after level level %d\n", level - 1); return EXIT_SUCCESS; }
int main(int argc, const char *argv[]) { if (argc<2) usage(0); int arg = 1; while (arg < argc) { if (stricmp(argv[arg], "-crc") == 0) { checkCRC = true; } else if (stricmp(argv[arg], "-errorLimit") == 0) { ++arg; if (arg>=argc) usage(1); errorLimit = strtoul(argv[arg], NULL, 10); if (!errorLimit) errorLimit = (unsigned) -1; } else if (stricmp(argv[arg], "-node") == 0) { ++arg; if (arg>=argc) usage(1); nodeAddress = strtoul(argv[arg], NULL, 16); checkCRC = true; } else if (stricmp(argv[arg], "-noleaf") == 0) { skipLeafLevel = true; } else if (stricmp(argv[arg], "-quick") == 0) { quick = true; } else if (*argv[arg]=='-') usage(1); ++arg; } arg = 1; while (arg < argc) { if (*argv[arg]!='-') { curFileName = argv[arg]; printf("Processing key file %s\n", curFileName); int f = _open(argv[arg], _O_RDONLY|_O_BINARY); if (f==-1) { noteError(0, "Could not open file\n"); } else { KeyHdr h; if (_read(f, &h, sizeof(h)) != sizeof(h)) { noteError(0, "Could not read key header\n"); } else { SwapBigEndian(h); if (nodeAddress) { checkNode(f, h, nodeAddress); } else if (quick) { int levels = countLevels(f, h, h.root); printf("%d levels found\n", levels); } else { unsigned level = 0; checkLevel(f, h, level, h.root); } } _close(f); } } arg++; } return errors; }
void checkLevel(int f, KeyHdr &h, unsigned &level, offset_t firstnode) { unsigned nodecount = 0; unsigned maxExpandSize = 0; unsigned __int64 totalExpandSize = 0; unsigned __int64 reccount = 0; unsigned __int64 maxcount = 0; offset_t thisnode = firstnode; while (thisnode) { _lseeki64(f, thisnode, SEEK_SET); char *nodeData = (char *) malloc(h.nodeSize); if (!nodeData || _read(f, nodeData, h.nodeSize) != h.nodeSize) { noteError(thisnode, "Could not read node (error %d)\n", errno); free(nodeData); return; } NodeHdr &nodeHdr = *(NodeHdr *) nodeData; swap(nodeHdr); if ( nodeHdr.rightSib > h.phyrec || nodeHdr.leftSib > h.phyrec || nodeHdr.rightSib % h.nodeSize || nodeHdr.leftSib % h.nodeSize || nodeHdr.keyBytes == 0 || nodeHdr.keyBytes > h.nodeSize ) { noteError(thisnode, "Htree: Corrupt key node detected (keyBytes==%x)\n", nodeHdr.keyBytes ); } else if (nodeHdr.crc32 && checkCRC) { unsigned crc = mcrc32(nodeData+sizeof(NodeHdr), nodeHdr.keyBytes, 0); if (nodeHdr.crc32 != crc) { noteError(thisnode, "CRC error on key node (keyBytes==%x)\n", nodeHdr.keyBytes ); } } if (nodeHdr.leafFlag) { if (skipLeafLevel) { level++; free(nodeData); return; } if ((h.ktype & (HTREE_COMPRESSED_KEY|HTREE_QUICK_COMPRESSED_KEY))==HTREE_COMPRESSED_KEY) { unsigned expandSize; memcpy(&expandSize, nodeData+sizeof(NodeHdr)+8, 4); _WINREV(expandSize); if (expandSize > maxExpandSize) maxExpandSize = expandSize; totalExpandSize += expandSize; } } else { unsigned nodeKeyLength = h.nodeKeyLength; if (nodeKeyLength==(unsigned)-1) nodeKeyLength = h.length; unsigned expandSize = nodeKeyLength * nodeHdr.numKeys; if (expandSize > maxExpandSize) maxExpandSize = expandSize; totalExpandSize += expandSize; if (!nodecount) { unsigned __int64 fpos = *(unsigned __int64 *) (nodeData + sizeof(nodeHdr)); _WINREV(fpos); checkLevel(f, h, level, fpos); } } nodecount++; reccount+= nodeHdr.numKeys; if (nodeHdr.numKeys > maxcount) maxcount = nodeHdr.numKeys; thisnode = nodeHdr.rightSib; free(nodeData); } printf("%d nodes containing %"I64F"d records expanding to %"I64F"d bytes (average %.2f per node, maximum %"I64F"d, max expand %d) at level %d\n", nodecount, reccount, totalExpandSize, (float) reccount/nodecount, maxcount, maxExpandSize, level); level++; }
static bool checkCond(lquery_level * curq, int query_numlevel, ltree_level * curt, int tree_numlevel, FieldNot * ptr) { uint32 low_pos = 0, high_pos = 0, cur_tpos = 0; int tlen = tree_numlevel, qlen = query_numlevel; int isok; lquery_level *prevq = NULL; ltree_level *prevt = NULL; if (SomeStack.muse) { high_pos = SomeStack.high_pos; qlen--; prevq = curq; curq = LQL_NEXT(curq); SomeStack.muse = false; } while (tlen > 0 && qlen > 0) { if (curq->numvar) { prevt = curt; while (cur_tpos < low_pos) { curt = LEVEL_NEXT(curt); tlen--; cur_tpos++; if (tlen == 0) return false; if (ptr && ptr->q) ptr->nt++; } if (ptr && curq->flag & LQL_NOT) { if (!(prevq && prevq->numvar == 0)) prevq = curq; if (ptr->q == NULL) { ptr->t = prevt; ptr->q = prevq; ptr->nt = 1; ptr->nq = 1 + ((prevq == curq) ? 0 : 1); ptr->posq = query_numlevel - qlen - ((prevq == curq) ? 0 : 1); ptr->post = cur_tpos; } else { ptr->nt++; ptr->nq++; } if (qlen == 1 && ptr->q->numvar == 0) ptr->nt = tree_numlevel - ptr->post; curt = LEVEL_NEXT(curt); tlen--; cur_tpos++; if (high_pos < cur_tpos) high_pos++; } else { isok = false; while (cur_tpos <= high_pos && tlen > 0 && !isok) { isok = checkLevel(curq, curt); curt = LEVEL_NEXT(curt); tlen--; cur_tpos++; if (isok && prevq && prevq->numvar == 0 && tlen > 0 && cur_tpos <= high_pos) { FieldNot tmpptr; if (ptr) memcpy(&tmpptr, ptr, sizeof(FieldNot)); SomeStack.high_pos = high_pos - cur_tpos; SomeStack.muse = true; if (checkCond(prevq, qlen + 1, curt, tlen, (ptr) ? &tmpptr : NULL)) return true; } if (!isok && ptr) ptr->nt++; } if (!isok) return false; if (ptr && ptr->q) { if (checkCond(ptr->q, ptr->nq, ptr->t, ptr->nt, NULL)) return false; ptr->q = NULL; } low_pos = cur_tpos; high_pos = cur_tpos; } } else { low_pos = cur_tpos + curq->low; high_pos = cur_tpos + curq->high; if (ptr && ptr->q) { ptr->nq++; if (qlen == 1) ptr->nt = tree_numlevel - ptr->post; } } prevq = curq; curq = LQL_NEXT(curq); qlen--; } if (low_pos > tree_numlevel || tree_numlevel > high_pos) return false; while (qlen > 0) { if (curq->numvar) { if (!(curq->flag & LQL_NOT)) return false; } else { low_pos = cur_tpos + curq->low; high_pos = cur_tpos + curq->high; } curq = LQL_NEXT(curq); qlen--; } if (low_pos > tree_numlevel || tree_numlevel > high_pos) return false; if (ptr && ptr->q && checkCond(ptr->q, ptr->nq, ptr->t, ptr->nt, NULL)) return false; return true; }
void Character::addExp( int v ) { stat.exp += v; checkLevel(); saveStat(); }
void Selection(void) // This Is Where Selection Is Done { GLuint buffer[512]; // Set Up A Selection Buffer GLint hits; // The Number Of Objects That We Selected // The Size Of The Viewport. [0] Is <x>, [1] Is <y>, [2] Is <length>, [3] Is <width> GLint viewport[4]; // This Sets The Array <viewport> To The Size And Location Of The Screen Relative To The Window glGetIntegerv(GL_VIEWPORT, viewport); glSelectBuffer(512, buffer); // Tell OpenGL To Use Our Array For Selection // Puts OpenGL In Selection Mode. Nothing Will Be Drawn. Object ID's and Extents Are Stored In The Buffer. (void) glRenderMode(GL_SELECT); glInitNames(); // Initializes The Name Stack glPushName(0); // Push 0 (At Least One Entry) Onto The Stack glMatrixMode(GL_PROJECTION); // Selects The Projection Matrix glPushMatrix(); // Push The Projection Matrix glLoadIdentity(); // Resets The Matrix // This Creates A Matrix That Will Zoom Up To A Small Portion Of The Screen, Where The Mouse Is. gluPickMatrix((GLdouble) resX/2.0, (GLdouble) resY/2.0, 2.0f, 2.0f, viewport); // Apply The Perspective Matrix gluPerspective(45.0f, (GLfloat) (viewport[2]-viewport[0])/(GLfloat) (viewport[3]-viewport[1]), 0.1f, 100.0f); glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix // DrawTargets(); // Render The Targets To The Selection Buffer if(display == LAND1)dLand1(0); if(display == DUNG1)dDungeon(1); glMatrixMode(GL_PROJECTION); // Select The Projection Matrix glPopMatrix(); // Pop The Projection Matrix glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix hits=glRenderMode(GL_RENDER); // Switch To Render Mode, Find Out How Many // Objects Were Drawn Where The Mouse Was //test int dmg = you[0].dmg + you[0].dmgB; if (hits > 0) // If There Were More Than 0 Hits { int choose = buffer[3]; // Make Our Selection The First Object int depth = buffer[1]; // Store How Far Away It Is int loop; for (loop = 1; loop < hits; loop++) // Loop Through All The Detected Hits { // If This Object Is Closer To Us Than The One We Have Selected if (buffer[loop*4+1] < depth && buffer[loop*4+3] != 6 && buffer[loop*4+3] != 5) { choose = buffer[loop*4+3]; // Select The Closer Object depth = buffer[loop*4+1]; // Store How Far Away It Is } } if(display == LAND1) { if (choose == 1)//anubis { anb[0].Hp -= (you[0].dmg + you[0].dmgB); sprintf(tmppp,"You hit Anubis%d for %d damage\n",1,dmg); tmpC=tmppp; tmp_text = 90; if(anb[0].Hp <= 0) { you[0].XP += anb[0].XP; anb[0].alive = 0; Mix_PlayChannel(-1, AnbDie, 0); GetItem(QList[1].itemNeeded); tmpC = "You killed Anubis, gained 1 item"; } } if (choose == 2)//Spider #1 { spd[0].Hp -= (you[0].dmg + you[0].dmgB); sprintf(tmppp,"You hit Spider%d for %d damage\n",1,dmg); tmpC=tmppp; tmp_text = 90; if(spd[0].Hp <= 0) { you[0].XP += spd[0].XP; spd[0].alive = 0; Mix_PlayChannel(-1, SpdDie, 0); tmpC = "You killed Giant Spider"; } } } if(display == DUNG1) { if (choose > 2) { Dun0Mobs[choose-3].Hp -= (you[0].dmg + you[0].dmgB); sprintf(tmppp,"You hit Spider%d for %d damage\n",choose-3,dmg); tmpC=tmppp; tmp_text = 90; if(Dun0Mobs[choose-3].Hp <= 0) { you[0].XP += spd[0].XP; Dun0Mobs[choose-3].alive = 0; Mix_PlayChannel(-1, SpdDie, 0); sprintf(tmppp,"You killed Spider%d \n",choose-3); tmpC=tmppp; tmp_text = 90; // tmpC = "You killed Giant Spider"; } } // printf("Debug::Hit%d\n",choose); } checkLevel(); } }
void Matrix::setLines(int lines) { _lines = lines; checkLevel(); }