Beispiel #1
0
void print_info(void) {
    char *dir_names[] = {"Right:", "Bottom:", "Left:", "Top:"};
    struct coord base_pos = player->pos;
    move(HEIGHT / 2, 2 * WIDTH);
    printw("%-8s %c", "Player:", player->symbol);
    move(HEIGHT / 2 + 1, 2 * WIDTH);
    printw("%7d HP", player->health);
    for(enum direction dir = EAST; dir <= NORTH; dir++) {
        struct coord cur_pos = {
            base_pos.x + next_coords[dir].x,
            base_pos.y + next_coords[dir].y
        };
        move(HEIGHT / 2 + 4 * next_coords[dir].y,
                2 * WIDTH + 16 * next_coords[dir].x);
        if (!out_of_bounds(cur_pos) && position_covered(cur_pos)) {
            struct entity *ent = board_map[cur_pos.y][cur_pos.x];
            printw("%-8s %c", dir_names[dir], ent->symbol);
            move(HEIGHT / 2 + 4 * next_coords[dir].y + 1,
                    2 * WIDTH + 16 * next_coords[dir].x);
            printw("%7d HP", ent->health);
        } else {
            printw("%-8s --", dir_names[dir]);
        }
    }
}
// Get the data at an arbitrary (sort of) data index.
ProfileData* methodDataOopDesc::data_at(int data_index) {
  if (out_of_bounds(data_index)) {
    return NULL;
  }
  DataLayout* data_layout = data_layout_at(data_index);
  
  switch (data_layout->tag()) {
  case DataLayout::no_tag:
  default:
    ShouldNotReachHere();
    return NULL;
  case DataLayout::bit_data_tag:
    return new BitData(data_layout);
  case DataLayout::counter_data_tag:
    return new CounterData(data_layout);
  case DataLayout::jump_data_tag:
    return new JumpData(data_layout);
  case DataLayout::virtual_call_data_tag:
    return new VirtualCallData(data_layout);
  case DataLayout::ret_data_tag:
    return new RetData(data_layout);
  case DataLayout::branch_data_tag:
    return new BranchData(data_layout);
  case DataLayout::multi_branch_data_tag:
    return new MultiBranchData(data_layout);
  };
}
Beispiel #3
0
// Get the data at an arbitrary (sort of) data index.
ProfileData* MethodData::data_at(int data_index) const {
  if (out_of_bounds(data_index)) {
    return NULL;
  }
  DataLayout* data_layout = data_layout_at(data_index);
  return data_layout->data_in();
}
Beispiel #4
0
// Get the data at an arbitrary (sort of) data index.
ciProfileData* ciMethodData::data_at(int data_index) {
  if (out_of_bounds(data_index)) {
    return NULL;
  }
  DataLayout* data_layout = data_layout_at(data_index);

  switch (data_layout->tag()) {
  case DataLayout::no_tag:
  default:
    ShouldNotReachHere();
    return NULL;
  case DataLayout::bit_data_tag:
    return new ciBitData(data_layout);
  case DataLayout::counter_data_tag:
    return new ciCounterData(data_layout);
  case DataLayout::jump_data_tag:
    return new ciJumpData(data_layout);
  case DataLayout::receiver_type_data_tag:
    return new ciReceiverTypeData(data_layout);
  case DataLayout::virtual_call_data_tag:
    return new ciVirtualCallData(data_layout);
  case DataLayout::ret_data_tag:
    return new ciRetData(data_layout);
  case DataLayout::branch_data_tag:
    return new ciBranchData(data_layout);
  case DataLayout::multi_branch_data_tag:
    return new ciMultiBranchData(data_layout);
  case DataLayout::arg_info_data_tag:
    return new ciArgInfoData(data_layout);
  };
}
Beispiel #5
0
template<> void Bullet<rapid>::update(){
  
  if(!active) return;
  draw();
  x += xv;
  y += yv;
  
  if(out_of_bounds()) active = 0; else 
  if(Entity* e = enemy_contact(16.0)){
    
    aim(e->x,e->y,0.0);
    if(e = enemy_contact(1)){
  
      e->hit(2);
      gbullet_explosion(x,y,rand()%4+1);
      active = 0;
      return;
  
    }
    
  }  
  
  draw();
  
}
Beispiel #6
0
template<> void Bullet<gbomb>::update(){
  
  if(!active) return;
  
  x += xv*=0.98;
  y += yv*=0.98;
  
  if(fabs(xv)<0.1&&fabs(yv)<0.1){
    active = 0;
    gbullet_explosion(x,y,rand()%25+25);
    return;
  }
  
  if(out_of_bounds()) active = 0; else 
  
  if(Entity* e = enemy_contact(1)){
    e->hit(5);
    gbullet_explosion(x,y,rand()%25+25);
    active = 0;
    return;

  }  
  
  draw();
  
}
Beispiel #7
0
int puts_at(char *str, char attr, int r, int c) {
	if(out_of_bounds(r, c)) {
		return INDEX_OUT_OF_BOUNDS_ERROR;
	}

	while(*str) {
		if(*str == '\n') {
			if(++r >= ROWS) {
				return INDEX_OUT_OF_BOUNDS_ERROR;
			}
			c = 0;
			str++;
			continue;
		}
		if(c == COLS) {
			if(++r >= ROWS) {
				return INDEX_OUT_OF_BOUNDS_ERROR;
			}
			c = 0;
		}
		putchar_at(*str++, attr, r, c++);
	}

	return 0;
}
Beispiel #8
0
// Get the data at an arbitrary (sort of) data index.
ProfileData* methodDataOopDesc::data_at(int data_index) {
  if (out_of_bounds(data_index)) {
    return NULL;
  }
  DataLayout* data_layout = data_layout_at(data_index);
  return data_layout->data_in();
}
Beispiel #9
0
void array_read( const array *arr, int n, void *dst )
{
    if ( 0 <= n && n < arr->length ) {
        memcpy( dst, arr->mem + n * arr->size, arr->size );
    } else {
        out_of_bounds(arr, n);
    }
}
Beispiel #10
0
int putchar_at(char ch, char attr, int r, int c) {
	if(out_of_bounds(r, c)) {
		return INDEX_OUT_OF_BOUNDS_ERROR;
	}
	video[(c + r * COLS) * 2] = ch;
	video[(c + r * COLS) * 2 + 1] = attr;

	return 0;
}
Beispiel #11
0
void array_write( array *arr, int n, const void *src )
{
    if ( 0 <= n && n < arr->length ) {
        memcpy( arr->mem + n * arr->size, src, arr->size );
    } else {
        out_of_bounds(arr, n);
    }
    
}
Beispiel #12
0
/*
 * Draw one map character on the players terminal.
 */
