-
Notifications
You must be signed in to change notification settings - Fork 0
/
rules_encode.c
31 lines (26 loc) · 883 Bytes
/
rules_encode.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
#include <string.h>
#include "rules_encode.h"
#include "matrix_utils.h"
void encodeRules(char mat[][5], int *col, int *row, char *out) {
if (col[0] == col[1]) {
sameColEncode(mat, col, row, out);
} else if (row[0] == row[1]) {
sameRowEncode(mat, col, row, out);
} else {
differentRowCol(mat, col, row, out);
}
}
void sameColEncode(char mat[][5], int *col, int *row, char *out) {
char a = getCharInMatrix(mat, col[0], mod5(row[0] + 1));
char b = getCharInMatrix(mat, col[1], mod5(row[1] + 1));
strncat(out, &a, 1);
strncat(out, &b, 1);
strcat(out, " ");
}
void sameRowEncode(char mat[][5], int *col, int *row, char *out) {
char a = getCharInMatrix(mat, mod5(col[0] + 1), row[0]);
char b = getCharInMatrix(mat, mod5(col[1] + 1), row[1]);
strncat(out, &a, 1);
strncat(out, &b, 1);
strcat(out, " ");
}