glut/progs/examples/glpuzzle.c
/* Checks if a piece can move */
Checks if a piece can move
Checks if a piece can move
int
canmove(Config pieces, int x, int y, int dir, Config newpieces)
{
  int xadd, yadd;
  xadd = xadds[dir];
  yadd = yadds[dir];
  if (x + xadd < 0 || x + xadd >= WIDTH ||
    y + yadd < 0 || y + yadd >= HEIGHT)
    return 0;
  if (pieces[y + yadd][x + xadd] == pieces[y][x]) {
    return canmove(pieces, x + xadd, y + yadd, dir, newpieces);
  }
  if (pieces[y + yadd][x + xadd] != 0)
    return 0;
  return canmove0(pieces, x + xadd, y + yadd, (dir + 2) % 4, newpieces);
}
int canmove ( Config pieces , int x , int y , int dir , Config newpieces ) { int xadd , yadd ; xadd = xadds [ dir ] ; yadd = yadds [ dir ] ; if ( x + xadd < 0 || x + xadd >= WIDTH || y + yadd < 0 || y + yadd >= HEIGHT ) return 0 ; if ( pieces [ y + yadd ] [ x + xadd ] == pieces [ y ] [ x ] ) { return canmove ( pieces , x + xadd , y + yadd , dir , newpieces ) ; } if ( pieces [ y + yadd ] [ x + xadd ] != 0 ) return 0 ; return canmove0 ( pieces , x + xadd , y + yadd , ( dir + 2 ) % 4 , newpieces ) ; }
Checks if a piece can move
Checks if a piece can move