Skip to content
Snippets Groups Projects
Commit 4f3b7f4b authored by Vytor Calixto's avatar Vytor Calixto :space_invader:
Browse files

Muda heurística: para de usar o peso, usa só bônus

parent 6460a716
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -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 1 4 3 2 1 4 5 3 6 2 5 4 6 2 5 3 1 4 6 3 2 4 5 1 3 6 4 2 5 1 6 4 2 1 3 6 4 2 5 1 3 2 6 4 1 3 5 4 2 6 3 5 1 4 6 2 5 3 1 4 5 6 2 1 4 3 2 1 4 3 5 6 2 1
80
2 1 3 4 2 6 5 2 1 3 5 4 1 3 2 4 5 2 5 4 2 3 5 1 2 6 4 1 6 3 2 5 4 6 1 2 6 4 2 5 6 2 4 1 2 3 6 4 1 3 5 2 6 3 1 2 3 5 4 2 1 5 6 4 1 5 3 5 4 1 6 2 3 4 5 1 2 6 3 4
```
**Test 6- 100 100 6 2**
Our code gave the sequence:
```
186
5 2 1 5 3 2 4 1 4 2 3 1 4 5 6 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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
......@@ -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) {
......
......@@ -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;
}
......
......@@ -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'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment