예제 #1
0
파일: hanoi.c 프로젝트: AmitKrJoshi/LDP
void solve_hanoi(peg *p_my_pegs, int n_discs, int src, int aux, int dst)
{	if(n_discs == 0)
		return;
	solve_hanoi(p_my_pegs, n_discs - 1, src, dst, aux);
	move_disc(p_my_pegs, store_n_discs, src, dst);
	show_pegs(stdscr, p_my_pegs, store_n_discs);
	check_usr_response(p_my_pegs, store_n_discs);
	solve_hanoi(p_my_pegs, n_discs - 1, aux, src, dst);
}
예제 #2
0
  void move_discs(Pin &orig, Pin &dest, int num_discs) {
    // Stop case of recorrence
    if (num_discs == 1) {
      move_disc(orig, dest);
      return;
    }

    // Discover intermediate pin
    if (orig.pos() != PIN_A && dest.pos() != PIN_A) {
      move_discs(orig, p_a, num_discs - 1);
      move_disc(orig, dest);
      move_discs(p_a, dest, num_discs - 1);
    } else if (orig.pos() != PIN_B && dest.pos() != PIN_B) {
      move_discs(orig, p_b, num_discs - 1);
      move_disc(orig, dest);
      move_discs(p_b, dest, num_discs - 1);
    } else {
      move_discs(orig, p_c, num_discs - 1);
      move_disc(orig, dest);
      move_discs(p_c, dest, num_discs - 1);
    }
  }
예제 #3
0
static unsigned long
intermomentary_draw (Display *dpy, Window window, void *closure)
{
  struct state *st = (struct state *) closure;
  int tempx;

  if ((st->f->cycles % 10) == 0) {
    /* Restart if the window size changes */
    XGetWindowAttributes(dpy, window, &st->xgwa);

    if (st->f->height != st->xgwa.height || st->f->width != st->xgwa.width) {
      st->f->height = st->xgwa.height;
      st->f->width = st->xgwa.width;
      st->f->visdepth = st->xgwa.depth;

      build_img(dpy, window, st->f);
    }
  }

  blank_img(dpy, st->f->off_map, st->xgwa, st->fgc, st->f);
  for (tempx = 0; tempx < st->f->num; tempx++) {
    move_disc(st->f, tempx);
    render_disc(st, st->f->off_map, st->fgc, st->f, tempx);
  }

#if 0
  XSetFillStyle(dpy, st->copygc, FillTiled);
  XSetTile(dpy, st->copygc, st->f->off_map);
  XFillRectangle(dpy, window, st->copygc, 0, 0, st->f->width, st->f->height);
#else
  if (st->f->off_map != window)
    XCopyArea (dpy, st->f->off_map, window, st->copygc, 0, 0, 
               st->f->width, st->f->height, 0, 0);

#endif

  st->f->cycles++;

  return st->draw_delay;
}