From 4ead459661818bd6f2f086a5016341efb44ff5ef Mon Sep 17 00:00:00 2001
From: Vytor Calixto <vytorcalixto@gmail.com>
Date: Sun, 18 Jun 2017 14:41:50 -0300
Subject: [PATCH] =?UTF-8?q?[ci=20skip]=20Limpando=20o=20c=C3=B3digo=20para?=
 =?UTF-8?q?=20a=20entrega?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 libs/grafo.c   |  4 ++--
 libs/jogador.c | 28 ++++++++++++++--------------
 main.c         | 24 +-----------------------
 3 files changed, 17 insertions(+), 39 deletions(-)

diff --git a/libs/grafo.c b/libs/grafo.c
index dd81194..c3002cf 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 c1c8327..afb06fd 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 64059a9..dfeb37a 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);
-- 
GitLab