Ejemplo n.º 1
0
/* display_mat: displays a Row x Col matrix Mat in the window Gid,
 * using a simple colour-coded representation (blue for Lowval, red for
 * Upval etc.) The window may be resized, moved or iconified.
 * The window is closed when <Esc> is pressed.
 */
void display_mat(long Gid, double **Mat, unsigned int Row, unsigned int Col, 
		    double Lowval, double Upval)
{
    Device Dev;
    short Val;
    
    plot_mat(Gid, Mat, Row, Col, Lowval, Upval);
    while(1)
    {
	do  /* read the event queue until empty */
	{
	    Dev=qread(&Val);
	    switch(Dev)
	    {
		case REDRAW:	/* redraw if necessary */
		case REDRAWICONIC:
		case WINFREEZE:
		case WINTHAW:
		    plot_mat(Gid, Mat, Row, Col, Lowval, Upval);
		break;
		
		case ESCKEY:	/* both close up shop */
		case WINQUIT:
		    winclose(Gid); return;
		break;
		
		default: break;
	    }
	} while (qtest());
    }	    /* while(1) */
}
Ejemplo n.º 2
0
void event_loop(void)
{
  int e,w,x,y;
  for (;;) {
    while (qtest()) {
      e = qread(&w, &x, &y);
      switch (e) {
      case KEY:
         key(x);
         break;
               
      case REDRAW:
      case SHAPE:
        break;
        
      case WINSHUT:
      case HANGUP:
        return; 
      }
    }
    idle();
    draw();
    swapbuffers();
  }
}
Ejemplo n.º 3
0
int update_widgets(short val) {
    gl_slider *sl = firstslider;
    gl_button *bt = firstbutton;
    Int16 x, y;
    int flag = FALSE, sliderchange = FALSE;

#ifdef DEBUG
    printf("update_widgets called with val = %d\n", (int)val);
    if (qtest()) {
	int dev; 
	dev = qread(&x);
	printf("update_widgets: qtest() for x is true. dev = %d, val = %d\n",
	       dev, (int)x);
    } else {
	x = getvaluator(MOUSEX);
	printf("update_widgets: qtest() for x is FALSE!. x = %d\n", (int)x);
    }
    if (qtest()) {
	int dev; 
	dev = qread(&y);
	printf("update_widgets: qtest() for y is true. dev = %d, val = %d\n",
	       dev, (int)y);
    } else {
	y = getvaluator(MOUSEY);
	printf("update_widgets: qtest() for y is FALSE!. y = %d\n", (int)y);
    }
#else
    if (qtest()) qread(&x); else x = getvaluator(MOUSEX);
    if (qtest()) qread(&y); else y = getvaluator(MOUSEY);
#endif
    if (val == 0) return(FALSE);
       
    while (sl != NULL && !flag) {
	switch (updateslider(x, y, sl)) {
	  case -1:    sliderchange = TRUE; break;
	  case FALSE: flag = FALSE;        break;
	  default:    flag = TRUE;         break;
	}
	sl = sl->nextp;
    }

    while (bt != NULL && !flag) {
	flag = updatebutton(x, y, bt);
	bt = bt->nextp;
    }
    return(flag||sliderchange);
}
Ejemplo n.º 4
0
static void build_pict_list(PlayState *ps, char *first, int totframes, int fstep, int fontid)
{
	char *mem, filepath[FILE_MAX];
//	short val;
	PlayAnimPict *picture = NULL;
	struct ImBuf *ibuf = NULL;
	char str[32 + FILE_MAX];
	struct anim *anim;

	if (IMB_isanim(first)) {
		/* OCIO_TODO: support different input color space */
		anim = IMB_open_anim(first, IB_rect, 0, NULL);
		if (anim) {
			int pic;
			ibuf = IMB_anim_absolute(anim, 0, IMB_TC_NONE, IMB_PROXY_NONE);
			if (ibuf) {
				playanim_toscreen(ps, NULL, ibuf, fontid, fstep);
				IMB_freeImBuf(ibuf);
			}

			for (pic = 0; pic < IMB_anim_get_duration(anim, IMB_TC_NONE); pic++) {
				picture = (PlayAnimPict *)MEM_callocN(sizeof(PlayAnimPict), "Pict");
				picture->anim = anim;
				picture->frame = pic;
				picture->IB_flags = IB_rect;
				BLI_snprintf(str, sizeof(str), "%s : %4.d", first, pic + 1);
				picture->name = strdup(str);
				BLI_addtail(&picsbase, picture);
			}
		}
		else {
			printf("couldn't open anim %s\n", first);
		}
	}
	else {
		int count = 0;

		BLI_strncpy(filepath, first, sizeof(filepath));

		pupdate_time();
		ptottime = 1.0;

		/* O_DIRECT
		 *
		 * If set, all reads and writes on the resulting file descriptor will
		 * be performed directly to or from the user program buffer, provided
		 * appropriate size and alignment restrictions are met.  Refer to the
		 * F_SETFL and F_DIOINFO commands in the fcntl(2) manual entry for
		 * information about how to determine the alignment constraints.
		 * O_DIRECT is a Silicon Graphics extension and is only supported on
		 * local EFS and XFS file systems.
		 */

		while (IMB_ispic(filepath) && totframes) {
			size_t size;
			int file;

			file = open(filepath, O_BINARY | O_RDONLY, 0);
			if (file < 0) {
				/* print errno? */
				return;
			}

			picture = (PlayAnimPict *)MEM_callocN(sizeof(PlayAnimPict), "picture");
			if (picture == NULL) {
				printf("Not enough memory for pict struct '%s'\n", filepath);
				close(file);
				return;
			}
			size = BLI_file_descriptor_size(file);

			if (size < 1) {
				close(file);
				MEM_freeN(picture);
				return;
			}

			picture->size = size;
			picture->IB_flags = IB_rect;

			if (fromdisk == FALSE) {
				mem = (char *)MEM_mallocN(size, "build pic list");
				if (mem == NULL) {
					printf("Couldn't get memory\n");
					close(file);
					MEM_freeN(picture);
					return;
				}

				if (read(file, mem, size) != size) {
					printf("Error while reading %s\n", filepath);
					close(file);
					MEM_freeN(picture);
					MEM_freeN(mem);
					return;
				}
			}
			else {
				mem = NULL;
			}

			picture->mem = mem;
			picture->name = strdup(filepath);
			close(file);
			BLI_addtail(&picsbase, picture);
			count++;

			pupdate_time();

			if (ptottime > 1.0) {
				/* OCIO_TODO: support different input color space */
				if (picture->mem) {
					ibuf = IMB_ibImageFromMemory((unsigned char *)picture->mem, picture->size,
					                             picture->IB_flags, NULL, picture->name);
				}
				else {
					ibuf = IMB_loadiffname(picture->name, picture->IB_flags, NULL);
				}
				if (ibuf) {
					playanim_toscreen(ps, picture, ibuf, fontid, fstep);
					IMB_freeImBuf(ibuf);
				}
				pupdate_time();
				ptottime = 0.0;
			}

			BLI_newname(filepath, +fstep);

#if 0 // XXX25
			while (qtest()) {
				switch (qreadN(&val)) {
					case ESCKEY:
						if (val) return;
						break;
				}
			}
#endif
			totframes--;
		}
	}
	return;
}
Ejemplo n.º 5
0
static int updatebutton(int x, int y, gl_button *bt) {
    Int32 xo, yo;
    Int16 xx, yy;
    Int32  oriwin = winget();
    int oldstate;

#ifdef DEBUG
    printf("updatebutton: button with label %s - ", bt->label);
#endif
    
    winset(bt->win);
    locate_button(bt);
    
    getorigin(&xo, &yo);
    x -= xo;
    y -= yo;
    if (x < bt->scx0 || y > bt->scy0 ||
	x > bt->scx1 ||	y < bt->scy1) {
	winset(oriwin);
	bt->changed = FALSE;
#ifdef DEBUG
	printf("x = %d y = %d, btscx0 = %d btscx1 = %d btscy0 = %d btscy1 = %d\n",
	       x, y, bt->scx0,  bt->scx1, bt->scy0,  bt->scy1);
	puts("click not inside - return(FALSE)");
#endif
	return(FALSE);
    }
    oldstate = *(bt->state);
    *(bt->state) = (bt->type == BUTTON)?TRUE:!oldstate;
    drawbutton(bt);
    
    while (qread(&xx) != LEFTMOUSE); /* wait for LEFTMOUSE release */

    if (qtest()) qread(&xx); else {
	xx = getvaluator(MOUSEX);      
	fprintf(stderr, 
		"updatebutton: This should not happen, tie() seems to fail.\n");
    }
    if (qtest()) qread(&yy); else {
	yy = getvaluator(MOUSEY);
	fprintf(stderr, 
		"updatebutton: This should not happen, tie() seems to fail.\n");
    }
    getorigin(&xo, &yo);
    x = xx - xo;
    y = yy - yo;

    if (!(bt->changed = !(
			  x < bt->scx0 || y > bt->scy0 ||
			  x > bt->scx1 || y < bt->scy1
			  )
	  )) *(bt->state) = oldstate;

    if (bt->type == BUTTON) {
	*(bt->state) = FALSE;
	usleep(50000);
    }
    drawbutton(bt);
    if (oriwin != bt->win) winset(oriwin);

    if (bt->callback != NULL && bt->changed) {
	bt->callback(bt, *(bt->state));
    }
#ifdef DEBUG
    printf("return(%s)\n", bt->changed?"true":"false");
#endif
    return(bt->changed);
}
Ejemplo n.º 6
0
static int updateslider(int x, int y, gl_slider *sl) {
    Int32 xo, yo;
    Int16 xx, yy;
    double orival;
    Int32  oriwin = winget();
    int dev;
    
    orival = sl->value;
    update_slider_value(sl);
    winset(sl->win);

    getorigin(&xo, &yo);
    x -= xo;
    y -= yo;

#ifdef DEBUG
    printf("updateslider: slider label %s - ", sl->buf);
#endif    
    locate_slider(sl);
    
    if (x < sl->scx0 || y > sl->scy0 ||
	x > sl->scx1 + sl->sc_thick  ||	y < sl->scy1) {
	winset(oriwin);
	if (orival != sl->value) {
	    /* This is used when the click is not for this slider, but
	       update_slider_value() has changed the value... */
	    if (sl->callback != NULL) sl->callback(sl, sl->value);
#ifdef DEBUG
	    puts("return(-1)");
#endif
	    return(-1);
	} else {
#ifdef DEBUG
	    puts("return(FALSE)");
#endif
	    return(FALSE);
	}
    }
	
    while (qtest() == 0 || (dev = qread(&xx)) != LEFTMOUSE) {
	/* getorigin(&xo, &yo); */
	setslider(getvaluator(MOUSEX) - xo, sl);
	usleep(100000);
    } 
#ifdef DEBUG
    printf("updateslider: got an event, dev = %d val = %d\n", dev, (int)xx);
    if (qtest()) {
	int dev; 
	dev = qread(&xx);
	printf("updateslider: qtest() for x is true. dev = %d, val = %d\n",
	       dev, (int)xx);
    } else {
	xx = getvaluator(MOUSEX);
	printf("updateslider: qtest() for x is FALSE!. x = %d\n", (int)xx);
    }
    if (qtest()) {
	int dev; 
	dev = qread(&yy);
	printf("updateslider: qtest() for y is true. dev = %d, val = %d\n",
	       dev, (int)yy);
    } else {
	yy = getvaluator(MOUSEY);
	printf("updateslider: qtest() for y is FALSE!. y = %d\n", (int)yy);
    }
    setslider((int)(xx-xo), sl);
#else
    if (qtest()) qread(&xx);
    if (qtest()) {
	qread(&yy);
	setslider((int)(xx-xo), sl);
    } else 
      fprintf(stderr, 
	      "updateslider: This should not happen, tie() seems to fail.\n");
#endif
    winset(oriwin);
    if (sl->value != orival) {
	if (sl->callback != NULL) sl->callback(sl, sl->value);
	return(TRUE);
#ifdef DEBUG
	puts("return(TRUE)");
#endif
    } else {
#ifdef DEBUG
	puts("return(FALSE)");
#endif
	return(FALSE);
    }
}
 void ExplanationsFixture::bqtest(QueryPtr q, Collection<int32_t> expDocNrs)
 {
     qtest(reqB(q), expDocNrs);
     qtest(optB(q), expDocNrs);
 }
 void ExplanationsFixture::qtest(const String& queryText, Collection<int32_t> expDocNrs)
 {
     qtest(makeQuery(queryText), expDocNrs);
 }
