Ejemplo n.º 1
0
bool snake_valid( cube_t *cube, position_t *position, char *binary_string) {
  int i;
  position_t * position_;
  bool valid_snake;

  printf( "%s\n", binary_string);
  print_snake( position);
  if( strlen( binary_string) == 1) {
    return true;
  }

  if( binary_string[0] == '0') {
    position_ = position_append( position, position->d);
    if( position_valid( cube, position_)) {
      valid_snake = snake_valid( cube, position_, binary_string + 1);
      free_position( position_);
      return valid_snake;
    } else {
      free_position( position_);
      return false;
    }
  } else {
    for( i = 1; i <= 3; i++) {
      if( abs( position->d ) != abs( i)) {
        position_ = position_append( position, i );
        if( position_valid( cube, position_)){
          valid_snake = snake_valid( cube, position_, binary_string + 1);
          free_position(position_);
          if( valid_snake) return true;
        }
      }
    }
    for( i = -1; i >= -3; i--) {
      if( abs( position->d ) != abs( i)) {
        position_ = position_append( position, i );
        if( position_valid( cube, position_)){
          valid_snake = snake_valid( cube, position_, binary_string + 1);
          free_position(position_);
          if( valid_snake) return true;
        }
      }
    }
    return false;
  }
}
Ejemplo n.º 2
0
void handle_destroy_event(XEvent *e)
{
	free_position(e->xdestroywindow.window);
	XDestroyWindow(display, e->xdestroywindow.window);
}