int get_one_square(int x, int y) {

    if(out_of_bounds(x, y, 1, 1)) {
	write("Someone spilled spam on that part of the map.\n");
	return 1;
    }

    do_draw(x, y, 1, 1);
    return 1;
}
Beispiel #13
0
/*
 * Draw a map with x,y as centre and rad as radius using
 * standard map characters.
 */
draw_area_around(int x, int y, int rad) {

    if(out_of_bounds(x - rad, y + rad, rad * 2 + 1, rad * 2 + 1)) {
	write("Someone spilled spam on that part of the map.\n");
	return 1;
    }

    do_draw(x - rad, y + rad, rad * 2 + 1, rad * 2 + 1);
    return 0;
}
Beispiel #14
0
void block_loop::set_subspace_looped(size_t bispace_idx, size_t subspace_idx)
{
#ifdef LIBTENSOR_DEBUG
    //Is bispace_idx/subspace_idx valid?
    if(bispace_idx >= m_bispaces_ignored.size())
    {
        throw out_of_bounds(g_ns, k_clazz,"set_subspace_looped(...)",
                            __FILE__, __LINE__, "bispace_idx is out of bounds");
    }
    if(subspace_idx >= m_bispace_orders[bispace_idx])
    {
        throw out_of_bounds(g_ns, k_clazz,"set_subspace_looped(...)",__FILE__, __LINE__,
                            "subspace_idx is out of bounds");
    }
#endif

    //Finally, record that the loop touches the specified subspace of the given bispace
    m_subspaces_looped[bispace_idx] = subspace_idx;
    m_bispaces_ignored[bispace_idx] = false;
}
Beispiel #15
0
bool block_loop::is_bispace_ignored(size_t bispace_idx) const
{
#ifdef LIBTENSOR_DEBUG
    if(bispace_idx >= m_bispaces_ignored.size())
    {
        throw out_of_bounds(g_ns, k_clazz,"is_bispace_ignored(...)",
                            __FILE__, __LINE__, "bispace_idx is out of bounds");
    }
#endif

    return m_bispaces_ignored[bispace_idx];
}
Beispiel #16
0
int main(int argc, char **argv) {
    if (argc != 7) {
        printf("Usage: %s <input> <output> <start_x> <start_y> <end_x> <end_y>\n", argv[0]);
    } else {
        FILE *in = fopen(argv[1], "r"); // open input file
        FILE *out = fopen(argv[2], "w"); // open output file

        int start_x = atoi(argv[3]);
        int start_y = atoi(argv[4]);
        int end_x = atoi(argv[5]);
        int end_y = atoi(argv[6]);

        if (in == NULL) {
            printf("Could not open input file: No such file or directory\n");
        } else if (out == NULL) {
            printf("Could not open output file\n");
        } else if (!parseable(&argv[3], 4)) {
            printf("Could not parse coordinates\n");
        } else if (out_of_bounds(start_x, start_y)) {
            printf("Start location out of bounds: (%d, %d)\n", start_x, start_y);
        } else if (out_of_bounds(end_x, end_y)) {
            printf("End location out of bounds: (%d, %d)\n", end_x, end_y);
        } else {
            reconstruct(in); // reconstruct maze array from input file

#ifdef FULL
            fprintf(out, "FULL\n");
#else
            fprintf(out, "PRUNED\n");
#endif

            // depth-first search for solution path
            dfs(start_x, start_y, end_x, end_y, out);

            fclose(in);
            fclose(out);
        }
    }
    return 0;
}
Beispiel #17
0
template<> void Bullet<particle>::update(){
  
  if(!active) return;
  x += xv;
  y += yv;
 
  w *= decay;
  if(w < 0.1) active = 0;
  
  if(out_of_bounds()) active = 0; 
  
  draw();
  
}
Beispiel #18
0
template<> void Bullet<bad>::update(){

  if(!active) return;
  draw();
  x += xv;
  y += yv;
  
  if(out_of_bounds()) active = 0; else
  if(player_contact()){
    player.hit(1);
    explosion(x,y,rand()%13+7);
    active = 0;
    return;
  }
  draw();
  
}
Beispiel #19
0
size_t block_loop::get_subspace_looped(size_t bispace_idx) const
{
#ifdef LIBTENSOR_DEBUG
    if(bispace_idx >= m_bispaces_ignored.size())
    {
        throw out_of_bounds(g_ns, k_clazz,"get_subspace_looped(...)",
                            __FILE__, __LINE__, "bispace_idx is out of bounds");
    }
    else if(m_bispaces_ignored[bispace_idx] == true)
    {
        throw bad_parameter(g_ns, k_clazz,"get_subspace_looped(...)",
                            __FILE__, __LINE__, "bispace_idx is not looped over");
    }
#endif

    return m_subspaces_looped[bispace_idx];
}
Beispiel #20
0
/*
 * Draw a map with the top left corner in x,y. Use the standard
 * map characters.
 */
