2016-12-14 12:06:38 +02:00
|
|
|
|
#include "fillit.h"
|
2016-12-14 13:04:07 +02:00
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdio.h>
|
2016-12-14 12:06:38 +02:00
|
|
|
|
|
|
|
|
|
unsigned int ft_sqrt_ceil(unsigned int num)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
i = 1;
|
|
|
|
|
while (i * i < num)
|
|
|
|
|
i++;
|
|
|
|
|
return (i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void clear_map(t_map *map)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
while (i < 16)
|
|
|
|
|
map->line[i++] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-14 17:18:34 +02:00
|
|
|
|
void convert_tetramino(char *s, t_map *map, int index)
|
2016-12-14 12:06:38 +02:00
|
|
|
|
{
|
2016-12-14 13:04:07 +02:00
|
|
|
|
uint16_t temp;
|
|
|
|
|
int i;
|
|
|
|
|
int y;
|
2016-12-14 17:18:34 +02:00
|
|
|
|
int sharp_count;
|
2016-12-14 12:06:38 +02:00
|
|
|
|
|
2016-12-14 17:18:34 +02:00
|
|
|
|
map->figure[index].offset = 0;
|
|
|
|
|
sharp_count = 0;
|
2016-12-14 13:04:07 +02:00
|
|
|
|
i = 0;
|
|
|
|
|
y = 1;
|
2016-12-14 17:18:34 +02:00
|
|
|
|
while (i < 16 && sharp_count < 4)
|
2016-12-14 13:04:07 +02:00
|
|
|
|
{
|
|
|
|
|
temp = 0;
|
|
|
|
|
while (i < y * 4)
|
|
|
|
|
{
|
|
|
|
|
temp = temp << 1;
|
2016-12-14 17:18:34 +02:00
|
|
|
|
if (s[i++] == '#' && ++sharp_count)
|
2016-12-14 13:04:07 +02:00
|
|
|
|
temp = temp | 0x01;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
temp = temp << 12;
|
2016-12-14 17:18:34 +02:00
|
|
|
|
map->figure[index].line[y - 1] = temp;
|
2016-12-14 13:04:07 +02:00
|
|
|
|
y++;
|
|
|
|
|
}
|
2016-12-14 17:18:34 +02:00
|
|
|
|
map->figure[index].height = y - 1;
|
2016-12-14 12:06:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-14 17:18:34 +02:00
|
|
|
|
void map_initialization(char **tetramino_table, t_map *map)
|
2016-12-14 12:06:38 +02:00
|
|
|
|
{
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
while (*tetramino_table)
|
2016-12-14 17:18:34 +02:00
|
|
|
|
convert_tetramino(*tetramino_table++, map, i++);
|
2016-12-14 12:06:38 +02:00
|
|
|
|
map->figure_amount = i;
|
|
|
|
|
map->size = ft_sqrt_ceil(i * 4);
|
|
|
|
|
clear_map(map);
|
|
|
|
|
}
|
2016-12-14 13:33:54 +02:00
|
|
|
|
|
|
|
|
|
void insert_tetramino(t_map *map, int index)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
int k;
|
|
|
|
|
t_tetraminos *temp;
|
|
|
|
|
|
|
|
|
|
temp = map->figure[index];
|
|
|
|
|
i = temp->offset_y;
|
|
|
|
|
k = i + 4;
|
|
|
|
|
while (i < k)
|
|
|
|
|
{
|
|
|
|
|
map->line[i] |= temp->line[i];
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void erase_tetramino(t_map *map, int index)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
int k;
|
|
|
|
|
t_tetraminos *temp;
|
|
|
|
|
|
|
|
|
|
temp = map->figure[index];
|
|
|
|
|
i = temp->offset_y;
|
|
|
|
|
k = 0;
|
|
|
|
|
while (k < 4)
|
|
|
|
|
{
|
|
|
|
|
map->line[i + k] ^= temp->line[i + k];
|
|
|
|
|
k++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-14 17:18:34 +02:00
|
|
|
|
void shift_tetramino(t_map *map, int index)
|
|
|
|
|
{
|
|
|
|
|
//сделаю сдвиг фигуры вправо, если дошли до границы, то перемещу в начало следующего ряд и т.д.
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-14 13:33:54 +02:00
|
|
|
|
void algorithm(t_map *map)
|
|
|
|
|
{
|
2016-12-14 17:18:34 +02:00
|
|
|
|
//тут у меня сейчас трабл с рекурсией
|
|
|
|
|
//не могу пока написать что-то годное
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
t_map map;
|
|
|
|
|
char** table;
|
|
|
|
|
|
|
|
|
|
table = read_from_file();
|
|
|
|
|
map_initialization(table, &map);
|
|
|
|
|
algoritm(&map);
|
|
|
|
|
print_result(&map);
|
|
|
|
|
return (0);
|
2016-12-14 13:33:54 +02:00
|
|
|
|
}
|