From 4f3b7f4bb3865981b3a212b72dae029c710fdbe2 Mon Sep 17 00:00:00 2001
From: Vytor Calixto <vytorcalixto@gmail.com>
Date: Tue, 23 May 2017 15:32:30 -0300
Subject: [PATCH] =?UTF-8?q?Muda=20heur=C3=ADstica:=20para=20de=20usar=20o?=
 =?UTF-8?q?=20peso,=20usa=20s=C3=B3=20b=C3=B4nus?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 README.md               | 26 ++++++++++++++++++++------
 customTests/14x14-1.txt | 28 ++++++++++++++--------------
 floodit_exemplo.c       | 35 ++++++++++++++++++-----------------
 libs/jogador.c          | 23 +++++++++++++++++------
 tests/runTests.sh       |  4 ++--
 5 files changed, 71 insertions(+), 45 deletions(-)

diff --git a/README.md b/README.md
index b7461a5..4d6f9c6 100644
--- a/README.md
+++ b/README.md
@@ -56,8 +56,8 @@ It is a correct sequence, and it is a minimum answer.
 
 Our code gave the sequence:
 ```
-57
-1 3 1 2 4 1 2 3 4 2 3 1 3 4 1 2 1 3 4 2 3 1 2 4 3 1 2 4 2 1 3 4 2 1 4 3 2 1 3 4 1 2 4 3 1 2 3 1 4 3 4 2 3 1 2 4 3
+51
+1 3 1 2 4 1 2 3 4 2 3 1 3 4 1 2 1 3 4 3 2 1 4 2 3 4 2 4 1 3 2 4 1 2 3 1 4 2 1 3 4 1 2 4 1 4 2 3 1 4 2
 ```
 It is a correct sequence.
 
@@ -70,20 +70,34 @@ Our code gave the sequence:
 ```
 It is a correc sequence.
 
+**Test 14x14-1**
+
+Our code gave the sequence:
+```
+20
+2 1 2 3 5 2 1 5 4 6 3 4 6 2 6 3 1 5 4 2
+```
+It is a correct sequence, but the minimum sequence is:
+```
+19
+4 1 4 5 2 1 5 1 2 4 6 2 3 6 3 2 4 5 1
+```
+
+
 **--------------- NOT ANALYSED yet --------------**
 
 **Test 5- 50 50 6 2**
 
 Our code gave the sequence:
 ```
