glut/progs/examples/glpuzzle.c
/* Checks if a space can move */
Checks if a space can move
Checks if a space can move
int
canmove0(Config pieces, int x, int y, int dir, Config newpieces)
{
  char piece;
  int xadd, yadd;
  int l, m;
  xadd = xadds[dir];
  yadd = yadds[dir];
  if (x + xadd < 0 || x + xadd >= WIDTH ||
    y + yadd < 0 || y + yadd >= HEIGHT)
    return 0;
  piece = pieces[y + yadd][x + xadd];
  if (piece == 0)
    return 0;
  memcpy(newpieces, pieces, HEIGHT * WIDTH);
  for (l = 0; l < WIDTH; l++) {
    for (m = 0; m < HEIGHT; m++) {
      if (newpieces[m][l] == piece)
        newpieces[m][l] = 0;
    }
  }
  xadd = -xadd;
  yadd = -yadd;
  for (l = 0; l < WIDTH; l++) {
    for (m = 0; m < HEIGHT; m++) {
      if (pieces[m][l] == piece) {
        int newx, newy;
        newx = l + xadd;
        newy = m + yadd;
        if (newx < 0 || newx >= WIDTH ||
          newy < 0 || newy >= HEIGHT)
          return 0;
        if (newpieces[newy][newx] != 0)
          return 0;
        newpieces[newy][newx] = piece;
      }
    }
  }
  return 1;
}
int canmove0 ( Config pieces , int x , int y , int dir , Config newpieces ) { char piece ; int xadd , yadd ; int l , m ; xadd = xadds [ dir ] ; yadd = yadds [ dir ] ; if ( x + xadd < 0 || x + xadd >= WIDTH || y + yadd < 0 || y + yadd >= HEIGHT ) return 0 ; piece = pieces [ y + yadd ] [ x + xadd ] ; if ( piece == 0 ) return 0 ; memcpy ( newpieces , pieces , HEIGHT * WIDTH ) ; for ( l = 0 ; l < WIDTH ; l ++ ) { for ( m = 0 ; m < HEIGHT ; m ++ ) { if ( newpieces [ m ] [ l ] == piece ) newpieces [ m ] [ l ] = 0 ; } } xadd = - xadd ; yadd = - yadd ; for ( l = 0 ; l < WIDTH ; l ++ ) { for ( m = 0 ; m < HEIGHT ; m ++ ) { if ( pieces [ m ] [ l ] == piece ) { int newx , newy ; newx = l + xadd ; newy = m + yadd ; if ( newx < 0 || newx >= WIDTH || newy < 0 || newy >= HEIGHT ) return 0 ; if ( newpieces [ newy ] [ newx ] != 0 ) return 0 ; newpieces [ newy ] [ newx ] = piece ; } } } return 1 ; }
Checks if a space can move
Checks if a space can move