-
Notifications
You must be signed in to change notification settings - Fork 0
/
output.c
56 lines (51 loc) · 1.95 KB
/
output.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* output.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kmira <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/12 18:55:45 by kmira #+# #+# */
/* Updated: 2019/05/16 14:51:15 by kmira ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
void write_piece(t_tetrimino piece, char *board_str, int board_size)
{
int bit;
int i;
bit = 1 << 15;
i = 0;
while (i < 4)
{
if (piece.mask[0] & bit)
board_str[i + piece.col_loc +
((board_size + 1) * (piece.row_loc + 0))] = piece.id;
if (piece.mask[1] & bit)
board_str[i + piece.col_loc +
((board_size + 1) * (piece.row_loc + 1))] = piece.id;
if (piece.mask[2] & bit)
board_str[i + piece.col_loc +
((board_size + 1) * (piece.row_loc + 2))] = piece.id;
if (piece.mask[3] & bit)
board_str[i + piece.col_loc +
((board_size + 1) * (piece.row_loc + 3))] = piece.id;
bit = bit >> 1;
i++;
}
}
void print_solution_of(t_tetrimino *tetriminos, int board_size)
{
char board_str[MAX_BOARD_SIZE * MAX_BOARD_SIZE];
int num_pieces;
int i;
ft_memset(board_str, '.', 16 * 16);
i = -1;
while (++i < board_size)
board_str[(i * (board_size + 1)) + board_size] = '\n';
i = -1;
num_pieces = count_pieces(tetriminos);
while (++i < num_pieces)
write_piece(tetriminos[i], board_str, board_size);
write(1, board_str, board_size * (board_size + 1));
}