varargs int draw_area_from_corner(int x, int y, int range, int y__width) {

    if(range < 1 || range > 40 || y__width > 40) {
	write("Illegal range\n");
	return 1;
    }

    if(!y__width)
	y__width = range;

    if(out_of_bounds(x, y, range, y__width)) {
	write("Someone spilled spam on that part of the map.\n");
	return 1;
    }

    do_draw(x, y, range, y__width);

    return 0;
}
Beispiel #21
0
template<> void Bullet<good>::update(){
  
  if(!active) return;
  draw();
  x += xv;
  y += yv;
  
  if(out_of_bounds()) active = 0; else 
  if(Entity* e = enemy_contact(1)){
  
    e->hit(1);
    explosion(x,y,rand()%13+7);
    active = 0;
    return;
    
  }  
  
  draw();
  
}
Beispiel #22
0
int putnumber_at(int n, char attr, int r, int c) {
	int digits = 1;
	int number, i;
	char ch;

	if(out_of_bounds(r, c)) {
		return INDEX_OUT_OF_BOUNDS_ERROR;
	}
	if(n < 0) {
		putchar_at('-', attr, r, c++);
		n *= -1;
	}

	number = n;

	while((number /= 10) > 0) {
		digits++;
	}

	while(digits--) {
		number = n;
		i = digits;
		while(i--) {
			number /= 10;
		}

		if(c == COLS) {
			if(++r >= ROWS) {
				return INDEX_OUT_OF_BOUNDS_ERROR;
			}
			c = 0;
		}
		ch = number % 10 + '0';
		putchar_at(ch, attr, r, c++);
	}

	return 0;
}
Beispiel #23
0
	T & operator[](size_t i) const {
		if(i >= n) throw out_of_bounds(i, n);
		++index_counter;
		return d[i];
	}
