int64_t DateTimeParserBucket::computeMillis(bool resetFields, string text) { int count = iSavedFieldsCount; if (iSavedFieldsShared) { // iSavedFields = savedFields = (vector<SavedField*>)iSavedFields.clone(); iSavedFieldsShared = false; } sort(iSavedFields, count); if (count > 0) { // alter base year for parsing if first field is month or day const DurationField *months = DurationFieldType::months()->getField(iChrono); const DurationField *days = DurationFieldType::days()->getField(iChrono); const DurationField *first = iSavedFields[0]->iField->getDurationField(); if (compareReverse(first, months) >= 0 && compareReverse(first, days) <= 0) { saveField(DateTimeFieldType::year(), iDefaultYear); return computeMillis(resetFields, text); } } int64_t millis = iMillis; try { for (int i = 0; i < count; i++) { millis = iSavedFields[i]->set(millis, resetFields); } if (resetFields) { for (int i = 0; i < count; i++) { millis = iSavedFields[i]->set(millis, i == (count - 1)); } } } catch (IllegalFieldValueException e) { if (!text.empty()) { // e.prependMessage("Cannot parse \"" + text + '"'); } throw e; } millis -= iOffset; if (iZone != NULL) { int offset = iZone->getOffsetFromLocal(millis); millis -= offset; if (offset != iZone->getOffset(millis)) { string message = "Illegal instant due to time zone offset transition (" + iZone->toString() + ")"; if (!text.empty()) { message = "Cannot parse \"" + text + "\": " + message; } throw IllegalInstantException(message); } } return millis; }
void Event::updateDuration() { saveField("duration", start().msecsTo(end())); }
int main(int argc, char **argv) { if (argc != 3) { std::cout << "Usage: XO_tester <program1> <program2>\n"; return 1; } const char *program1 = argv[1]; const char *program2 = argv[2]; //initLog(program1, program2); // save field and score before the first move saveField(); ExecutionResult result = ER_OK; for (int move = 0 ; move < size * size ; ++move) { bool first = move % 2 == 0; std::ostringstream outs; outs << !first + 1 << "\n"; for (int i = 0 ; i < size ; ++i) { for (int j = 0 ; j < size ; ++j) { outs << field[i][j] << " "; } outs << "\n"; } std::string output; result = runProcess(first ? program1 : program2, outs.str(), output, 1000, 64000); if (result == ER_OK) { std::istringstream ins(output); int x, y; ins >> y >> x; if (x >= 1 && x <= size && y >= 1 && y <= size && !field[y-1][x-1]) { printLog(first, result, output); int xo = first ? 1 : 2; field[y-1][x-1] = xo; saveField(); // check win if (diag1(xo) || diag2(xo) || horz(xo, y - 1) || vert(xo, x - 1)) { result = ER_WIN; printLog(first, result, output); break; } } else { result = ER_IM; printLog(first, result, output); break; } } else {
int main() { long i; long count; long start = 1, end = 1; char nodataerror = 1; Node **path; #ifdef _DEBUG printf("ULONG_MAX: %ld (%d), UINT_MAX: %d (%d),\nUSHRT_MAX: %d (%d), UCHAR_MAX: %d (%d)\n\n",ULONG_MAX,sizeof(unsigned long),UINT_MAX,sizeof(unsigned int),USHRT_MAX,sizeof(unsigned short),UCHAR_MAX,sizeof(unsigned char)); printMemSize(); #endif printf("Enter m and n (number of nodes on the x-axis and y-axis,\n\tthe width and height of the grid)\n\tlike so:\n\t\"x\ty\" (without the quotes)\n"); scanf("%ld%ld",&m,&n); if(m<3){ printf("ERROR: 3 is the minimun for m, your value of: %ld doesn't qualify.\n",m); nodataerror = 0; } if(n<3){ printf("ERROR: 3 is the minimun for n, your value of: %ld doesn't qualify.\n",n); nodataerror = 0; } #ifdef _DEBUG printMemSize(); #endif if(nodataerror){ numNodes = m*n; numLinesH = n*(m-1); numLinesV = m*(n-1); numLines = numLinesH + numLinesV; numControlPosts = 2*(m-2) + 2*(n-2); printf("Enter start and end controlpost (starting from the bottom left numbered CCW)\n\tlike so:\n\"start\tend\" (without the quotes)\n"); scanf("%ld%ld",&start,&end); if(start>numControlPosts||start<1){ printf("ERROR: Start point not on the grid, for these dimensions (%ldx%ld)\n\tthe control posts on the grid are numbered %ld through %ld.\n",m,n,1L,numControlPosts); nodataerror = 0; } if(end>numControlPosts||end<1){ printf("ERROR: End point not on the grid, for these dimensions (%ldx%ld)\n\tthe control posts on the grid are numbered %ld through %ld.\n",m,n,1L,numControlPosts); nodataerror = 0; } if(start==end){ printf("ERROR: Start point is the same as endpoint you won't be needing any navigation.\n"); nodataerror = 0; } #ifdef _DEBUG printMemSize(); #endif if(nodataerror){ printf("Input accepted...\n"); nodes = (Node**)safeMalloc(sizeof(Node*)*numNodes); #ifdef _DEBUG printMemSize(); #endif lines = (Line**)safeMalloc(sizeof(Line*)*numLines); #ifdef _DEBUG printMemSize(); #endif printf("Creating grid..."); createGrid(); printf("Done\n"); #ifdef _DEBUG printMemSize(); #endif //create mines /*placeMine(getNode(2,0),getNode(3,0)); placeMine(getNode(2,1),getNode(3,1)); placeMine(getNode(2,2),getNode(3,2)); placeMine(getNode(2,3),getNode(3,3)); placeMine(getNode(2,4),getNode(3,4));*/ printf("Finding Path... CPs: %ld and %ld\n",start,end); startStopwatch(); path = findShortestRoute(getNodeFromControlPost(start),getNodeFromControlPost(end),&count); printf("Finding the path took %0.4lf seconds.\n",stopStopwatch()); printf("Path length: %ld\n",count); for(i=0;i<count;i++){ printf("\tPath node #%ld at (x,y) => (%ld,%ld)\n",i,path[i]->x,path[i]->y); } #ifdef _DEBUG printMemSize(); #endif safeFree(path); #ifdef _DEBUG if(m<=20){ printField(); } saveField("final_field.txt"); #endif } else { printf("There were errors, can not proceed.\n"); } } #ifdef _DEBUG printMemSize(); #endif printf("Hit enter to exit\n"); //empty stdin and wait emptySTDIN(); getchar(); // return 0; }
void DateTimeParserBucket::saveField(const DateTimeFieldType *fieldType, string text, Locale *locale) { saveField(new SavedField(fieldType->getField(iChrono), text, locale)); }
void DateTimeParserBucket::saveField(const DateTimeFieldType *fieldType, int value) { saveField(new SavedField(fieldType->getField(iChrono), value)); }
void DateTimeParserBucket::saveField(DateTimeField *field, int value) { saveField(new SavedField(field, value)); }
int main(int argc, char **argv) { if (argc != 3 && argc != 4) { std::cout << "Usage: Maxit_tester <program1> <program2> [<seed>]\n"; return 1; } const char *program1 = argv[1]; const char *program2 = argv[2]; // init field if (argc >= 4) srand(atoi(argv[3])); else srand((unsigned int)time(NULL)); for (int i = 0 ; i < size ; ++i) { for (int j = 0 ; j < size ; ++j) { field[i][j] = rand() % size + 1; } } col = 1; row = 1; // save field and score before the first move saveField(1); bool first = true; ExecutionResult result = ER_OK; for (int move = 0 ; move < size * size ; ++move) { std::ostringstream outs; for (int i = 0 ; i < size ; ++i) { for (int j = 0 ; j < size ; ++j) { outs << field[i][j] << " "; } outs << "\n"; } outs << !first + 1 << "\n" << (first ? row : col) << "\n"; std::string output; printInput(first, outs.str()); result = runProcess(first ? program1 : program2, outs.str(), output, 1000, 64000); if (result == ER_OK) { InStream ins(output); int rowcol; try { ins >> ValueInBounds<int>(rowcol, 1, size); } catch (ReadCheckerException &exception) { result = ER_IM; std::ostringstream outs; outs << output << std::endl << exception.getReadResultText() << ": " << exception.what() << std::endl; printLog(first, result, outs.str()); break; } if ( (first && field[row-1][rowcol-1]) || (!first && field[rowcol-1][col-1]) ) { if (first) col = rowcol; else row = rowcol; printLog(first, result, output); scores[!first] += field[row-1][col-1]; field[row-1][col-1] = -field[row-1][col-1]; // save field and score after the correct move saveField(!first + 1); field[row-1][col-1] = 0; // get next player bool canFirst = checkFirst(row); bool canSecond = checkSecond(col); if ((first && canSecond) || (!first && canFirst)) first = !first; else if (canFirst) first = true; else if (canSecond) first = false; else break; } else { result = ER_IM; printLog(first, result, output); break; } } else {