Skip to content

Commit c3f17f3

Browse files
committed
refactoring et correction beug fermeture ui
1 parent 8da3fe7 commit c3f17f3

15 files changed

Lines changed: 163 additions & 439 deletions

File tree

lib/ai/ai.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "chessboard/move/move.h"
55
#include "chessboard/chessboardcontroller.h"
66
#include "evaluation.h"
7-
#include "transposition_tables.h"
87

98
#include "stdlib.h"
109
#include "string.h"
@@ -40,5 +39,3 @@ typedef struct
4039
/// @param board
4140
/// @return
4241
Move get_best_move(Chessboard board);
43-
44-
void initialise_ai(int color_ai);

lib/ai/evaluation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ int evaluate_position(Chessboard *board);
2121

2222
/// @brief Initialise les tables de position valeur utilisés pour l'évaluation des cases
2323
/// @return
24-
int initialize_tables();
24+
int initialize_tables(void);

lib/ai/transposition_tables.h

Lines changed: 0 additions & 45 deletions
This file was deleted.

lib/chessboard/bitboards/bitboard.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ uint64_t create_1bit_board(int exponent);
1111
void print_bitboard(uint64_t bitboard);
1212
uint64_t set_bit(uint64_t bitboard, int square);
1313
uint64_t pop_bit(uint64_t bb);
14-
unsigned int get_random_number();
15-
uint64_t get_random_bitboard();
14+
unsigned int get_random_number(void);
15+
uint64_t get_random_bitboard(void);
1616
uint64_t line_mask(int sq1, int sq2);
17-
void init_diag_masks();
17+
void init_diag_masks(void);
1818

1919
#endif

lib/chessboard/bitboards/masks.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extern uint64_t rook_masks[64];
1818
/// @brief Cette fonction permet d'initialiser les bitsmasks qui vont être un précalcul
1919
/// pour tout les coups possibles pour toutes les pieces. Ces coups sont stockés sous forme de bitboards
2020
/// en tant que variable globale.
21-
void init_bitboards();
21+
void init_bitboards(void);
2222

2323
/// @brief permet de récupérer les attaques possibles pour un fou grâce au tables de magic bitboards
2424
/// @param square le numéro de la case du fou
@@ -27,7 +27,7 @@ void init_bitboards();
2727
uint64_t get_bishop_attacks(int square, uint64_t occupancy);
2828
uint64_t get_rook_attacks(int square, uint64_t occupancy);
2929

30-
void save_globals_state();
31-
void check_globals_state();
30+
void save_globals_state(void);
31+
void check_globals_state(void);
3232

3333
#endif

src/ai/ai.c

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,6 @@
33
struct timespec t_start;
44
int max_time_ms = 100;
55

6-
static const int piece_value[7] = {
7-
0,
8-
900,
9-
320,
10-
330,
11-
100,
12-
500,
13-
INFINI,
14-
};
15-
16-
int compare_moves_desc(const void *a, const void *b)
17-
{
18-
return ((ScoredMove *)b)->score - ((ScoredMove *)a)->score;
19-
}
20-
21-
int get_value_piece(int square, Chessboard *board)
22-
{
23-
uint64_t piece_pos = create_1bit_board(square);
24-
if (board->pawns & piece_pos)
25-
return piece_value[PAWN];
26-
if (board->queens & piece_pos)
27-
return piece_value[QUEEN];
28-
if (board->knights & piece_pos)
29-
return piece_value[KNIGHT];
30-
if (board->bishops & piece_pos)
31-
return piece_value[BISHOP];
32-
if (board->rooks & piece_pos)
33-
return piece_value[ROOK];
34-
if (board->kings & piece_pos)
35-
return piece_value[KING];
36-
return 0;
37-
}
38-
396
typedef struct
407
{
418
Move best_move;
@@ -46,7 +13,7 @@ typedef struct
4613
* Recherche Alpha-Beta récursive
4714
* Retourne une évaluation numérique pour la position courante.
4815
*/
49-
int alpha_beta(Chessboard *board, int depth, int alpha, int beta, bool maximizingPlayer)
16+
static int alpha_beta(Chessboard *board, int depth, int alpha, int beta, bool maximizingPlayer)
5017
{
5118
if (depth == 0) // Rajouter une condition sur mat et pat
5219
{
@@ -104,7 +71,7 @@ int alpha_beta(Chessboard *board, int depth, int alpha, int beta, bool maximizin
10471
/**
10572
* Recherche le meilleur coup à une profondeur donnée.
10673
*/
107-
SearchResult search_best_move_alpha_beta(Chessboard *board, int depth)
74+
static SearchResult search_best_move_alpha_beta(Chessboard *board, int depth)
10875
{
10976
Move moves[250];
11077
int nb_moves = getalllegalmoves(board, moves);
@@ -145,9 +112,3 @@ Move get_best_move(Chessboard board)
145112
SearchResult best_move = search_best_move_alpha_beta(&board, 5);
146113
return best_move.best_move;
147114
}
148-
149-
void initialise_ai(int color_ai)
150-
{
151-
initialize_tables(color_ai);
152-
init_zobrist();
153-
}

src/ai/evaluation.c

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,7 @@ int king_table[BOARD_SIZE];
99

1010
int ally_color;
1111

12-
int abs(int x)
13-
{
14-
if (x >= 0)
15-
return x;
16-
return -x;
17-
}
18-
19-
int max(int a, int b)
20-
{
21-
if (a > b)
22-
return a;
23-
return b;
24-
}
25-
26-
int count_material(Chessboard *board, int *total_value)
12+
static int count_material(Chessboard *board, int *total_value)
2713
{
2814
int score = 0;
2915
*total_value = 0;
@@ -53,7 +39,7 @@ int count_material(Chessboard *board, int *total_value)
5339

5440

5541

56-
int evaluate_position_ally_pieces(Chessboard *board)
42+
static int evaluate_position_ally_pieces(Chessboard *board)
5743
{
5844
int score = 0;
5945

@@ -146,7 +132,7 @@ int evaluate_position(Chessboard *board)
146132
return -1 * score;
147133
}
148134

149-
int lire_piece_square_table(const char *nom_fichier, int valeurs[BOARD_SIZE])
135+
static int lire_piece_square_table(const char *nom_fichier, int valeurs[BOARD_SIZE])
150136
{
151137
FILE *f = fopen(nom_fichier, "r");
152138
if (!f)
@@ -178,8 +164,9 @@ int lire_piece_square_table(const char *nom_fichier, int valeurs[BOARD_SIZE])
178164
return 0; // succès
179165
}
180166

181-
int initialize_tables(int color_ai)
167+
int initialize_tables()
182168
{
169+
int color_ai = 0;
183170
ally_color = color_ai;
184171
if (lire_piece_square_table("assets/squares_pieces_tables/pawn.txt", pawn_table) != 0)
185172
return -1;

0 commit comments

Comments
 (0)