-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrint.c
143 lines (117 loc) · 3.11 KB
/
Print.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
/*
System modules
*/
#include <stdio.h>
#include <stdbool.h> // For booleans in C
#include <string.h> // For string modifications
/*
User defined modules
*/
#include "Definitions.h"
/*
Types aren't directly passed to each of the below functions so as to allow for
the same function to accept both debug arrays and solutions arrays, which are of
different natures. Both have 3D arrays in one way or another, but the 3rd dimension
in both mean very different things, as illustrated below
- 3rd dimension in debug arrays: a single solution, with 2D arrays for each attempt
- 3rd dimension in solutions arrays: stores all solutions without any failed attempts
*/
void print_1D_array(int* array, int max_size, bool chessboard, bool debug)
{
const char QUEEN_CHAR[] = "Q";
for (int i = 0; i < max_size; i++)
{
if (chessboard)
{
if (debug)
{
printf("%i ", array[i]); // Prints out number of attacks for each square
}
else
{
if (array[i] == 0)
{
printf(" %s ", QUEEN_CHAR);
}
else
{
printf(" \u2593 "); //2593 is unicode for a chequered square, which appears on non queen squares
}
}
}
else
{
printf("%i ", array[i]); // Prints the array as is
}
}
printf("\n");
}
/**
Prints out chessboard in both the chessboard and debug arrays
*/
void print_2D_array(int** array, int max_size, bool debug)
{
const char QUEEN_CHAR[] = "Q";
for (int i = 0; i < max_size; i++)
{
for (int j = 0; j < max_size; j++)
{
if (debug)
{
printf("%i ", array[i][j]); // Prints out number of attacks for each square
}
else
{
if (array[i][j] == 0)
{
printf(" %s ", QUEEN_CHAR);
}
else
{
printf(" \u2593 "); //2593 is unicode for a chequered square, which appears on non queen squares
}
}
}
printf("\n"); // Print a new line at the end of a row
}
printf("\n");
}
/**
Chessboard array gets passed to here. For loop which loops through all solutions
is found here
*/
void print_3D_array(int*** array, int no_3D_iterations, int no_2D_iterations, bool solutions_array, bool debug)
{
string heading; // Heading to print each time the chessboard is printed. Depends on array type inputted into function
// Check if array being passed is for solutions array or debug array
if (solutions_array)
{
strcpy(heading.str, "SOLUTION NO "); // Method of assigning strings to char arrays in structs
}
else
{
strcpy(heading.str, "ATTEMPT NO ");
}
for(int i = 0; i < no_3D_iterations; i++)
{
// Print required heading
printf("%s%i: \n", heading.str, i + 1);
print_2D_array(array[i], no_2D_iterations, debug);
// Print new line after chessboard has been printed
printf("\n");
}
}
/**
Used to print out the 4D debug array
*/
void print_4D_array(int**** array, int no_4D_iterations, int *no_3D_iterations, int no_2D_iterations, bool debug)
{
const bool NOT_SOLUTIONS_ARRAY = false;
string heading;
strcpy(heading.str, "SOLUTION NO ");
for (int i = 0; i < no_4D_iterations; i++)
{
printf("%s%i\n", heading.str, i + 1);
print_3D_array(array[i], no_3D_iterations[i], no_2D_iterations, NOT_SOLUTIONS_ARRAY, debug);
}
}