Example #1
0
/* generate pawn captures and promotions */
void genattacksp(int f, int r, int c)
{
    int forward = dir(c);
    square loc = SQ(f,r);

    r += forward;

    if (f<7)
    {
        chesspiece p = getpiece(f+1, r);
        if (p&&chesspiececolor(p)!=c)
            pushmove(MV(loc, SQ(f+1, r)));
    }

    if (f>0)
    {
        chesspiece p = getpiece(f-1,r);
        if (p&&chesspiececolor(p)!=c)
            pushmove(MV(loc, SQ(f-1, r)));
    }

    if (c==WHITE)
    {
        if ((r==6)&&emptyp(f,r))
            pushmove(MV(loc, SQ(f,r)));
    }
    else
    {
        if ((r==1)&&emptyp(f,r))
            pushmove(MV(loc, SQ(f,r)));
    }

    /* get en passante */
    if (doublepushp())
    {
        square start;
        square end;
        move m;

        m = lastmove();

        start = FR(m);
        end = TO(m);

        r -= forward;		/* restore to original r */
        if (R(end) == r)
        {
            if (((f+1) == F(start))||
                    ((f-1) == F(start)))
                pushmove(MV(loc, SQ(F(start),forward+r)));
        }
    }
}
Example #2
0
void getmovesp(int f, int r, int c)
{
    int forward = dir(c);
    square loc = SQ(f,r);
    
    r += forward;

    // captures
    if ((f<7) && (oppenentp (f+1, r, c)))
    {
	push_pawn_move(loc, SQ(1+f, r));
    }

    if ((f>0) && (oppenentp (f-1, r, c)))
    {
	push_pawn_move(loc, SQ(f-1, r));
    }
    
    if (emptyp(f,r))
    {
	int startrank = ((c == WHITE) ? 2 : 5);

	push_pawn_move(loc, SQ(f,r));
	
	/* can go two on first move */
	if ((r == startrank)&&(emptyp(f,r+forward)))
	    pushmove(MV(loc, SQ(f,r+forward)));
    }

    // if last move was double push we can possibly do an en passante
    if (doublepushp())
    {
	square start;
	square end;
	move m;

	m = lastmove();
	
	start = FR(m);
	end = TO(m);
	
	r -= forward;		/* restore to original r */
	if (R(end) == r)
	{
	    if (((f+1) == F(start))||
		((f-1) == F(start)))
		pushmove(MV(loc, SQ(F(start),forward+r)));
	}
    }
}
Example #3
0
int length(pair *list) {
  pair *n = list;
  int l = 0;
  while (!emptyp(n)) {
    l += 1;
    n = cdr(n);
  }
  return l;
}
Example #4
0
pair *reverse(pair *list) {
  pair *l = list;
  pair *new_list = NULL;
  
  while (!emptyp(l)) {
    new_list = cons(l->car, new_list);
    l = l->cdr;
  }
  return new_list;
}
Example #5
0
File: glfw.c Project: plops/glfw
char*
pop() // obtain next pointer from circular buffer
{
  if(emptyp()){
    //intf("error buffer is empty\n");
    return 0;
  }

  char*ret=circbuf[circread];
  printf("cread=%d cmd=%s\n",circread,ret);
  inc(&circread);

  return ret;
}
Example #6
0
void main() {
  // Test construction of a pair
  
  // Test car
  pair *a = cons(42, NULL);
  printf("\nExpected: 42 ==> %d\n", car(a));
  
  // Test cdr
  pair *b = cons(42, cons(43, NULL));
  pair *c = cdr(b);
  printf("\nExpected: 43 ==> %d\n", car(c));
  
  // Test empty
  pair *d = NULL;
  printf("\nExpected: 1 ==> %d\n", emptyp(d));
  
  // Test length
  pair *e = cons(42, cons(43, cons(44, NULL)));
  printf("\nExpected: 3 ==> %d\n", length(e));
  
  // Test list
  printf("\nExpected: (1 2 3) ==> ");
  print_list(list(1, 2, 3, NULL));
  
  // Test make_list
  printf("\nExpected: (42 42 42) ==> ");
  print_list(make_list(3, 42));
  
  // Test iota
  printf("\nExpected: (0 1 2) ==> ");
  print_list(iota(3));
  
  // Test reverse
  pair * g = list(1, 2, 3, 4, 5, NULL);
  printf("\nExpected: (1 2 3 4 5) ==> ");
  print_list(g);
  printf("\nExpected: (5 4 3 2 1) ==> ");
  print_list(reverse(g));

  // Test print_list
  printf("\nExpected: (1 2 3) ==> ");
  print_list(list(1, 2, 3, NULL));

  // Test drop
  printf("\nExpected: (4 5) ==> ");
  print_list(drop(g, 3));
  
  // Test take
  printf("\nExpected: (1 2 3) ==> ");
  print_list(take(g, 3));
  
  // Test list_ref
  printf("\nExpected: 4 ==> %d\n", list_ref(g, 3));

  // Test map
  pair *h = map(g, dub);
  printf("\nExpected: (2 4 6 8 10) ==> ");
  print_list(h);

  // Test filter
  pair *i = filter(g, even);
  printf("\nExpected: (2 4) ==> ");
  print_list(i);
  
  // Test member
  printf("\nExpected: (3 4 5) ==> ");
  print_list(member(g, 3));
  
  
}
Example #7
0
File: glfw.c Project: plops/glfw
// Main program. Open a window. Continuously read commands from the
// command line interface and draw frames with 60Hz onto the
// screen. Commands for multiple frames can be cached within a ring
// buffer, so that a consistent frame rate can be maintained even if
// the control program doesn't respond within 16ms. The control
// program is written in Common Lisp and a 16ms time granularity cannot
// always be maintained, due to the time a garbage collection may
// take.
int
main(int argc,char**argv)
{
  
  // make sure frame rate update cycle is phase locked to vertical
  // refresh of screen. On Nvidia hardware this can be done by setting
  // the following environment variable.
  setenv("__GL_SYNC_TO_VBLANK","1",1); 
  
  if(!glfwInit())
    exit(EXIT_FAILURE);
  int width=1280,height=1024;

  if(argc==3){
    width=atoi(argv[1]);
    height=atoi(argv[2]);
  }
   
  if(!glfwOpenWindow(width,height,8,8,8,
		     0,0,0,
		     GLFW_WINDOW
		     )){
    glfwTerminate();
    exit(EXIT_FAILURE);
  }
  printf("lcos started %dx%d\n",width,height);
  fflush(stdout);

  glfwSetWindowTitle("LCoS");
  //glfwSetWindowPos(-8,-31);

  // use glfw method to sync to vertical refresh
  glfwSwapInterval(1);

  glfwSetKeyCallback(keyhandler);
  init_matrix();
  
  glMatrixMode(GL_PROJECTION);
  glOrtho(0,1280,1024,0,-1,1);
  glMatrixMode(GL_MODELVIEW);
  
  while(running){
    while(check_stdin()>0){
      char*s=malloc(CMDLEN);
      char*line=fgets(s,CMDLEN,stdin);
      if(line!=s)
	printf("fgets error\n");
      parse_line(line);
    }
    
    glClear(GL_COLOR_BUFFER_BIT);
    glLoadMatrixf(m);
    
    frame_count++;
    
    // run all commands which have been stored in the queue
    while(!emptyp()){
      char*cmd=pop();
      if(0==strncmp(cmd,"swap",4)){
	struct timeval tv;
	gettimeofday(&tv,0);
	printf("q swap frame-count=%d sec=%lu usec=%lu\n",
	       frame_count,tv.tv_sec,tv.tv_usec);
	free(cmd);
	goto nextframe;
      }
      parse_line(cmd);
      printf("q cread=%5d cwrite=%5d cmd=%s\n",circread,circwrite,cmd);
      fflush(stdout);
      free(cmd);
    }
  nextframe:
    if(show_calibration_stripes){
      float v = 100+20*(frame_count%10);
      glRectf(v,0,v+2,400);    
    }
    
    glfwSleep(1./72);
    glfwSwapBuffers();
  }
  
  glfwCloseWindow();

  glfwTerminate();
  exit(EXIT_SUCCESS);
}