int main(void) {
  cell_t *head_cell = create_cell(0);
  for(int i = 1; i < 11; i++) {
    append_cell(head_cell, create_cell(i));
  }
  printCells(head_cell);
  insert_nth(head_cell, create_cell(100), 3);
  printCells(head_cell);
  return 0;
}
Exemple #2
0
static inline expr *eval_varargs(scope *scope, expr *e) {
  assert(islist(e));
  if (e == NULL)
    return NULL;
  else
    return create_cell(eval(scope, e->head), eval_varargs(scope, e->tail));
}
Exemple #3
0
void create_groups()
{
  Cell * cell = create_cell();
  unitize_cell( cell );
  group_units( cell );
  free( cell->units );
  free( cell );
  //update_texture();
}
Exemple #4
0
sudoku_board create_board(int side){
	int i = 0, j = 0;
	sudoku_board board = (sudoku_board) calloc(side, sizeof(cell_ptr));
	
	for(i=0; i<side; i++){
		board[i] = (cell_ptr) calloc(side, sizeof(struct cell));
		for (j=0; j<side;j++){
			create_cell(&board[i][j], side);
		}
	}
	return board;
}
Exemple #5
0
/*!
	Creates a new cell.

	\param internal is true if the cell is an internal cell, false otherwise
*/
long Patch::create_cell(bool internal, ElementInfo::Type type)
{
	long id;
	if (m_unusedCellIds.empty()) {
		id = m_cells.size();
	} else {
		id = m_unusedCellIds.front();
		m_unusedCellIds.pop_front();
	}

	return create_cell(id, internal, type);
}
/*
 * Method to create a new cell from the two lenses that
 * we are trying to put into the same cell
 */