-86
-2 1 3 6 2 4 1 2 4 5 4 6 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 6 5 3 2 6 5 2 1 3 1 6 3 4 2 3 1 6 5 2 3 6 4 1 5 3 2 
 ```
diff --git a/customTests/14x14-1.txt b/customTests/14x14-1.txt
index 26b04c6..cfc40f2 100644
--- a/customTests/14x14-1.txt
+++ b/customTests/14x14-1.txt
@@ -1,15 +1,15 @@
 14 14 9
-    1     1     2     3     3     4     5     6     2     2     6     4     6     4 
-    4     5     1     1     2     3     3     5     2     2     6     5     3     2 
-    1     1     1     3     5     1     3     4     6     1     2     6     2     6 
-    2     4     4     4     5     5     1     1     5     1     1     1     6     3 
-    4     1     5     1     3     5     3     5     4     4     5     5     3     3 
-    4     6     3     3     6     2     6     3     6     4     1     2     3     1 
-    2     5     4     4     6     2     5     2     3     3     1     3     6     2 
-    6     3     2     1     5     1     3     6     2     3     3     6     4     5 
-    2     4     3     2     4     1     6     1     1     3     4     5     6     1 
-    1     5     3     1     2     5     5     5     1     2     4     2     2     3 
-    1     1     4     3     6     6     5     4     4     6     4     5     6     1 
-    1     2     2     6     5     1     2     6     5     5     4     1     2     4 
-    5     4     6     6     5     3     3     6     3     2     6     2     6     6 
-    4     2     3     3     3     2     2     2     6     2     2     4     3     2 
+1 1 2 3 3 4 5 5 2 2 6 4 6 4
+4 5 1 1 2 3 3 5 2 2 6 5 3 2
+1 1 1 3 5 1 3 4 6 1 2 6 2 6
+2 4 4 4 5 5 1 1 5 1 1 1 6 3
+4 1 5 1 3 5 3 5 4 4 5 5 3 3
+4 6 3 3 6 2 6 3 6 4 1 2 3 1
+2 5 4 4 6 2 5 2 3 3 1 3 6 2
+6 3 2 1 5 1 3 6 2 3 3 6 4 5
+2 4 3 2 4 1 6 1 1 3 4 5 6 1
+1 5 3 1 2 5 5 5 1 2 4 2 2 3
+1 1 4 3 6 6 5 4 4 6 4 5 6 1
+1 2 2 6 5 1 2 6 5 5 4 1 2 4
+5 4 6 6 5 3 3 6 3 2 6 2 6 6
+4 2 3 3 3 2 2 2 6 2 2 4 3 2
diff --git a/floodit_exemplo.c b/floodit_exemplo.c
index d84ef39..8443dbc 100644
--- a/floodit_exemplo.c
+++ b/floodit_exemplo.c
@@ -13,9 +13,9 @@ void gera_mapa(tmapa *m, int semente) {
   int i, j;
 
   if(semente < 0)
-    srand(time(NULL));  
+    srand(time(NULL));
   else
-    srand(semente);  
+    srand(semente);
   m->mapa = (int**) malloc(m->nlinhas * sizeof(int*));
   for(i = 0; i < m->nlinhas; i++) {
     m->mapa[i] = (int*) malloc(m->ncolunas * sizeof(int));
@@ -99,21 +99,22 @@ int main(int argc, char **argv) {
   tmapa m;
   int semente;
 
-  if(argc < 4 || argc > 5) {
-    printf("uso: %s <numero_de_linhas> <numero_de_colunas> <numero_de_cores> [<semente_aleatoria>]\n", argv[0]);
-    exit(1);
-  }
-
-  m.nlinhas = atoi(argv[1]);
-  m.ncolunas = atoi(argv[2]);
-  m.ncores = atoi(argv[3]);
-
-  if(argc == 5)
-    semente = atoi(argv[4]);
-  else
-    semente = -1;
-  gera_mapa(&m, semente);
-  mostra_mapa_cor(&m); 
+  // if(argc < 4 || argc > 5) {
+  //   printf("uso: %s <numero_de_linhas> <numero_de_colunas> <numero_de_cores> [<semente_aleatoria>]\n", argv[0]);
+  //   exit(1);
+  // }
+
+  // m.nlinhas = atoi(argv[1]);
+  // m.ncolunas = atoi(argv[2]);
+  // m.ncores = atoi(argv[3]);
+
+  // if(argc == 5)
+  //   semente = atoi(argv[4]);
+  // else
+  //   semente = -1;
+  // gera_mapa(&m, semente);
+  carrega_mapa(&m);
+  mostra_mapa_cor(&m);
 
   scanf("%d", &cor);
   while(cor > 0 && cor <= m.ncores) {
diff --git a/libs/jogador.c b/libs/jogador.c
index a89b831..5af134b 100644
--- a/libs/jogador.c
+++ b/libs/jogador.c
@@ -9,7 +9,7 @@ Lista Joga(Grafo g, Lista grupo){
     Lista jogadas = constroiLista();
     //TODO: A Logica toda do jogo vai ficar aqui
     int counter = 1;
-    do {
+    while(tamanhoLista(grupo) < tamanhoLista(g->vertices)) {
         // Pega os filhos do grupo
         Lista filhos = filhosGrupo(grupo);
         // Monta a árvore de busca:
@@ -18,6 +18,12 @@ Lista Joga(Grafo g, Lista grupo){
         //      - NETOS: Cores alcançáveis a partir dos filhos que NÃO são alcançáveis a partir da raiz
         //          Só é necessário para calcular o bônus de cada filho
         Lista coresFilhos = agrupaCores(filhos, g);
+        // printf("\tJOGADA %d\n", counter);
+        // printf("\tTamanho coresFilhos %d\n", tamanhoLista(coresFilhos));
+        // for(No n = primeiroNoLista(coresFilhos); n; n = getSucessorNo(n)) {
+        //     Vertice v = (Vertice) getConteudo(n);
+        //     printf("\t\tVértice - cor: %d, peso: %d, bonus: %d\n", v->cor, v->peso, v->bonus);
+        // }
         // Seleciona o melhor filho baseado em peso(filho) + bônus(filho) // (filho com a maior soma de filho e peso)
         // O bônus é calculado da seguinte forma:
         //      - Soma o valor de cada neto (que não é alcançável pela raiz)
@@ -29,10 +35,15 @@ Lista Joga(Grafo g, Lista grupo){
         for(No n = primeiroNoLista(coresFilhos); n; n = getSucessorNo(n)) {
             Vertice v = (Vertice) getConteudo(n);
             // TODO: tratar empates!
-            if((v->peso + v->bonus) > (maior->peso + maior->bonus)) {
+            if((/*v->peso + */v->bonus) > (/*maior->peso + */maior->bonus)) {
                 maior = v;
+            } else if((/*v->peso + */v->bonus) == (/*maior->peso + */maior->bonus)) {
+                if(v->peso > maior->peso) {
+                    maior = v;
+                }
             }
         }
+        // printf("\t\tCOR ESCOLHIDA: %d\n", maior->cor);
         insereLista(maior->cor, jogadas);
         // "Pinta o tablueiro"
         for(No n = primeiroNoLista(filhos); n; n = getSucessorNo(n)) {
@@ -47,7 +58,7 @@ Lista Joga(Grafo g, Lista grupo){
         destroiLista(filhos, NULL);
         destroiLista(coresFilhos, destroiVertice);
 
-        // // PARA DEBUG!! Imprime as últimas 10 jogadas em um arquivo
+        // PARA DEBUG!! Imprime as últimas 10 jogadas em um arquivo
         //  char str[32];
         //  sprintf(str, "./jogada%d.out", counter );
         //  FILE* debug = fopen(str, "w+");
@@ -56,7 +67,7 @@ Lista Joga(Grafo g, Lista grupo){
         //  }
         //  fclose(debug);
         //  ++counter;
-    } while(tamanhoLista(grupo) < tamanhoLista(g->vertices));
+    }
 
     return jogadas;
 }
@@ -100,7 +111,7 @@ Lista agrupaCores(Lista filhos, Grafo g) {
         }
     }
 
-    // Depois de agrupar, verifica se algum grupo vai chegar ao fim nesta jogada
+    // Depois de agrupar, verifica se alguma cor vai chegar ao fim nesta jogada
     for(No n = primeiroNoLista(agrupa); n; n = getSucessorNo(n)) {
         Vertice v = (Vertice) getConteudo(n);
         int somaCor = 0;
@@ -124,7 +135,7 @@ int calculaBonus(Vertice v, Lista filhos) {
     int bonus = 0;
     for(No n = primeiroNoLista(v->filhos); n; n = getSucessorNo(n)) {
         Vertice filho = getConteudo(n);
-        // Se o filho não está na lsita filhos e não está no grupo de vértices já consumidos
+        // Se o filho não está na lista filhos e não está no grupo de vértices já consumidos
         if(!filho->grupo && !pertenceLista(filho, filhos)) {
             bonus += filho->peso;
         }
diff --git a/tests/runTests.sh b/tests/runTests.sh
index 46c5f05..4bdc639 100755
--- a/tests/runTests.sh
+++ b/tests/runTests.sh
@@ -4,10 +4,10 @@
 tempo_max=10000 #10s
 
 # tamanhos do tabuleiro
-tams=(4 8 16 32 64 128)
+tams=(16 32 64 128)
 
 # lista de cores
-cores=(2 4 8 16)
+cores=(4 8 10 16)
 
 #-- Cores do terminal
 RED='\033[0;31m'
-- 
GitLab