diff --git a/.gitignore b/.gitignore index fb87ea4e037b72e38c0da16b7bbf0b2279f32351..0b30b8aa6846e4bbaf1cf6aef5e398df0d28946f 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ test tests/*.txt tests/*.png massif.out* +*.out diff --git a/libs/grafo.c b/libs/grafo.c index d3f4729f4290f60b88989523c0bfcaa669049320..45d0ad878ed0c9c99e6640d3dc90648f783a4213 100644 --- a/libs/grafo.c +++ b/libs/grafo.c @@ -3,6 +3,7 @@ #include "lista.h" #include "vertice.h" #include "tabuleiro.h" +#include <stdio.h> Grafo criaGrafo() { Grafo g = malloc(sizeof(struct Grafo)); @@ -117,3 +118,23 @@ void destroiGrafo(Grafo g) { g = NULL; return; } + +void grafoParaDot(Grafo g, Lista grupo, FILE* fp) { + fprintf(fp, "strict graph g {\n"); + // Pinta os nós que estão no grupo de vermelho + for(No n = primeiroNoLista(grupo); n; n = getSucessorNo(n)) { + Vertice v = (Vertice) getConteudo(n); + fprintf(fp, "\t\"%p\" [color=red];\n", v); + } + // Imprime o grafo + for(No n = primeiroNoLista(g->vertices); n; n = getSucessorNo(n)) { + Vertice pai = (Vertice) getConteudo(n); + fprintf(fp, "\t\"%p\" [label=\"cor=%d,peso=%d\"];\n", pai, pai->cor, pai->peso); + for(No m = primeiroNoLista(pai->filhos); m; m = getSucessorNo(m)) { + Vertice filho = (Vertice) getConteudo(m); + fprintf(fp, "\t\"%p\" [label=\"cor=%d,peso=%d\"];\n", filho, filho->cor, filho->peso); + fprintf(fp, "\t\"%p\" -- \"%p\";\n", pai, filho); + } + } + fprintf(fp, "}\n"); +} diff --git a/libs/grafo.h b/libs/grafo.h index cd6a6ab5d1c55efaf1ee448a27eb45114b315040..90f148991241a0f505a5318c012b4e41ea6a35ce 100644 --- a/libs/grafo.h +++ b/libs/grafo.h @@ -1,6 +1,7 @@ #ifndef _GRAFO_ #define _GRAFO_ #include "tabuleiro.h" +#include <stdio.h> struct Grafo { Lista vertices; @@ -18,4 +19,6 @@ void tabuleiroParaGrafo(Tblr t, Grafo g); void destroiGrafo(Grafo g); +void grafoParaDot(Grafo g, Lista grupo, FILE* fp); + #endif diff --git a/main.c b/main.c index c9b43ff5e4a8e2717e6de40f4729421995c5a27c..50c6c7fe77cbd5d3b9d5393646d45847760b26ec 100644 --- a/main.c +++ b/main.c @@ -26,9 +26,17 @@ int main() { // Desaloca tabuleiro destroiTblr(t); - // printf("Número de grupos: %d\n", tamanhoLista(g->vertices)); Lista jogadas = constroiLista(); + // PARA DEBUGAR: Imprime o grafo tabuleiro em formato dot com os vértices já + // "consumidos" pintados de vermelho + printf("Número de grupos: %d\n", tamanhoLista(g->vertices)); + FILE* debug = fopen("./debug.out", "w+"); + if(debug) { + grafoParaDot(g, grupo, debug); + } + fclose(debug); + destroiLista(jogadas, NULL); // Desaloca lista do grupo destroiLista(grupo, NULL); diff --git a/tests/runTests.sh b/tests/runTests.sh index 47eee75d8044e46b0f58eb05d39724a0a02f163f..359beedd89058b632ce5e0e676f8ea80f1809f68 100755 --- a/tests/runTests.sh +++ b/tests/runTests.sh @@ -4,10 +4,10 @@ tempo_max=10000 #10s # tamanhos do tabuleiro -tams=(4 8 16 25 32 50 64 75 100 128) +tams=(4 8 16 32 64 128 256) # lista de cores -cores=(2 3 4 5 6 7 8 10 16 32) +cores=(2 4 8 16 32) #-- Cores do terminal RED='\033[0;31m'