Esempio n. 1
0
int main()
{
  zeropad();
  printfield();
  calculate();
  if (check1() || check2() || check3())
    printf("No solution\n");
  else
    if (solve())
      drawpath();
    else
      printf("Path not found\n");
  return 0;
}
Esempio n. 2
0
void
devcntl(Biobufhdr *inp) {
	char cmd[50], buf[256], str[MAXTOKENSIZE], *line;
	int c, n;

/*
 *
 * Interpret device control commands, ignoring any we don't recognize. The
 * "x X ..." commands are a device dependent collection generated by troff's
 * \X'...' request.
 *
 */

	Bgetfield(inp, 's', cmd, 50);
	if (debug) Bprint(Bstderr, "devcntl(cmd=%s)\n", cmd);
	switch (cmd[0]) {
	case 'f':		/* mount font in a position */
		Bgetfield(inp, 'd', &n, 0);
		Bgetfield(inp, 's', str, 100);
		mountfont(n, str);
		break;

	case 'i':			/* initialize */
		initialize();
		break;

	case 'p':			/* pause */
		break;

	case 'r':			/* resolution assumed when prepared */
		Bgetfield(inp, 'd', &resolution, 0);
		Bgetfield(inp, 'd', &minx, 0);
		Bgetfield(inp, 'd', &miny, 0);
		break;

	case 's':			/* stop */
	case 't':			/* trailer */
		/* flushtext(); */
		break;

	case 'H':			/* char height */
		Bgetfield(inp, 'd', &n, 0);
		t_charht(n);
		break;

	case 'S':			/* slant */
		Bgetfield(inp, 'd', &n, 0);
		t_slant(n);
		break;

	case 'T':			/* device name */
		Bgetfield(inp, 's', devname, 16);
		if (debug) Bprint(Bstderr, "devname=%s\n", devname);
		break;

	case 'E':			/* input encoding - not in troff yet */
		Bgetfield(inp, 's', str, 100);
/*
		if (strcmp(str, "UTF") == 0)
			reading = UTFENCODING;
		else
			reading = ONEBYTE;
 */
		break;

	case 'X':			/* copy through - from troff */
		if (Bgetfield(inp, 's', str, MAXTOKENSIZE-1) <= 0)
			error(FATAL, "incomplete devcntl line\n");
		if ((line = Brdline(inp, '\n')) == 0)
			error(FATAL, "incomplete devcntl line\n");
		strncpy(buf, line, Blinelen(inp)-1);
		buf[Blinelen(inp)-1] = '\0';
		Bungetc(inp);

		if (strncmp(str, "PI", sizeof("PI")-1) == 0 || strncmp(str, "PictureInclusion", sizeof("PictureInclusion")-1) == 0) {
			picture(inp, str);
		} else if (strncmp(str, "InlinePicture", sizeof("InlinePicture")-1) == 0) {
			error(FATAL, "InlinePicture not implemented yet.\n");
/*			inlinepic(inp, buf);			*/
		} else if (strncmp(str, "BeginPath", sizeof("BeginPath")-1) == 0) {
			beginpath(buf, FALSE);
		} else if (strncmp(str, "DrawPath", sizeof("DrawPath")-1) == 0) {
			drawpath(buf, FALSE);
		} else if (strncmp(str, "BeginObject", sizeof("BeginObject")-1) == 0) {
			beginpath(buf, TRUE);
		} else if (strncmp(str, "EndObject", sizeof("EndObject")-1) == 0) {
			drawpath(buf, TRUE);
		} else if (strncmp(str, "NewBaseline", sizeof("NewBaseline")-1) == 0) {
			error(FATAL, "NewBaseline not implemented yet.\n");
/*			newbaseline(buf);			*/
		} else if (strncmp(str, "DrawText", sizeof("DrawText")-1) == 0) {
			error(FATAL, "DrawText not implemented yet.\n");
/*			drawtext(buf);				*/
		} else if (strncmp(str, "SetText", sizeof("SetText")-1) == 0) {
			error(FATAL, "SetText not implemented yet.\n");
/*			settext(buf);				*/
		} else if (strncmp(str, "SetColor", sizeof("SetColor")-1) == 0) {
			error(FATAL, "SetColor not implemented yet.\n");
/*			newcolor(buf);				*/
/*			setcolor();					*/
		} else if (strncmp(str, "INFO", sizeof("INFO")-1) == 0) {
			error(FATAL, "INFO not implemented yet.\n");
/*			flushtext();				*/
/*			Bprint(outp, "%%INFO%s", buf);	*/
		} else if (strncmp(str, "PS", sizeof("PS")-1) == 0 || strncmp(str, "PostScript", sizeof("PostScript")-1) == 0) {
			if(pageon()) {
				endstring();
				Bprint(Bstdout, "%s\n", buf);
			}
		} else if (strncmp(str, "ExportPS", sizeof("ExportPS")-1) == 0) {	/* dangerous!! */
			error(FATAL, "ExportPS not implemented yet.\n");
/*			if (Bfildes(outp) == 1) {		*/
/*				restore();				*/
/*				Bprint(outp, "%s", buf);	*/
/*				save();				*/
/*			}						*/
		}
/*		 else
			error(WARNING, "Unknown string <%s %s> after x X\n", str, buf);
*/

		break;
	}
	while ((c = Bgetc(inp)) != '\n' && c != Beof);
	inputlineno++;
}
Esempio n. 3
0
void Pathfinder::newNode(PathNode* oldnode, PathfindingState& state,
						 unsigned int steps)
{
	PathNode* newnode = new PathNode();
	nodelist.push_back(newnode); // for garbage collection
	newnode->state = state;
	newnode->parent = oldnode;
	newnode->depth = oldnode->depth + 1;
	newnode->stepsfromparent = 0;
	
	double sqrddist;
	
	sqrddist = ((newnode->state.x - oldnode->state.x)*
				(newnode->state.x - oldnode->state.x));
	sqrddist += ((newnode->state.y - oldnode->state.y)*
				 (newnode->state.y - oldnode->state.y));
	sqrddist += ((newnode->state.z - oldnode->state.z)*
				 (newnode->state.z - oldnode->state.z));
	
	unsigned int dist;
	dist = static_cast<unsigned int>(std::sqrt(sqrddist));
	
	int turn = 0;
	
	if (oldnode->depth > 0) {
		turn = state.direction - oldnode->state.direction;
		if (turn < 0) turn = -turn;
		if (turn > 4) turn = 8 - turn;
	}
	
	newnode->cost = oldnode->cost + dist + 32*turn; //!! constant

	bool done = checkTarget(newnode);
	if (done)
		newnode->heuristicTotalCost = 0;
	else
		costHeuristic(newnode);

#if 0
	perr << "trying dir " << state.direction;

	if (steps > 0) {
		perr << ", " << steps << " steps";
	}
	perr << " from ("
		 << oldnode->state.x << "," << oldnode->state.y << ") to ("
		 << newnode->state.x << "," << newnode->state.y
		 << "), cost = " << newnode->cost << ", heurtotcost = "
		 << newnode->heuristicTotalCost << std::endl;
#endif

#ifdef DEBUG
	if (actor->getObjId() == visualdebug_actor) {
		RenderSurface* screen = GUIApp::get_instance()->getScreen();
		screen->BeginPainting();
		drawpath(newnode, 0xFFFFFF00, done);
		screen->EndPainting();
		SDL_Delay(250);
		if (!done) {
			screen->BeginPainting();
			drawpath(newnode, 0xFFB0B000, done);
			screen->EndPainting();
		}
	}
#endif

	nodes.push(newnode);	
}
Esempio n. 4
0
int main (int argc, char * argv[]) {

    int i, j, n;                          // General purpose counters
    double x, y;                          // Source coordinates of particle being tracked
    int source_column, source_row;                // Source grid location
    double r, s, nextr, nexts;            // Values as particle is iterated through the Mandelbrot function
    double x_jump, y_jump;                        // Distances between particles in the source grid
    double target_startx, target_starty;  // Top-left coordinates of drawn area
    double target_endx, target_endy;      // Bottom-right coordinates of drawn area
    double pixel_width;                   // Actual distance represented by a pixel in the drawn area

    char filename[200];


    for (i = 0; i < WIDTH; i++)
    {
        for (j = 0; j < HEIGHT; j++)
        {
            redcount[i][j] = 0;
            greencount[i][j] = 0;
            bluecount[i][j] = 0;
        }
    }

    /*
    target_startx = CENTRE_X - ((double) WIDTH / (ZOOM * 2));
    target_endx = CENTRE_X + ((double) WIDTH / (ZOOM * 2));

    target_starty = CENTRE_Y - ((double) HEIGHT / (ZOOM * 2));
    target_endy = CENTRE_Y + ((double) HEIGHT / (ZOOM * 2));

    pixel_width = (target_endx - target_startx) / WIDTH;

    x_jump = ((double) SOURCE_RIGHT_X - SOURCE_LEFT_X) / SOURCE_COLUMNS;
    y_jump = ((double) SOURCE_BOTTOM_Y - SOURCE_TOP_Y) / SOURCE_ROWS;
    */

    // Map Source (world space) to Pixels (image space)
    double world_2_image_x = (double)(WIDTH -1) / ((double) SOURCE_RIGHT_X - SOURCE_LEFT_X);
    double world_2_image_y = (double)(HEIGHT-1) / ((double) SOURCE_BOTTOM_Y - SOURCE_TOP_Y);

    x_jump = ((double) SOURCE_RIGHT_X - SOURCE_LEFT_X) / (SOURCE_COLUMNS - 1);
    y_jump = ((double) SOURCE_BOTTOM_Y - SOURCE_TOP_Y) / (SOURCE_ROWS    - 1);

    iterations = RED_ITERATIONS_UPPER;
    if (GREEN_ITERATIONS_UPPER > iterations) iterations = GREEN_ITERATIONS_UPPER;
    if (BLUE_ITERATIONS_UPPER > iterations) iterations = BLUE_ITERATIONS_UPPER;

    // Main bit...

    //x = SOURCE_LEFT_X;
    //for (source_column = 0; source_column < SOURCE_COLUMNS; source_column++, x += x_jump)
    //{
    //        y = SOURCE_TOP_Y;
    //        for (source_row = 0; source_row < SOURCE_ROWS; source_row++, y += y_jump)
    double x0;
    source_column = 0;
    for( x0 = SOURCE_LEFT_X; x0 < SOURCE_RIGHT_X; source_column++, x0 += x_jump )
    {
        double y0;
        for( y0 = SOURCE_TOP_Y; y0 < SOURCE_BOTTOM_Y; y0 += y_jump )
        {

#ifdef OPTIMISE
            if
            (
                (x >  -1.2 && x <=  -1.1 && y >  -0.1 && y < 0.1)
                || (x >  -1.1 && x <=  -0.9 && y >  -0.2 && y < 0.2)
                || (x >  -0.9 && x <=  -0.8 && y >  -0.1 && y < 0.1)
                || (x > -0.69 && x <= -0.61 && y >  -0.2 && y < 0.2)
                || (x > -0.61 && x <=  -0.5 && y > -0.37 && y < 0.37)
                || (x >  -0.5 && x <= -0.39 && y > -0.48 && y < 0.48)
                || (x > -0.39 && x <=  0.14 && y > -0.55 && y < 0.55)
                || (x >  0.14 && x <   0.29 && y > -0.42 && y < -0.07)
                || (x >  0.14 && x <   0.29 && y >  0.07 && y < 0.42)
            ) continue;
#endif
            r = 0;
            s = 0;
            for (n = 0; n <= iterations; n++)
            {
                nextr = ((r * r) - (s * s)) + x;
                nexts = (2 * r * s) + y;
                r = nextr;
                s = nexts;
                if (n == iterations)
                {
                    // drawpath(x, y, target_startx, target_starty, pixel_width);
                    break;
                } else if ((r * r) + (s * s) > 4) {
                    //drawpath(x, y, target_startx, target_starty, pixel_width);
                    drawpath(x, y, world_2_image_x, world_2_image_y);
                    break;
                }
            }

        }

        if (source_column % UPDATETICK == 0)
        {
            printf("Reached source column: %d of %d\n", source_column, SOURCE_COLUMNS);
        }

    }

    sprintf(filename, "%s r %d g %d b %d spp %d.bmp", OUTFILE, RED_ITERATIONS_UPPER, GREEN_ITERATIONS_UPPER, BLUE_ITERATIONS_UPPER, (SOURCE_COLUMNS / WIDTH) * (SOURCE_ROWS / HEIGHT));
    drawbmp(filename);

    printf("Done.\n");
    return 0;
}