diff --git a/libs/grafo.c b/libs/grafo.c index dd81194df53b12dd4d18ddefab71e0e5460d6013..c3002cf05526c2109f54c3e802d8eef0c99a4c67 100644 --- a/libs/grafo.c +++ b/libs/grafo.c @@ -184,10 +184,10 @@ void grafoParaDot(Grafo g, Lista grupo, FILE* fp) { // 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\npeso=%d\nbonus=%d\naltura=%d\"];\n", pai, pai->cor, pai->peso, pai->bonus, pai->altura); + fprintf(fp, "\t\"%p\" [label=\"cor=%d\npeso=%d\nbonus=%lu\naltura=%d\"];\n", pai, pai->cor, pai->peso, pai->bonus, pai->altura); for(No m = primeiroNoLista(pai->filhos); m; m = getSucessorNo(m)) { Vertice filho = (Vertice) getConteudo(m); - fprintf(fp, "\t\"%p\" [label=\"cor=%d\npeso=%d\nbonus=%d\naltura=%d\"];\n", filho, filho->cor, filho->peso, filho->bonus, filho->altura); + fprintf(fp, "\t\"%p\" [label=\"cor=%d\npeso=%d\nbonus=%lu\naltura=%d\"];\n", filho, filho->cor, filho->peso, filho->bonus, filho->altura); fprintf(fp, "\t\"%p\" -- \"%p\";\n", pai, filho); } } diff --git a/libs/jogador.c b/libs/jogador.c index c1c832755d04b2314f0a431fbab1275f4b20fe7d..afb06fd1aab93136fa613cc370571f797036a117 100644 --- a/libs/jogador.c +++ b/libs/jogador.c @@ -54,7 +54,7 @@ Lista Joga(Grafo g, Lista grupo){ } } // printf("\t\tCOR ESCOLHIDA: %d\n", maior->cor); - insereLista(maior->cor, jogadas); + insereLista((void *) maior->cor, jogadas); for(No n = primeiroNoLista(filhos); n; n = getSucessorNo(n)) { Vertice v = (Vertice) getConteudo(n); @@ -145,6 +145,18 @@ bool corEstaNaLista(Lista l, int cor) { return false; } +int calculaBonusRec(Vertice v, Grafo g, int profundidade) { + if(profundidade <= 0) return 0; + int bonus = 0; + for(No n = primeiroNoLista(v->filhos); n; n = getSucessorNo(n)) { + Vertice filho = (Vertice) getConteudo(n); + if((filho->altura > v->altura)) { + bonus += filho->peso + calculaBonusRec(filho, g, profundidade-1); + } + } + return v->bonus = bonus; +} + void calculaBonus(Lista grupo, Grafo g, int profundidade) { for(No n = primeiroNoLista(grupo); n; n = getSucessorNo(n)) { Vertice v = (Vertice) getConteudo(n); @@ -152,7 +164,7 @@ void calculaBonus(Lista grupo, Grafo g, int profundidade) { for(No m = primeiroNoLista(v->filhos); m; m = getSucessorNo(m)) { Vertice filho = (Vertice) getConteudo(m); if((filho->altura > v->altura)) { - int bonus = filho->peso + calculaBonusRec(filho, v, g, profundidade); + int bonus = filho->peso + calculaBonusRec(filho, g, profundidade); if(corEstaNaLista(grupo, filho->cor)) bonus += 50; v->bonus += bonus; } @@ -213,15 +225,3 @@ void calculaBonus(Lista grupo, Grafo g, int profundidade) { return; } - -int calculaBonusRec(Vertice v, Vertice pai, Grafo g, int profundidade) { - if(profundidade <= 0) return 0; - int bonus = 0; - for(No n = primeiroNoLista(v->filhos); n; n = getSucessorNo(n)) { - Vertice filho = (Vertice) getConteudo(n); - if((filho->altura > v->altura)) { - bonus += filho->peso + calculaBonusRec(filho, v, g, profundidade-1); - } - } - return v->bonus = bonus; -} diff --git a/main.c b/main.c index 64059a996b32095e07962f62e899695f145e5cba..dfeb37af150bd3ff52a1ff1029f669ef1a6c1fa2 100644 --- a/main.c +++ b/main.c @@ -10,7 +10,7 @@ #include "libs/grafo.h" #include "libs/jogador.h" -int main(int argc, char *argv[]) { +int main() { Tblr t = criaTblr(); // Aloca o tabuleiro em um único array em vez de um "array de arrays" if(!leTblr(t)) { @@ -18,28 +18,6 @@ int main(int argc, char *argv[]) { return -1; } - // Se colocar UMA e APENAS UMA coisa depois do main - if(argc == 2) { - // Calcula e imprime o número mÃnimo e máximo de jogadas - if(t->x != t->y) { - puts("Apenas funciona para tabuleiros quadrados"); - } else { - // Max é 2n + sqrt(2k)n + k - double max = 2*(t->x) + (sqrt(2*t->cores))*(t->x) + t->cores; - printf("\tNúmero máximo de jogadas: %f\n", max); - // Min é válido para 2 <= k <= n² - // Min é sqrt(k - 1)n/2 - k/2 - if(t->cores >= 2 && t->cores <= (t->x*t->x)) { - double n2 = t->x/2; - double min = (sqrt(t->cores - 1)*t->x/2) - (t->cores/2); - printf("\tNúmero mÃnimo de jogadas: %f\n", min); - } - } - } - - //TODO imprimindo o tabuleiro -// imprimeTblr(t); - Grafo g = criaGrafo(); // Transforma o tabuleiro para um grafo tabuleiroParaGrafo(t, g);