Ejemplo n.º 9
0
/*
OK w95
 */
void mainEventLoop() {

   short     sVal, sXCurrent, sYCurrent;
   long      lDevice;
	int		i=0;
	int 	state = FALSE;
    short attached = 1;
    short value;
    int dev;
    int pupval;

  // make_all();
	//init_menu();

   nCurrentDir = DIR_NONE;

   czclear(0x404040, getgdesc(GD_ZMAX));

   while (TRUE) {

      if (qtest()) {
         lDevice = qread(&sVal);

         switch (lDevice) {

			case INPUTCHANGE:
				#ifdef DOFF
					printf(" %d, %d, %d\n", Win_ids[0], Win_ids[1], sVal);
				#endif
				if ( sVal != 0 )
					Input_win = sVal;
				else
					Input_win = -1;
				break;

            case REDRAW:
				if ( sVal == Win_ids[1] && Win_ids[1] != -1 )
					vDrawHelpScene();
				else if ( sVal == Win_ids[0] )
				{
               		reshapeviewport();
               		getsize(&nWinWidth, &nWinHeight);
               		getorigin(&nXWinOrigin, &nYWinOrigin);
				}
               break;

            case RIGHTMOUSE:
               pupval = dopup(mainmenu);
               break;
  
			case SPACEKEY:
				state = TRUE;
				i++;
				if ( i == 4 )
					subEventLoop();
				break;

			case RKEY:
				if ( Last_Actions[FIRE] == TRUE )
					vEventLoop(&vDrawTitle);
				break;

         case QKEY:
				if ( Input_win == Win_ids[1] ) 
				{
					winclose(Input_win);
					Win_ids[1] != -1;
				}
				else if ( Input_win == Win_ids[0] )
				{
					winclose(Win_ids[0]);
					if ( Win_ids[1] != -1 )
						winclose(Win_ids[1]);
	               exit(0);
				}
               break;

            default:
               break;
         }
      }
		getdev(DR_NUM_BUT, Devs, Last_Actions);

	  	vDrawTitle(state);
   }
}
Ejemplo n.º 10
0
/*
 half OK w95
 */
