-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolving_utils.c
57 lines (52 loc) · 2.1 KB
/
solving_utils.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
57
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* solving_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kmira <kmira@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/16 12:49:17 by kmira #+# #+# */
/* Updated: 2019/05/20 14:57:48 by kmira ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
extern t_tetrimino *g_place_pruning[27];
void place_piece
(t_tetrimino *tetrimino, unsigned short *board, int *row, int *col)
{
tetrimino->row_loc = *row;
tetrimino->col_loc = *col;
*(u_int64_t *)&board[*row] =
(*(u_int64_t *)&board[*row]) ^ (*(u_int64_t *)tetrimino->mask >> *col);
tetrimino->last = g_place_pruning[tetrimino->type];
g_place_pruning[tetrimino->type] = tetrimino;
}
void remove_piece
(t_tetrimino tetrimino, unsigned short *board, int *row, int *col)
{
*col = tetrimino.col_loc;
*row = tetrimino.row_loc;
*(u_int64_t *)&board[*row] =
(*(u_int64_t *)&board[*row]) ^ (*(u_int64_t *)tetrimino.mask >> *col);
g_place_pruning[tetrimino.type] = tetrimino.last;
}
int board_is_solved
(int *current_piece, t_tetrimino *tetrimino, int *row, int *col)
{
*current_piece = *current_piece + 1;
if (*current_piece > 25 || !(tetrimino[*current_piece].id))
return (1);
else
{
if (g_place_pruning[tetrimino[*current_piece].type] != NULL)
*row = g_place_pruning[tetrimino[*current_piece].type]->row_loc;
else
*row = 0;
if (g_place_pruning[tetrimino[*current_piece].type] != NULL)
*col = g_place_pruning[tetrimino[*current_piece].type]->col_loc;
else
*col = 0;
*col = *col - 1;
}
return (0);
}