-
Notifications
You must be signed in to change notification settings - Fork 0
/
output.c
77 lines (70 loc) · 1.36 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "output.h"
void print_hamiltonian_path(struct Num_Coordinates *numbers)
{
int i;
printf(" (%2d, %2d)", numbers->coordinates[0].row, numbers->coordinates[0].col);
for (i = 1; i < numbers->count; i++)
{
printf(" -> (%2d, %2d)", numbers->coordinates[i].row, numbers->coordinates[i].col);
if ((i + 1) % 9 == 0)
{
printf("\n ");
}
}
printf("\n\n");
}
void print_board(
const struct Board *board,
const struct Num_Coordinates *numbers)
{
int i, j;
int output[MAX_ROWS][MAX_COLS];
for (i = 0; i < numbers->count; i++)
{
if (numbers->coordinates[i].row >= 0 && numbers->coordinates[i].col >= 0)
{
output[numbers->coordinates[i].row][numbers->coordinates[i].col] = i + 1;
}
}
for (i = 0; i < board->rows; i++)
{
for (j = 0; j < board->cols; j++)
{
if (board->grid[i][j] == FREE)
{
output[i][j] = FREE;
}
else if (board->grid[i][j] == BLOCKED)
{
output[i][j] = BLOCKED;
}
}
}
printf(" ");
for (i = 0; i < board->cols; i++)
{
printf(" %2d ", i);
}
printf("\n");
for (i = 0; i < board->rows; i++)
{
printf("%4d ", i);
for (j = 0; j < board->cols; j++)
{
if (output[i][j] != BLOCKED && output[i][j] != FREE)
{
printf("[%3d]", output[i][j]);
}
else if (output[i][j] == BLOCKED)
{
printf(" ");
}
else
{
printf("[ ]");
}
}
printf("\n");
}
printf("\n");
}