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

[ci skip] Limpando o código para a entrega

parent a43643b0
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -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);
}
}
......
......@@ -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;
}
......@@ -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);
......
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