better test
This commit is contained in:
parent
afcf0f07a4
commit
155d212a85
1 changed files with 45 additions and 11 deletions
52
src/test.c
52
src/test.c
|
@ -1,4 +1,5 @@
|
|||
#include "../includes/jeu.h"
|
||||
#include <time.h>
|
||||
|
||||
Test_Data *nouveau_test_data(int test, int profondeur) {
|
||||
Test_Data *res = malloc(sizeof(Test_Data));
|
||||
|
@ -12,23 +13,56 @@ Test_Data *nouveau_test_data(int test, int profondeur) {
|
|||
void free_test_data(Test_Data *test_data) { free(test_data); }
|
||||
|
||||
void run_tests(void) {
|
||||
printf("Test alphabeta...\n");
|
||||
int repetions = 5;
|
||||
int max_profondeur = 6;
|
||||
|
||||
printf("Lancement des tests, on va jusqu'à une profondeur de %d avec une "
|
||||
"moyenne de %d répétitions.\n",
|
||||
max_profondeur, repetions);
|
||||
|
||||
clock_t t0;
|
||||
double delta1, delta2;
|
||||
for (int i = 1; i < max_profondeur + 1; ++i) {
|
||||
delta1 = 0;
|
||||
for (int j = 0; j < repetions; ++j) {
|
||||
Jeu *jeu = nouvelle_partie();
|
||||
|
||||
Test_Data *test = nouveau_test_data(1, 8);
|
||||
Test_Data *test = nouveau_test_data(1, i);
|
||||
|
||||
clock_t ta, td;
|
||||
|
||||
td = clock();
|
||||
t0 = clock();
|
||||
|
||||
// Lance le jeu en mode test avec 2 alpha-bêta
|
||||
deroulement_partie(jeu, ALPHABETA, ALPHABETA, test);
|
||||
|
||||
ta = clock();
|
||||
|
||||
printf("Alphabêta : %ld\n", ta - td);
|
||||
delta1 += ((double)(clock() - t0)) / CLOCKS_PER_SEC;
|
||||
|
||||
free_jeu(jeu);
|
||||
|
||||
free_test_data(test);
|
||||
}
|
||||
delta1 /= repetions;
|
||||
|
||||
printf("Profondeur de %d (moyenne de %d tests) ->\t Alphabêta = %fs\t",
|
||||
i, repetions, delta1);
|
||||
|
||||
delta2 = 0;
|
||||
for (int j = 0; j < repetions; ++j) {
|
||||
Jeu *jeu = nouvelle_partie();
|
||||
|
||||
Test_Data *test = nouveau_test_data(1, i);
|
||||
|
||||
t0 = clock();
|
||||
|
||||
// Lance le jeu en mode test avec 2 alpha-bêta
|
||||
deroulement_partie(jeu, MINIMAX, MINIMAX, test);
|
||||
|
||||
delta2 += ((double)(clock() - t0)) / CLOCKS_PER_SEC;
|
||||
|
||||
free_jeu(jeu);
|
||||
free_test_data(test);
|
||||
}
|
||||
delta2 /= repetions;
|
||||
|
||||
printf("| Minimax = %fs\t | Différence (m - a) = %fs\n", delta2,
|
||||
delta2 - delta1);
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue