-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtree_visual.c
73 lines (67 loc) · 1.99 KB
/
tree_visual.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
#include <stdlib.h>
#include <curses.h>
#include "tree.h"
#include "board.h"
#include "points.h"
void board_print_old(board_t *board, char color, int depth) {
for (int i = 0; i <= depth; i++) {
printf("\t");
}
printf(" 0 1 2 3 4 5 6 7\n");
int amount = 0;
for (int y = 0; y < 8; y++) {
for (int i = 0; i <= depth; i++) {
printf("\t");
}
printf("%i ", y);
for (int x = 0; x < 8; x++) {
if (board->pieces[y][x] != NULL) {
printf("%c", board->pieces[y][x]->color);
} else if (board_can_add_print(board, color, x, y)) {
if (color == 'W') {
printf("◼");
} else {
printf("◻");
}
amount++;
} else {
printf("·");
}
if (x != 7) printf(" ");
}
printf("\n");
}
printf("\n\n");
}
void print_tree(node_t *node) {
if (node->recentPieceAdded.x == 0 && node->recentPieceAdded.y == 0) {
printf("\troot\n");
//board_print_old(node->board, node->player, node->depth);
} else {
for (int i = 0; i <= node->depth; i++) {
printf("\t");
}
printf("%c Depth %i Added: %i, %i (First: %i, %i) Flipped %i, value %i\n\n",
node->player, node->depth, node->recentPieceAdded.x, node->recentPieceAdded.y, node->firstPieceAdded.x, node->firstPieceAdded.y, node->piecesFlipped,
node->value);
//board_print_old(node->board, node->player == 'P' ? 'C' : 'P', node->depth);
}
for (int i = 0; i < node->numOfChildren; i++) {
print_tree(node->children[i]);
}
}
int main(void) {
board_t* board = board_init();
//board_print_old(board, 'P', 0);
board_add_piece(board, 'P', 2, 3);
node_t* root = node_init(board);
tree_create(root, 5);
//print_tree(root);
node_t* max = tree_get_max(root, 5);
printf("%i, %i, value: %i\n", max->firstPieceAdded.x, max->firstPieceAdded.y, max->value);
free(root);
root = calloc(sizeof(root), sizeof(node_t*));
free(max);
max = calloc(sizeof(max), sizeof(node_t*));
return 0;
}