예제 #1
0
파일: xmaze.c 프로젝트: forestbaker/jqian
int solvefrom(int x, int y) {
    int i;
    static int solved=0;
    static int solvedepth=0;
    if(solved) return(1);
    solvedepth++;
    if(solvedepth>h) h=solvedepth;
    pset(x,y,fg);
    sprintf(status," %d,%d Depth:%d  ",x,y,solvedepth);
    showstatus(1);
    if(x>=(width-4)) {
        solved=1;
        sprintf(status,"Solved! Depth:%d ",solvedepth);
        showstatus(0);
        return(1);
    }
    for(i=0; i<4; i++) {
        if(ppoint(x+sx[i]/2,y+sy[i]/2)==(fg^31)) {
            if(solvefrom(x+sx[i]/2,y+sy[i]/2)) {
                if(button==0 && solved==0) nap(delay);
                solvedepth--;
                return(1);
            }
        }
    }
    pset(x,y,fg^31);
    if(button==0) nap(delay);
    solvedepth--;
    return(0);
}
예제 #2
0
파일: xmaze.c 프로젝트: forestbaker/jqian
void usersolve() {
    x=5;
    y=6;
    ox=x;
    oy=y;
    steps=0;
    r=1;
    m=0;
    while((x!=width-3) && (button==0)) {
        expose();
        XQueryPointer(display,main_win,&root,&win,&root_x,&root_y,&win_x,&win_y,&mask);
        while(ox!=x || oy!=y) {
            steps++;
            pset(ox,oy,7);
            px[m]=ox;
            py[m]=oy;
            if(m<maxdepth) m++;
            sprintf(status," Steps: %d",steps);
            showstatus(0);
            if(ox!=x) ox=x;
            else oy=y;
        }
        pset(ox,oy,7);
        ox=x;
        oy=y;
        pset(x,y,(fg+1)&31);
        if((x>win_x/mag) && (ppoint(x-1,y)!=bg)) x--;
        if((x<win_x/mag) && (ppoint(x+1,y)!=bg)) x++;
        if((y>win_y/mag) && (ppoint(x,y-1)!=bg)) y--;
        if((y<win_y/mag) && (ppoint(x,y+1)!=bg)) y++;
        nap(50);
    }
    if(x==width-3) {
        code=rand();
        sprintf(status," %d Steps! Code:%04X ",steps,code);
        showstatus(0);
        i=0;
        c=1;
        button=0;
        while(button==0) {
            pset(ox,oy,c);
            ox=px[i];
            oy=py[i];
            pset(ox,oy,0);
            i++;
            if(i>=m) {
                i=0;
                c=(c+1)&31;
                if(c==bg) c=(c+1)&31;
            }
            expose();
            nap(20);
        }
    }
    waitnobutton();
}
예제 #3
0
파일: xmaze.c 프로젝트: forestbaker/jqian
void cpusolve(void) {
    h=0;
    sprintf(status,"Clearing maze...");
    showstatus(0);
    for(x=4; x<width-3; x++) {
        for(y=4; y<height-3; y++) {
            if(ppoint(x,y)!=bg) pset(x,y,fg^31);
        }
    }
    x=5;
    y=6;
    r=solvefrom(x,y);
    sprintf(status,"Solution depth: %d",h);
    showstatus(0);
}
예제 #4
0
파일: batt.c 프로젝트: abbrev/punix
/* batt_check() returns one of the following values:
 * 7: >4.6V  full
 * 6: >4.5V  ok
 * 5: >4.3V  medium
 * 4: >4.0V  low
 * 3: >3.7V  very low
 * 2: >3.4V  starving
 * 1: >3.2V  almost dead
 * 0: <=3.2V dead (calculator is reset?)
 */