void subEventLoop() 
{
   short     sVal, sXCurrent, sYCurrent;
   long      lDevice;
	float tmp;

   nCurrentDir = DIR_NONE;
   czclear(0x404040, getgdesc(GD_ZMAX));

   strcpy(Message, ReadyMesg);
   vDrawScene();
   qreset();
   while (TRUE) {

      if (qtest()) {
         lDevice = qread(&sVal);

         switch (lDevice)
			{

			case INPUTCHANGE:
				#ifdef DOFF
					printf(" %d, %d, %d\n", Win_ids[0], Win_ids[1], sVal);
				#endif
				if ( sVal != 0 )
					Input_win = sVal;
				else
					Input_win = -1;
				break;

            case REDRAW:
				if ( sVal == Win_ids[1] && Win_ids[1] != -1 )
					vDrawHelpScene();
				else if ( sVal == Win_ids[0] )
				{
					winset(Win_ids[0]);
               		reshapeviewport();
               		getsize(&nWinWidth, &nWinHeight);
               		getorigin(&nXWinOrigin, &nYWinOrigin);
					tmp = Speed;
					Speed = 0.0;
               		vDrawScene();
					Speed = tmp;
				}
            break;

         case RIGHTMOUSE:
               dopup(mainmenu);
               break;
  
			case SPACEKEY:
				if ( EMode == FALSE )
				{
					p1EventLoop();
					strcpy(Message, "");
				}
				if ( EMode == TRUE )    /* game over */
				{
					vDrawOverScene();
				}
				break;

			case RKEY:
				if ( Last_Actions[FIRE] == TRUE )
					vEventLoop((&vDrawScene));
				break;

         case QKEY:
				if ( Input_win == Win_ids[1] ) 
				{
					winclose(Input_win);
					Win_ids[1] != -1;
				}
				else if ( Input_win == Win_ids[0] )
				{
					winclose(Win_ids[0]);
					if ( Win_ids[1] != -1 )
						winclose(Win_ids[1]);
	               exit(0);
				}
				break;

             default:
               break;
         }
      }
	  else
		getdev(DR_NUM_BUT, Devs, Last_Actions);

   }
}
Ejemplo n.º 11
0
/*---------------------------------------------------------------------------
main play loop
---------------------------------------------------------------------------*/
void p1EventLoop() {

   short     sVal;
   long      lDevice;
   Matrix    mNewMat;
   int		 reset = TRUE, i;
	static OKMode = FALSE;

	PMode = TRUE;

    strcpy(Message, "");
    while (TRUE) 
	{

		if (qtest()) 
		{
    		lDevice = qread(&sVal);

        	switch (lDevice) 
			{

			case INPUTCHANGE:
				#ifdef DOFF
					printf(" %d, %d, %d\n", Win_ids[0], Win_ids[1], sVal);
				#endif
				if ( sVal != 0 )
					Input_win = sVal;
				else
					Input_win = -1;
				break;

            case REDRAW:
				if ( sVal == Win_ids[1] && Win_ids[1] != -1 )
					vDrawHelpScene();
				else if ( sVal == Win_ids[0] )
				{
					winset(Win_ids[0]);
               		reshapeviewport();
               		getsize(&nWinWidth, &nWinHeight);
               		getorigin(&nXWinOrigin, &nYWinOrigin);
/*
               		vDrawScene();
*/
				}
               break;

				case ESCKEY:
					if ( OKMode != TRUE)
						return;
					break;

            case QKEY:
				if ( Input_win == Win_ids[1] ) 
				{
					winclose(Input_win);
					Win_ids[1] != -1;
				}
				else if ( Input_win == Win_ids[0] )
				{
					winclose(Win_ids[0]);
					if ( Win_ids[1] != -1 )
						winclose(Win_ids[1]);
	               exit(0);
				}
                	break;
        	}
		}

		getdev(DR_NUM_BUT, Devs, Last_Actions);

		if ( Time == Time/REDRAW_RATE*REDRAW_RATE )
		{
			if ( Energy <= 0 )
			{
				EMode = TRUE;
				return;
			}
			else if ( Time >= END_TIME )
			{
				OKMode = TRUE;
				last_mesg();
			}
			else
				vDrawScene();
		}

		for ( i=0; i<DR_NUM_BUT; i++)
		{
			Last_Actions[i] = FALSE;
		}
		Time++;

	}
}
Ejemplo n.º 12
0
main()
{
        char    *p;
	float	tdir = TRANS;
	float	scal = 1.0 + SCAL;
	int	but, nplanes;
	int	x, y, i, n;
	short	val;
	int	bf = 1;
	int	fill = 1;

	prefsize(500L, 500L);

	vinit("mswin");
	winopen("lcube");

	unqdevice(INPUTCHANGE);
	qdevice(SKEY);
	qdevice(XKEY);
	qdevice(YKEY);
	qdevice(ZKEY);
	qdevice(EQUALKEY);
	qdevice(MINUSKEY);
	qdevice(ESCKEY);
	qdevice(QKEY);
	qdevice(FKEY);
	qdevice(BKEY);
	/* 
	 * Wait for REDRAW event ...
	 */
	while (qread(&val) != REDRAW)
		;
	

	window(-800.0, 800.0, -800.0, 800.0, -800.0, 800.0);
	lookat(0.0, 0.0, 1500.0, 0.0, 0.0, 0.0, 0);

	if ((nplanes = getplanes()) == 1)
		makecubes(0);

	makecubes(1);

	backface(1);
		
	doublebuffer();
	gconfig();

	/*
	 * Doublebuffer does a backbuffer(TRUE)....
	 */

	while(1) {
		x = 500 - (int)getvaluator(MOUSEX);
		y = 500 - (int)getvaluator(MOUSEY);
		x *= 3;
		y *= 3;
		pushmatrix();
			rotate(x, 'y');
			rotate(y, 'x');
			color(BLACK);
			clear();
			callobj((Object)3);
			if (nplanes == 1)
				callobj((Object)2);
		popmatrix();
		swapbuffers();

		if (qtest()) {
			but = qread(&val);
			but = qread(&val);	/* swallow up event */

			switch (but) {

			case SKEY:
				scale(scal, scal, scal);
				break;
			case XKEY:
				translate(tdir, 0.0, 0.0);
				break;
			case YKEY:
				translate(0.0, tdir, 0.0);
				break;
			case ZKEY:
				translate(0.0, 0.0, tdir);
				break;
			case MINUSKEY:
				tdir = -tdir;

				if (scal < 1.0)
					scal = 1.0 + SCAL;
				else
					scal = 1.0 - SCAL;

				break;
			case EQUALKEY:
				tdir = TRANS;
				break;
			case BKEY:
				bf = !bf;
				backface(bf);
				break;
			case FKEY:
				fill = !fill;
				if (fill)
					polymode(PYM_FILL);
				else
					polymode(PYM_LINE);
				break;
			case ESCKEY:
			case QKEY:
				gexit();
				exit(0);
			default:
				;
			}
		}
	}
}
Ejemplo n.º 13
0
main()
{
	int	i, itest,  dobackface, dofill, dodouble;
	char	buf[100];
	float	H;
	short	idata;
	int	xr, yr;

	vinit("mswin");
	winopen("piston");
	/* 
	 * Wait for REDRAW event ...
	 */
	while (qread(&idata) != REDRAW)
		;

	doublebuffer();

	gconfig();

	unqdevice(INPUTCHANGE);
	qdevice(QKEY);
	qdevice(FKEY);
	qdevice(BKEY);
	qdevice(ESCKEY);
        qdevice(REDRAW);

	makecyl();

	polymode(PYM_FILL);

	backface(1);
/*
 * set up a perspective projection with a field of view of
 * 40.0 degrees, aspect ratio of 1.0, near clipping plane 0.1,
 * and the far clipping plane at 1000.0.
 */
	perspective(400, 1.5, 0.1, 600.0);
	lookat(0.0, -6.0, 4., 0.0, 0.0, 0.0, 0);

/*
 * here we loop back here adnaseum until someone hits a key
 */
	xr = yr = 0;

 	while(1) {
		for (i = 0; i < 360; i += 5) {
			color(BLACK);
			clear();
			color(RED);
			H = 1.0 + cos(2.0 * 3.14159265*i / 180.0);

			yr = 500 - (int)getvaluator(MOUSEY);
			xr = 500 - (int)getvaluator(MOUSEX);
			yr = 500 - (int)getvaluator(MOUSEY);
			xr *= 3;
			yr *= 3;

			pushmatrix();
				rotate(xr, 'x');
				rotate(yr, 'y');
				piston(H);
			popmatrix();

			if (dodouble)
				swapbuffers();

			if (qtest()) {
				itest = qread(&idata);
				itest = qread(&idata); /* Zap Up event */
				if (itest == BKEY) {
					dobackface = !dobackface;
					backface(dobackface);
				} else if (itest == FKEY) {
					dofill = !dofill;
					if (dofill)
						polymode(PYM_FILL);
					else
						polymode(PYM_LINE);
				} else if(itest == QKEY || itest == ESCKEY) {
					 gexit();
					 exit(0);
				}

			}
		}
	}
}
Ejemplo n.º 14
0
void quest()
{
	
	int i,j;
	int pq_test;
	int flag;
	int pq_start;

	int direct, step,bricks;
	while(1)
	{
		direc_num=0;
		for(i=0;i<n;i++)
				for(j=0;j<n;j++)
					map[i][j]=0;
		pq_start = rand()%(n*n);
		pq_now = pq_start;
		pq_test=qtest();
		flag=1;
		//printf("in while\n");
		while(pq_test!=0)
		{
			//printf("in while while pq_test = %d\n",pq_test);
			if(pq_test%2 == 1)
			{
				direc_stack[direc_num]=0;
				direc_num++;
			}
			pq_test/=2;
			if(pq_test%2 == 1)
			{
				direc_stack[direc_num]=1;
				direc_num++;
			}
			pq_test/=2;
			if(pq_test%2 == 1)
			{
				direc_stack[direc_num]=2;
				direc_num++;
			}
			pq_test/=2;
			if(pq_test%2 == 1)
			{
				direc_stack[direc_num]=3;
				direc_num++;
			}
			//for(i=0;i<direc_num;i++)
			//	printf("%d ",direc_stack[i]);
		//	printf("\n");
			direct = direc_stack[rand()%direc_num];
			direc_num = 0;
			
			int temp = count(direct);
			//printf("temp = %d\n",temp);
			if(temp !=0)
				step=rand()%(temp)+1;
			else break;
			//printf("direct = %d, temp = %d, step = %d, pq_now = %d\n",direct,temp,step,pq_now);
			switch(direct)
			{
				case 0:
					for(i=0;i<step;i++)
						map[pq_now/n][pq_now%n-i]=1;
						if(pq_now%n-step-1>=0 && map[pq_now/n][pq_now%n-step-1]==0)
							map[pq_now/n][pq_now%n-step-1]=-1;
						pq_now=pq_now-step;

					break;
				case 1:
					for(i=0;i<step;i++)
						map[pq_now/n-i][pq_now%n]=1;
						if(pq_now/n-step-1>=0 && map[pq_now/n-step-1][pq_now%n]==0)
							map[pq_now/n-step-1][pq_now%n]=-1;
						pq_now=(pq_now/n-step)*n+pq_now%n;
					break;
				case 2:
					for(i=0;i<step;i++)
						map[pq_now/n][pq_now%n+i]=1;
						if(pq_now%n+step+1<=n-1 && map[pq_now/n][pq_now%n+step+1]==0)
							map[pq_now/n][pq_now%n+step+1]=-1;
						pq_now+=step;
					break;
				case 3:
					for(i=0;i<step;i++)
						map[pq_now/n+i][pq_now%n]=1;
					if(pq_now%n+step+1<=n-1 && map[pq_now/n+step+1][pq_now%n]==0)
							map[pq_now/n+step+1][pq_now%n]=-1;
					pq_now=(pq_now/n+step)*n+pq_now%n;
					break;
			}
		/*	for(i=0;i<n;i++)
		{
			for(j=0;j<n;j++)
				printf("%3d ",map[i][j]);
			printf("\n");
		}
		printf("\n");*/
		//printf("pq_now= %d\n",pq_now);
			pq_test=qtest();
			/*if(pq_test==0&&flag==1)
			{
				pq_now=pq_start;
				flag=0;
				pq_test=qtest();

			}*/
		}
		map[pq_now/n][pq_now%n] = 1;
		//printf("in while brick\n");
		bricks=0;
		for(i=0;i<n;i++)
				{
					for(j=0;j<n;j++)
					{
						if(map[i][j]==1)
							map[i][j] = 0;
						else
						{
							map[i][j] = 1;
							bricks++;
						}
							
					}
					
				}
			//printf("bricks = %d\n", bricks);
		int tmp,fflag=0;
		for(i=0;i<n;i++)
			{
				tmp =0;
				for(j=0;j<n;j++)
					if(map[i][j]==1)tmp++;
				if(tmp>n-1)fflag=1;

			}
			for(j=0;j<n;j++)
			{
				tmp =0;
				for(i=0;i<n;i++)
					if(map[i][j]==1)tmp++;
				if(tmp>n-1)fflag=1;
			}


		if(bricks>0 && bricks <0.3*n*n && fflag == 0)break;
		/*for(i=0;i<n;i++)
		{
			for(j=0;j<n;j++)
				printf("%d ",map[i][j]);
			printf("\n");
		}
		printf("\n");*/
	}



}