Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <sys/stat.h>
- #include "filler.h"
- #include "my_string.h"
- int check_free_space(collect_t *map, collect_t *new_elem, pos_t pos)
- {
- int i, j;
- for(i = 0; i < new_elem->h; i++)
- for(j = 0; j < new_elem->w; j++)
- if(new_elem->array[i][j] == '*')
- {
- if(i+pos.y < map->h && j+pos.x < map->w && i+pos.y >= 0 && j+pos.x >= 0)
- {
- if(map->array[i+pos.y][j+pos.x] != '.')
- return (-1);
- }
- else
- return (-1);
- }
- return (0);
- }
- int check_connection(collect_t *map, collect_t *new_elem, pos_t pos, char symbol)
- {
- int i, j;
- for(i = 0; i < new_elem->h; i++)
- {
- for(j = 0; j < new_elem->w; j++)
- {
- if(new_elem->array[i][j] != '.')
- {
- if(i+pos.y+1 < map->h && map->array[i+pos.y+1][j+pos.x] == symbol)
- return (0);
- if (i+pos.y-1 >= 0 && map->array[i+pos.y-1][j+pos.x] == symbol)
- return (0);
- if (j+pos.x+1 < map->w && map->array[i+pos.y][j+pos.x+1] == symbol)
- return (0);
- if (j+pos.x-1 >= 0 && map->array[i+pos.y][j+pos.x-1] == symbol)
- return (0);
- }
- }
- }
- return (-1);
- }
- pos_t play(req_t *core)
- {
- pos_t res;
- int i, j;
- printlog("filler.log", "a","H = %d, W = %d", core->map.h, core->map.w);
- for (i = 0; i < core->map.h; i++)
- {
- for (j = 0; j < core->map.w; j++)
- {
- printlog("filler.log", "a", "play on\n");
- res.x = j, res.y = i;
- if (!check_free_space(&(core->map), &(core->elem), res) && !check_connection(&(core->map), &(core->elem), res, core->symbol))
- {
- printlog("filler.log", "a", "position = %d %d\n", res.x, res.y);
- return (res);
- }
- }
- }
- return (res);
- }
Add Comment
Please, Sign In to add comment