int batt_check()
{
	int x = spl1();
	int i, j;
	BATTCHECK |= 0x09;
	
	for (i = 6; i >= 0; --i) {
		reinit();
		TRIGLEVEL = i << 7;
		for (j = 110; j >= 0; --j) {
			if (!(BATTSTAT & 0x04))
				goto quit;
		};
	};
quit:
	i = 6 - i;
	G.batt_level = i;
	BATTCHECK &= 0xf7;
	reinit();
	BATTCHECK &= 0xf6;
	WAITSTATE = ~0;
	
	showstatus();
	splx(x);
	return G.batt_level;
}
예제 #5
0
파일: vmexit.c 프로젝트: borisnorm/akaros
static bool handle_ept_fault(struct guest_thread *gth)
{
	struct vm_trapframe *vm_tf = gth_to_vmtf(gth);
	struct virtual_machine *vm = gth_to_vm(gth);
	uint64_t gpa, *regp;
	uint8_t regx;
	int store, size;
	int advance;

	if (decode(gth, &gpa, &regx, &regp, &store, &size, &advance))
		return FALSE;
	assert(size >= 0);
	/* TODO use helpers for some of these addr checks.  the fee/fec ones might
	 * be wrong too. */
	for (int i = 0; i < VIRTIO_MMIO_MAX_NUM_DEV; i++) {
		if (vm->virtio_mmio_devices[i] == NULL)
			continue;
		if (PG_ADDR(gpa) != vm->virtio_mmio_devices[i]->addr)
			continue;
		/* TODO: can the guest cause us to spawn off infinite threads? */
		if (store)
			virtio_mmio_wr(vm, vm->virtio_mmio_devices[i], gpa, size,
			               (uint32_t *)regp);
		else
			*regp = virtio_mmio_rd(vm, vm->virtio_mmio_devices[i], gpa, size);
		vm_tf->tf_rip += advance;
		return TRUE;
	}
	if (PG_ADDR(gpa) == 0xfec00000) {
		do_ioapic(gth, gpa, regx, regp, store);
	} else if (PG_ADDR(gpa) == 0) {
		memmove(regp, &vm->low4k[gpa], size);
	} else {
		fprintf(stderr, "EPT violation: can't handle %p\n", gpa);
		fprintf(stderr, "RIP %p, exit reason 0x%x\n", vm_tf->tf_rip,
				vm_tf->tf_exit_reason);
		fprintf(stderr, "Returning 0xffffffff\n");
		showstatus(stderr, gth);
		/* Just fill the whole register for now. */
		*regp = (uint64_t) -1;
		return FALSE;
	}
	vm_tf->tf_rip += advance;
	return TRUE;
}
예제 #6
0
파일: tint.c 프로젝트: yaozongyou/tetris
int main(int argc, char* argv[]) {
    bool finished;
    int ch;
    engine_t engine;
    /* Initialize */
    rand_init();							/* must be called before engine_init () */
    engine_init(&engine, score_function);	/* must be called before using engine.curshape */
    finished = shownext = FALSE;
    memset(shapecount, 0, NUMSHAPES * sizeof(int));
    shapecount[engine.curshape]++;
    parse_options(argc,argv);				/* must be called after initializing variables */
    if (level < MINLEVEL) {
        choose_level();
    }
    io_init();
    drawbackground();
    in_timeout(DELAY);
    /* Main loop */
    do {
        /* draw shape */
        showstatus(&engine);
        drawboard(engine.board);
        out_refresh();
        /* Check if user pressed a key */
        if ((ch = in_getch ()) != ERR) {
            switch (ch) {
            case 'j':
            case KEY_LEFT:
                engine_move(&engine,ACTION_LEFT);
                break;
            case 'k':
            case '\n':
                engine_move(&engine,ACTION_ROTATE);
                break;
            case 'l':
            case KEY_RIGHT:
                engine_move(&engine,ACTION_RIGHT);
                break;
            case ' ':
            case KEY_DOWN:
                engine_move(&engine,ACTION_DROP);
                break;
                /* show next piece */
            case 's':
                shownext = TRUE;
                break;
                /* toggle dotted lines */
            case 'd':
                dottedlines = !dottedlines;
                break;
                /* next level */
            case 'a':
            case KEY_UP:
                if (level < MAXLEVEL) {
                    level++;
                    in_timeout(DELAY);
                }
                else out_beep();
                break;
                /* quit */
            case 'q':
                finished = TRUE;
                break;
                /* pause */
            case 'p':
                out_setcolor(COLOR_WHITE,COLOR_BLACK);
                out_gotoxy((out_width() - 34) / 2,out_height() - 2);
                out_printf("Paused - Press any key to continue");
                while ((ch = in_getch ()) == ERR) ;	/* Wait for a key to be pressed */
                in_flush();							/* Clear keyboard buffer */
                out_gotoxy((out_width() - 34) / 2, out_height() - 2);
                out_printf("                                  ");
                break;
                /* unknown keypress */
            default:
                out_beep();
            }
            in_flush();
        } else {
            switch (engine_evaluate(&engine)) {
            /* game over (board full) */
            case -1:
                if ((level < MAXLEVEL) && ((engine.status.droppedlines / 10) > level)) level++;
                finished = TRUE;
                break;
                /* shape at bottom, next one released */
            case 0:
                if ((level < MAXLEVEL) && ((engine.status.droppedlines / 10) > level)) {
                    level++;
                    in_timeout(DELAY);
                }
                shapecount[engine.curshape]++;
                break;
                /* shape moved down one line */
            case 1:
                break;
            }
        }
    } while (!finished);
    /* Restore console settings and exit */
    io_close();
    /* Don't bother the player if he want's to quit */
    if (ch != 'q') {
        showplayerstats(&engine);
        savescores(GETSCORE(engine.score));
    }
    exit(EXIT_SUCCESS);
}
예제 #7
0
void doit(char *dir)
{
  struct stat st;
  int r;
  int fd;
  const char *x;
  const char *fntemp;
  char status[40];

  buffer_puts(&b,dir);
  buffer_puts(&b,": ");

  if (chdir(dir) == -1) {
    x = error_str(errno);
    buffer_puts(&b,"unable to chdir: ");
    buffer_puts(&b,x);
    return;
  }
  if (!svpath_init()) {
    strerr_warn4(WARNING,"unable to set up control path for ",dir,": ",&strerr_sys);
    return;
  }

  normallyup = 0;
  if (stat("down",&st) == -1) {
    if (errno != error_noent) {
      x = error_str(errno);
      buffer_puts(&b,"unable to stat down: ");
      buffer_puts(&b,x);
      return;
    }
    normallyup = 1;
  }

  if ((fntemp = svpath_make("/ok")) == 0) die_nomem();
  fd = open_write(fntemp);
  if (fd == -1) {
    if (errno == error_nodevice) {
      buffer_puts(&b,"supervise not running");
      return;
    }
    x = error_str(errno);
    buffer_puts(&b,"unable to open ");
    buffer_puts(&b,fntemp);
    buffer_puts(&b,": ");
    buffer_puts(&b,x);
    return;
  }
  close(fd);

  if ((fntemp = svpath_make("/status")) == 0) die_nomem();
  fd = open_read(fntemp);
  if (fd == -1) {
    x = error_str(errno);
    buffer_puts(&b,"unable to open ");
    buffer_puts(&b,fntemp);
    buffer_puts(&b,": ");
    buffer_puts(&b,x);
    return;
  }
  r = buffer_unixread(fd,status,sizeof status);
  close(fd);
  if (r < 18) {
    if (r == -1)
      x = error_str(errno);
    else
      x = "bad format";
    buffer_puts(&b,"unable to read ");
    buffer_puts(&b,fntemp);
    buffer_puts(&b,": ");
    buffer_puts(&b,x);
    return;
  }
  showstatus(status,r);
  if (r >= 20+18) {
    buffer_puts(&b,"\n");
    buffer_puts(&b,dir);
    buffer_puts(&b," log: ");
    showstatus(status+20,r-20);
  }
}
예제 #8
0
파일: xmaze.c 프로젝트: forestbaker/jqian
void makemaze(void) {
    segments=0;
    h=0;
    x=6+((rand()%(width-10))&32766);
    y=6+((rand()%(height-10))&32766);
    ox=x;
    oy=y;
    t=flatness;
    d=1;
    m=0;
    px[m]=x;
    py[m]=y;
    m++;
    start=time(0);
    for(i=0; i<chldmax; i++) {
        chldd[i]=-1;
    }
    while(m>=0) {
        for(i=0; i<chldmax; i++) {
            if(chldd[i]!=-1) {
                xx1=chldx[i]+sx[chldd[i]];
                yy1=chldy[i]+sy[chldd[i]];
                if(ppoint(xx1,yy1)==bg) {
                    px[m]=chldx[i];
                    py[m]=chldy[i];
                    m++;
                    line(chldx[i],chldy[i],xx1,yy1,fg);
                    segments++;
                    chldx[i]=xx1;
                    chldy[i]=yy1;
                    if((rand()%(flatness+1))==0) chldd[i]=rand()%4;
                } else {
                    c=0;
                    for(j=0; j<4; j++) {
                        if(ppoint(chldx[i]+sx[j],chldy[i]+sy[j])==bg) c++;
                    }
                    if(c==0) {
                        chldd[i]=-1;
                    } else {
                        chldd[i]=rand()%4;
                    }
                }
            }
        }
        if(statusline) {
            sprintf(status," %d %%%d  ",segments,segments*100/targetsegments);
            showstatus(1);
        }
        c=0;
        for(i=0; i<4; i++) {
            r=ppoint(x+sx[i],y+sy[i]);
            if(r==bg) {
                n[c]=i;
                c++;
            }
        }
        if(c==0) {
            x=px[m-1];
            y=py[m-1];
            m--;
            ox=x;
            oy=y;
        } else {
            if(delay) if (button==0) nap(delay);
            if(ppoint(x+sx[d],y+sy[d])!=bg) {
                d=n[rand()%c];
                while(c) {
                    for(i=0; i<chldmax; i++) {
                        if(chldd[i]== -1) {
                            chldx[i]=x;
                            chldy[i]=y;
                            chldd[i]=rand()%4;
                            break;
                        }
                    }
                    c--;
                }
            } else {
                xx1=x;
                yy1=y;
                x=x+sx[d];
                y=y+sy[d];
                line(x,y,xx1,yy1,fg);
                px[m]=x;
                py[m]=y;
                m++;
                if(m>h) h=m;
                segments++;
                t--;
                if(t<0) {
                    t=(rand()%(flatness+1));
                    d=rand()%4;
                }
            }
        }
    }
    end=time(0);
    for(i=1; i<4; i++) {
        box(i,i,width-i-1,height-i-1,fg);
    }
    box(4,4,width-4,height-4,bg);
    pset(5,6,fg);
    line(width-2,height-6,width-6,height-6,fg);
    sprintf(status," T:%d D:%d S:%d",(int)(end-start),h,segments);
    showstatus(1);
}
예제 #9
0
파일: xmaze.c 프로젝트: forestbaker/jqian
void clearstatus(void) {
    strcpy(status,"                                                          ");
    showstatus(0);
    strcpy(status,"");
    showstatus(0);
}