Beispiel #24
0
 void set_hint_di(int di)  {
   assert(!out_of_bounds(di), "hint_di out of bounds");
   _hint_di = di;
 }
Beispiel #25
0
static void
        map_laser_ray(
        pixel_t * map_pixels,
        int map_size,
        int x1,
        int y1,
        int x2,
        int y2,
        int xp,
        int yp,
        int value,
        int alpha)
{
    
    int x2c = x2;
    int y2c = y2;
    
    if (out_of_bounds(x1, map_size) || out_of_bounds(y1, map_size))
    {
        return;
    }
    
    if (!(clip(&x2c, &y2c, x1, y1, map_size) || clip(&y2c, &x2c, y1, x1, map_size)))
    {
        int dx = abs(x2 - x1);
        int dy = abs(y2 - y1);
        int dxc = abs(x2c - x1);
        int dyc = abs(y2c - y1);
        int incptrx = (x2 > x1) ? 1 : -1;
        int incptry = (y2 > y1) ? map_size : -map_size;
        int sincv = (value > NO_OBSTACLE) ? 1 : -1;
        
        int derrorv = 0;
        
        if (dx > dy)
        {
            derrorv = abs(xp - x2);
        }
        else
        {
            swap(&dx, &dy);
            swap(&dxc, &dyc);
            swap(&incptrx, &incptry);
            derrorv = abs(yp - y2);
        }
        
        if (!derrorv)
        {   /* XXX should probably throw an exception */
            fprintf(stderr, "map_update: No error gradient: try increasing hole width\n");
            exit(1);
        }
        
        else
        {
            int error = 2 * dyc - dxc;
            int horiz = 2 * dyc;
            int diago = 2 * (dyc - dxc);
            int errorv = derrorv / 2;
            
            int incv = (value - NO_OBSTACLE) / derrorv;
            
            int incerrorv = value - NO_OBSTACLE - derrorv * incv;
            
            pixel_t * ptr = map_pixels + y1 * map_size + x1;
            int pixval = NO_OBSTACLE;
            
            int x = 0;
            for (x = 0; x <= dxc; x++, ptr += incptrx)
            {
                if (x > dx - 2 * derrorv)
                {
                    if (x <= dx - derrorv)
                    {
                        pixval += incv;
                        errorv += incerrorv;
                        if (errorv > derrorv)
                        {
                            pixval += sincv;
                            errorv -= derrorv;
                        }
                    }
                    else
                    {
                        pixval -= incv;
                        errorv -= incerrorv;
                        if (errorv < 0)
                        {
                            pixval -= sincv;
                            errorv += derrorv;
                        }
                    }
                }
                
                /* Integration into the map */
                *ptr = ((256 - alpha) * (*ptr) + alpha * pixval) >> 8;
                
                if (error > 0)
                {
                    ptr += incptry;
                    error += diago;
                } else
                {
                    error += horiz;
                }
            }
        }
    }