-
Notifications
You must be signed in to change notification settings - Fork 0
/
printing.c
153 lines (141 loc) · 4.2 KB
/
printing.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* printing.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ybouddou <ybouddou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/06/23 20:07:09 by ybouddou #+# #+# */
/* Updated: 2021/07/02 13:35:21 by ybouddou ### ########.fr */
/* */
/* ************************************************************************** */
#include "sudoku.h"
void print_color(char *color, int num, int nl)
{
int x;
x = -1;
while (++x < num)
printf("%s", color);
if (nl)
printf("\n");
printf("\e[0m");
}
void print_VLine(int x)
{
if (!((x + 1) % 3))
print_color("\e[0m\e[1;32m|", 1, 0);
else
print_color("\e[2;37m|", 1, 0);
}
void print_HLine(int x, int y)
{
x = -1;
printf("\n ");
while (++x < 37)
{
if (!((x) % 12) && x && x != 36 && y != 8)
print_color("\e[1;32m+", 1, 0);
else if (!((y + 1) % 3) || !x || x == 36)
print_color("\e[1;32m-", 1, 0);
else
print_color("\e[2;37m-", 1, 0);
}
printf("\n");
}
void print_solved(t_sudo *sudo)
{
int x;
int y;
printf("\n\e[0;34mInput:\e[0m -a \e[0;35my \e[0;35mx \e[0mn | \e[0;34mErase:\e[0m -e \e[0;35my \e[0;35mx\e[0m | \e[0;34mExit: \e[0mexit\n\n");
printf("\e[1;32my\e[0;34m\\\e[1;32mx\e[0;35m 0 1 2 3 4 5 6 7 8\n \e[0m");
print_color("\e[1;32m-", 37, 1);
y = -1;
while (++y < 9)
{
printf("\e[0;35m%d \e[0m", y);
print_color("\e[1;32m|", 1, 0);
x = -1;
while (++x < 9)
{
if (sudo->solved[y][x])
printf("\e[1;34m %d \e[0m", sudo->solved[y][x]);
else
printf(" \e[2;37m%d\e[0m ", sudo->solved[y][x]);
print_VLine(x);
}
print_HLine(x, y);
}
printf("\n");
}
void print_grid(t_sudo *sudo)
{
int x;
int y;
printf("\n\e[0;34mInput:\e[0m -a \e[0;35my \e[0;35mx \e[0mn | \e[0;34mErase:\e[0m -e \e[0;35my \e[0;35mx\e[0m | \e[0;34mExit: \e[0mexit\n\n");
while (sudo->grids--)
write(1, "\033[1A\r\033[K", 8);
printf("\e[1;32my\e[0;34m\\\e[1;32mx\e[0;35m 0 1 2 3 4 5 6 7 8\n \e[0m");
print_color("\e[1;32m-", 37, 1);
y = -1;
while (++y < 9)
{
printf("\e[0;35m%d \e[0m", y);
print_color("\e[1;32m|", 1, 0);
x = -1;
while (++x < 9)
{
if (sudo->fixed[y][x])
printf("\e[1;34m %d \e[0m", sudo->grid[y][x]);
else if (!sudo->grid[y][x])
printf(" \e[2;37m%d ", sudo->grid[y][x]);
else if (sudo->grid[y][x] == sudo->solved[y][x] && y == sudo->y &&
x == sudo->x)
printf(" \e[0;32m%d\e[0m ", sudo->grid[y][x]);
else if (sudo->grid[y][x] == sudo->solved[y][x])
printf(" \e[0m%d ", sudo->grid[y][x]);
else
printf(" \e[0;31m%d\e[0m ", sudo->grid[y][x]);
print_VLine(x);
}
print_HLine(x, y);
}
printf("\n");
sudo->grids = 25;
}
void print_bits(t_sudo *sudo)
{
int x;
x = -1;
printf("--------rows-----------\n");
while (++x < 9)
printf("row[%d] : %d\n", x, sudo->row[x]);
x=-1;
printf("--------cols-----------\n");
while (++x < 9)
printf("col[%d] : %d\n", x, sudo->col[x]);
x=-1;
printf("--------cells----------\n");
while (++x < 9)
printf("cell[%d] : %d\n", x, sudo->cell[x]);
}
/*
-------------------------------------
| 3 | 0 | 6 | 5 | 0 | 8 | 4 | 0 | 0 |
------------+-----------+------------
| 5 | 2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
------------+-----------+------------
| 0 | 8 | 7 | 0 | 0 | 0 | 0 | 3 | 1 |
------------+-----------+------------
| 0 | 0 | 3 | 0 | 1 | 0 | 0 | 8 | 0 |
------------+-----------+------------
| 9 | 0 | 0 | 8 | 6 | 3 | 0 | 0 | 5 |
------------+-----------+------------
| 0 | 5 | 0 | 0 | 9 | 0 | 6 | 0 | 0 |
------------+-----------+------------
| 1 | 3 | 0 | 0 | 0 | 0 | 2 | 5 | 0 |
------------+-----------+------------
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 7 | 4 |
------------+-----------+------------
| 0 | 0 | 5 | 2 | 0 | 6 | 3 | 0 | 0 |
-------------------------------------
*/