66 ph->
map = (
int **)malloc(ph->
x_cells *
sizeof(
int *));
67 for(i = 0; i < ph->
x_cells; i++)
69 ph->
map[i] = (
int *)malloc(ph->
y_cells *
sizeof(
int));
70 for(j = 0; j < ph->
y_cells; j++)
77 ph->
eval_cells = ceil((
float)(eval_radius * 2) / (
float)width);
85 ph->
pheromone_cells = ceil((
float)(pheromone_radius * 2) / (
float)width);
115 for(i = 0; i < ph->
x_cells; i++)
152 (*stencil) = (
int **)malloc(size *
sizeof(
int *));
153 for(i = 0; i < size; ++i)
155 (*stencil)[i] = (
int *)malloc(size *
sizeof(
int));
156 for(j = 0; j < size; j++)
158 (*stencil)[i][j] = 0;
163 general_circle((*stencil), (size - 1)/2, (size - 1)/2, (size - 1)/2);
183 if(cx >= 0 && cy >= 0)
202 if((cx + i) >= 0 && (cy + j) >= 0 && (cx + i) < ph->
x_cells && (cy + j) < ph->
y_cells)
205 ph->
map[cx + i][cy + j] = time(NULL) / ph->
lifetime;
224 float a[5] = {-M_PI/2, -M_PI/4, 0, M_PI/4, M_PI/2};
227 int s[5] = {0, 0, 0, 0, 0};
229 float p[5] = {0, 0, 0, 0, 0};
237 for(k = 0; k < 5; k++)
244 for(i = 0; i < ph->eval_cells; i++)
252 if((x + i) >= 0 && (y + j) >= 0 && (x + i) < ph->
x_cells && (y + j) < ph->
y_cells)
254 t = ((time(NULL) / ph->
lifetime) - ph->
map[x + i][y + j]);
261 s[k] += (256 - t) * 100;
276 for(k = 0; k < 5; k++)
278 p[k] = ((float)s_t / (
float)s[k]);
288 if((rand() % 10) > 5)
295 debug_printf(
"%f, %f, %f, %f, %f\n", p[0], p[1], p[2], p[3], p[4]);
297 if(p[0] == p[1] && p[0] == p[2] && p[0] == p[3] && p[0] == p[4])
310 if(p_r >= 0 && p_r < (p[0])) {
313 else if(p_r >= (p[0]) && p_r < (p[0] + p[1])) {
316 else if(p_r >= (p[0] + p[1]) && p_r < (p[0] + p[1] + p[2])){
319 else if(p_r >= (p[0] + p[1] + p[2]) && p_r < (p[0] + p[1] + p[2] + p[3])) {
322 else if(p_r >= (p[0] + p[1] + p[2] + p[3]) && p_r < (p[0] + p[1] + p[2] + p[3] + p[4])) {
344 for(j = 0; j < ph->
y_cells; j++)
374 int i, j, x = 0, y = 0;
395 for(i = 0; i < ph->
x_cells; i++)
397 for(j = 0; j < ph->
y_cells; j++)
400 t = t_curr - ph->
map[i][j];
412 cell = (
unsigned char)t;
416 phms[x]->
data[y] = cell;
429 if(x < ph->sector_count)
void debug_printf(const char *format,...)
void pheromone_make_stencil(int ***stencil, int size)
int pheromone_eval(pheromone_t *ph, robot_t *robot)
pheromone_map_sector_t ** pheromone_map_extract(pheromone_t *ph)
void pheromone_map_update(pheromone_t *ph, pheromone_map_sector_t *phms)
void general_circle(int **arr, int cx, int cy, int radius)
unsigned char data[s_CONFIG_PHEROMONE_SECTOR_MAX_SIZE]
pheromone_t * pheromone_init(enviroment_t *env, int width, int lifetime, int pheromone_radius, int eval_radius, int eval_dist, int sector_max_size)
void pheromone_put(pheromone_t *ph, int x, int y)
void pheromone_destroy(pheromone_t *ph)
void pheromone_map_destroy(pheromone_t *ph, pheromone_map_sector_t **phms)
Pheromone Map Sector structure.
Enviroment Structure - room points, tags, room point number, tag number.