This repository was archived by the owner on Jul 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathetc.c
86 lines (67 loc) · 2.32 KB
/
etc.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
#define NULL 0
#include "etc.h"
#include "memoryAllocation.h"
/* get an instance of a game if needed for tests */
gameParams *getExampleGame(int n, int m) {
srand(5);
userMoveNode *head, *first, *second;
gameParams *game2 = NULL;
int i, j;
game2 = (gameParams *) malloc(sizeof(gameParams));
if (game2 == NULL) {
printf("Error: malloc has failed\n");
free(game2);
exit(0);
}
game2->n = n;
game2->m = m;
game2->N = m * n;
game2->mode = INIT_MODE;
game2->markErrors = 1;
game2->counter = 0;
game2->userBoard = allocateCellMatrix(game2->userBoard, game2->n * game2->m);
for (i = 0; i < m * n; i++) {
for (j = 0; j < m * n; j++) {
game2->userBoard[i][j] = (cell *) malloc(sizeof(cell *));
game2->userBoard[i][j]->value = rand() % (n * m) + 1;
game2->userBoard[i][j]->isValid = 1;
if (i % 3 == 0) {
game2->userBoard[i][j]->isFixed = 1;
}
if (j % 3 == 0) {
game2->userBoard[i][j]->isValid = 0;
}
}
}
game2->solution = allocateCellMatrix(game2->solution, m * n);
game2->counter = 6;
game2->movesList = (listOfMoves *) malloc(sizeof(listOfMoves *));
game2->movesList->size = 1;
game2->movesList->head = (userMoveNode *) malloc(sizeof(userMoveNode *));
head = game2->movesList->head;
head->change = (cellChangeRecNode *) malloc(sizeof(cellChangeRecNode *));
head->prev = NULL;
head->next = (userMoveNode *) malloc(sizeof(userMoveNode *));
first = head->next;
first->next = NULL;
first->prev = head;
first->change = (cellChangeRecNode *) malloc(sizeof(cellChangeRecNode *));
first->change->currVal = (cell *) malloc(sizeof(cell *));
first->change->prevVal = (cell *) malloc(sizeof(cell *));
first->change->next = NULL;
first->change->x = 1;
first->change->y = 1;
first->change->currVal = game2->userBoard[3][3];
first->change->prevVal = game2->userBoard[0][0];
game2->movesList->currentMove = first;
return game2;
}
#if 0
typedef struct cellChangeRecNode {
int x; /*x coordinate of cell*/
int y; /*y coordinate of cell*/
cell *prevVal;
cell *currVal;
struct cellChangeRecNode *next; /*pointer to next node*/
} cellChangeRecNode;
#endif