void add_lens(cell ** tree, lens **olens, lens **nlens, int pos) {
    int n_lens_pos = get_lens_pos(*tree, *nlens);                   /* The quadrant of the lens we want to insert*/
    int o_lens_pos = get_lens_pos(*tree, *olens); /* The quadrant of the lens that already exists*/

    if(!(n_lens_pos == o_lens_pos)) {
        (*tree)->lenses[o_lens_pos] = *olens;
        (*tree)->lenses[n_lens_pos] = *nlens;
    }
    else {
        /* if we get here the positions are the same for the lenses, but maybe different from the previous position obtained*/
        int new_pos = n_lens_pos;
        cell *tmp = create_cell(tree, *olens, *nlens, new_pos);
        add_lens(&tmp, olens, nlens, new_pos);
        (*tree)->desc[new_pos] = tmp;
        (*tree)->lenses[new_pos] = NULL;
    }
}
Exemple #7
0
int		fill_resource_with_cell(char *line, t_resources *resources, int lf)
{
	char		**split;
	int			i;
	t_cell		*cell;

	split = ft_strsplit(line, ' ');
	i = 0;
	while (split && split[i])
		i++;
	if (i != 3)
	{
		free_dbl_tab(split);
		return (-1);
	}
	if (ft_strchr(split[0], '-'))
		return (-1);
	if (!str_is_an_int_valid(split[1]) || !str_is_an_int_valid(split[2]))
		return (-1);
	cell = create_cell(split[0], ft_atoi(split[1]), ft_atoi(split[2]));
	free_dbl_tab(split);
	return (add_cell_to_resources(cell, resources, lf));
}
Exemple #8
0
PointList* next_move(Board* board, enum Direction dir) {
  PointList* snake = board->snake;
  int new_x = snake->x;
  int new_y = snake->y;
  switch(dir) {
    case UP:
      new_y = snake->y - 1;
      break;
    case DOWN:
      new_y = snake->y + 1;
      break;
    case LEFT:
      new_x = snake->x - 1;
      break;
    case RIGHT:
      new_x = snake->x + 1;
      break;
  }
  if (new_x < 0 || new_y < 0 || new_x >= board->xmax || new_y >= board->ymax) {
    return NULL;
  } else {
    return create_cell(new_x, new_y);
  }
}
Exemple #9
0
PointList* create_snake() {
  PointList* a = create_cell(2,3);
  PointList* b = create_cell(2,2);
  a->next = b;
  return a;
}
Exemple #10
0
PointList* create_random_cell(int xmax, int ymax) {
  return create_cell(rand() % xmax, rand() % ymax);
}
//
// incline is TABLE, shave - enable shaving
// not use for back rotating
//
cell * erect_cell_table (cell *c, int16_t tab_angle[], int16_t shave, Bool cutting)
{
int16_t     dx=c->w, dy=c->h, le, ri               ;
int16_t     lminx, lminsx, lminy, lminsy           ;
MN      *sh_mn                                 ;
cell    *sh_cell[MAX_CELLS_IN_LIST+1],res_cell ;
puchar   raster                                 ;
uchar    sh_raster[1024]                        ;
int16_t     i, d_x, n, inc                         ;
cell    *cret = c                              ;

if( !c->env     )              return c;
le = ri = 0;
for (i=0; i<dy; i++)
  tab_angle[i] >>= 2;
inc = (tab_angle[0] != tab_angle[dy-1]);
if( shave || inc)
  {
  raster = save_raster (c);
  le = diff_left_limit_rast(raster,dx,dy,tab_angle);
  d_x = shift_raster (raster, dy, dx, tab_angle,
        (int16_t)(MAX (tab_angle[0], tab_angle[dy-1])), sh_raster, 1);

  if( (sh_mn = c_locomp (sh_raster, (int16_t)bytlen(d_x), dy, 0, 0))==NULL )
    return NULL;

  for(i=0; sh_mn && i<MAX_CELLS_IN_LIST; i++, sh_mn = sh_mn->mnnext)
    {
    if( (sh_cell[i]=create_cell (sh_mn, c, c->bdiff, (char)(c->difflg&0xf0)))==NULL )
      return NULL;
    sh_cell[i]->stick_inc = NO_INCLINE; // rotate disabled
    }
  sh_cell[i] = NULL;
  n = i;

  for(lminx=lminy=c->w,i=0;i<n;i++)
    {
    if( lminx>sh_cell[i]->env->left )
      lminx=sh_cell[i]->env->left;
    if( lminy>sh_cell[i]->env->upper )
      lminy=sh_cell[i]->env->upper;
    }

  for(i=0;i<n;i++)
    pimpleshave( sh_cell[i], shave, inc );

  for(lminsx=lminsy=c->w,i=0;i<n;i++)
    {
    if( lminsx>sh_cell[i]->env->left )
      lminsx=sh_cell[i]->env->left;
    if( lminsy>sh_cell[i]->env->upper )
      lminsy=sh_cell[i]->env->upper;
    }

  memcpy( &res_cell, c , sizeof(cell));
  compose_cell(n, sh_cell, &res_cell);

  if( n<2 )
    c->cg_flag &= 0xFB         ; // clear compose flag for normal comp
  else
    c->cg_flag |= c_cg_comp    ; // set composed flag
  c->env        = res_cell.env ;
  c->env->upper = c->r_row     ;
  c->env->left  = c->r_col     ;
  if( n>1 || c->dens==255 )
    c->dens     = 255          ; // undef
  else
    {
    int32_t dens   = calc_dens(c);
    c->dens     = (dens*32)/(res_cell.w*res_cell.h);
    }
  c->w          = res_cell.w   ;
  c->h          = res_cell.h   ;
  c->recsource  = 0            ; // artifact
  if( lminsx>lminx )
    {
    lminsx -= lminx;
    c->env->left += lminsx;
    c->col       += lminsx;
    c->r_col     += lminsx;
    }
  if( lminsy>lminy )
    {
    lminsy -= lminy;
    c->env->upper += lminsy;
    c->row        += lminsy;
    c->r_row      += lminsy;
    }
  if( c->flg!=c_f_dust && c->w<MAX_DUST_WIDTH && c->h<MAX_DUST_HEIGHT )
    {
    cell *wc;
    c->flg   = c_f_dust;
    c->nvers = 0;
    c->vers[0].let=c->vers[0].prob=0;
    (wc=c->prevl)->nextl = c->nextl;
    c->nextl->prevl      = c->prevl;
    err_pnlet(c);
    }
  if( le<0 && c->col+le>=0 && c->r_col+le>=0 && c->env->left+le>=0 )
    {
    c->env->left += le;
    c->col       += le;
    c->r_col     += le;
    }
  c->pos_inc=erect_rot;
  if( n>1 && cutting)
    cret = convert_to_cells(c);
  }

return cret;
}
//
// incline is VALUE, shave - enable shaving
// use for back rotating too
//
cell * erect_cell_value (cell *c, int16_t inc, int16_t shave, Bool cutting)
{
int16_t     dx=c->w, dy=c->h, le, ri, sinc=inc     ;
int16_t     lminx, lminsx, lminy, lminsy           ;
MN      *sh_mn                                 ;
cell    *sh_cell[MAX_CELLS_IN_LIST+1],res_cell ;
puchar   raster                                 ;
uchar    sh_raster[1024*2]                      ;
int16_t     i, d_x, n                              ;
int16_t     tab_angle[256]                         ;
cell    *cret = c                              ;

if ( dy >= 256 )
	dy = 255;                                        //AK! add for crash steck protection
if( !c->env     )
	return c;

if( c->flg&c_f_dust)  shave = 0; // dust can't shave
ri = le = 0;
if( ((long)(dy-1)*abs(inc))<2048 )
  inc=0;
if( inc!=0 )
  for (i=0; ( i < dy ) && ( i < 256 ); i++)          //AK add c/g 06.03.98
    tab_angle[i] = ((long)(dy-1-i)*inc)/2048;
else
    memset(tab_angle,0,dy*2);

if( shave || inc )
  {
	// если слишком мал буфер - уходим
	// иначе возможен вылет и т.п.  Nick 07.04.2002
	if( (long)dy * ( (dx + (long)(MAX (abs(tab_angle[0]), abs(tab_angle[dy-1]))+7))>>3) >
		sizeof(sh_raster)
	  )
	  return c;

    raster = save_raster (c);

    le = diff_left_limit_rast(raster,dx,dy,tab_angle);

    if( inc<0 ) // inc<0 - clear rotating
      ri = diff_left_limit_cell(c, tab_angle, c->w);

    d_x = shift_raster (raster, dy, dx, tab_angle,
      (int16_t)(MAX (abs(tab_angle[0]), abs(tab_angle[dy-1]))), sh_raster, inc);

/*
	 if( line_number == 16 && c->col == 462)
	 {
		char qq[64];
		MessageBox(GetActiveWindow(),itoa(dx,qq,10),"old",MB_OK);
		MessageBox(GetActiveWindow(),itoa(dy,qq,10),"dy",MB_OK);
		MessageBox(GetActiveWindow(),itoa(inc,qq,10),"inc",MB_OK);
		MessageBox(GetActiveWindow(),itoa(d_x,qq,10),"new",MB_OK);
	 }
*/

  if( (sh_mn = c_locomp (sh_raster, (int16_t)bytlen(d_x), dy, 0, 0))==NULL )
    return c;

  for(i=0; sh_mn && i<MAX_CELLS_IN_LIST; i++, sh_mn = sh_mn->mnnext)
    {
    if( (sh_cell[i]=create_cell (sh_mn, c, c->bdiff, (char)(c->difflg&0xf0)))==NULL )
      return c;
    if( sh_cell[i]->w>RASTER_MAX_WIDTH || sh_cell[i]->h>RASTER_MAX_HEIGHT ||
		!sh_cell[i]->env
	  )
      {
      for(;i>=0;i--)
        del_cell(sh_cell[i]);
      return c;
      }

    sh_cell[i]->stick_inc = NO_INCLINE; // rotate disabled
    }

  sh_cell[i] = NULL;
  n=i;

  for(lminx=lminy=c->w,i=0;i<n;i++)
    {
    if( lminx>sh_cell[i]->env->left )
      lminx=sh_cell[i]->env->left;
    if( lminy>sh_cell[i]->env->upper )
      lminy=sh_cell[i]->env->upper;
    }


  for(i=0;i<n;i++)
    pimpleshave( sh_cell[i], shave, inc );

  for(lminsx=lminsy=c->w,i=0;i<n;i++)
    {
    if( lminsx>sh_cell[i]->env->left )
      lminsx=sh_cell[i]->env->left;
    if( lminsy>sh_cell[i]->env->upper )
      lminsy=sh_cell[i]->env->upper;
    }

  memcpy( &res_cell, c , sizeof(cell));
  compose_cell(n, sh_cell, &res_cell);

  if( n<2 )
    c->cg_flag &= 0xFB         ; // clear compose flag for normal comp
  else
    c->cg_flag |= c_cg_comp    ; // set composed flag
  c->env        = res_cell.env ;
  c->env->upper = c->r_row     ;
  c->env->left  = c->r_col     ;
  if( n>1 || c->dens==255 )
    c->dens     = 255          ; // undef
  else
    {
    int32_t dens   = calc_dens(c);
    c->dens     = (dens*32)/(res_cell.w*res_cell.h);
    }
  c->w          = res_cell.w   ;
  c->h          = res_cell.h   ;
  c->recsource  = 0            ; // artifact


  if( le<0 && c->col+le>=0 && c->r_col+le>=0 && c->env->left+le>=0 )
    {
    c->env->left += le;
    c->col       += le;
    c->r_col     += le;
    }
  if( ri>0 )
    {
    c->env->left += ri;
    c->col       += ri;
    c->r_col     += ri;
    }
  if( lminsx>lminx )
    {
    lminsx -= lminx;
    c->env->left += lminsx;
    c->col       += lminsx;
    c->r_col     += lminsx;
    }
  if( lminsy>lminy )
    {
    lminsy -= lminy;
    c->env->upper += lminsy;
    c->row        += lminsy;
    c->r_row      += lminsy;
    }
  if( (c->flg&(c_f_bad|c_f_let)) && c->w<MAX_DUST_WIDTH && c->h<MAX_DUST_HEIGHT )
    {
    cell *wc;
    c->flg   = c_f_dust;
    c->nvers = 0;
    c->vers[0].let=c->vers[0].prob=0;
    (wc=c->prevl)->nextl = c->nextl;
    c->nextl->prevl      = c->prevl;
    err_pnlet(c);
    }

  if( !(inc==0 && shave!=0) )    // not shaving without erection
    c->stick_inc  = inc;
  if( inc!=0 )
    c->pos_inc=erect_rot;

  if( n>1 && cutting)
    cret = convert_to_cells(c);

  }

// Nick 7.04.2002 c->cret - с может быть удален в convert_to_cells!
if( !inc &&  (cret->flg&c_f_dust) )
  {
  cret->stick_inc  = sinc;
  cret->pos_inc=erect_rot;
  }

return cret;
}