summaryrefslogtreecommitdiff
path: root/include/engine
diff options
context:
space:
mode:
Diffstat (limited to 'include/engine')
-rw-r--r--include/engine/moves.h36
-rw-r--r--include/engine/threads.h53
2 files changed, 72 insertions, 17 deletions
diff --git a/include/engine/moves.h b/include/engine/moves.h
index 86c4844..4032557 100644
--- a/include/engine/moves.h
+++ b/include/engine/moves.h
@@ -1,8 +1,8 @@
#ifndef MOVES_H
#define MOVES_H
-#include "../ints.h"
-#include "../bitboard.h"
+#include "ints.h"
+#include "bitboard.h"
typedef u8 square_t;
@@ -10,9 +10,9 @@ typedef u8 square_t;
// e4, Nf6, Qh3+, Qe1#, a8=Q, i need to store the information needed to
// recreate this in move_t
enum {
- MOVE_CAPTURE = 1,
- MOVE_SHORT_CASTLE = 1 << 1,
- MOVE_LONG_CASTLE = 1 << 2,
+ MOVE_CAPTURE = 1,
+ MOVE_SHORT_CASTLE = 1 << 1,
+ MOVE_LONG_CASTLE = 1 << 2,
// technically these promotation flags can be compressed to only use 2 bits..
MOVE_PROMOTE_Q = 1 << 3, // 1 << 5
@@ -28,10 +28,10 @@ typedef struct {
square_t to;
u16 flags;
} move_t;
-void position_make_move(position_t* position, move_t* move);
+void position_make_move(position_t *position, move_t *move);
typedef struct {
- move_t* moves;
+ move_t *moves;
u32 length;
u32 capacity;
} moves_t;
@@ -50,32 +50,34 @@ struct add_move_params {
(struct add_move_params) { .flags = 0, __VA_ARGS__ }\
)
void _add_move(
- moves_t* moves,
+ moves_t *moves,
square_t from,
square_t to,
struct add_move_params params
);
-void get_pawn_moves(moves_t* moves, position_t position);
-void get_knight_moves(moves_t* moves, position_t position);
-void get_king_moves(moves_t* moves, position_t position);
-void get_rook_moves(moves_t* moves, position_t position);
-void get_bishop_moves(moves_t* moves, position_t position);
-void get_queen_moves(moves_t* moves, position_t position);
+void get_pawn_moves(moves_t *moves, position_t position);
+void get_knight_moves(moves_t *moves, position_t position);
+void get_king_moves(moves_t *moves, position_t position);
+void get_rook_moves(moves_t *moves, position_t position);
+void get_bishop_moves(moves_t *moves, position_t position);
+void get_queen_moves(moves_t *moves, position_t position);
-void get_moves(moves_t* moves, position_t position);
+void get_moves(moves_t *moves, position_t position);
+#ifdef MOVES_INTERNAL
void __forloop_rook_moves_gen(
- moves_t* moves,
+ moves_t *moves,
bitboard_t friendly_type,
bitboard_t friendly_pieces,
bitboard_t enemy_pieces
);
void __forloop_bishop_moves_gen(
- moves_t* moves,
+ moves_t *moves,
bitboard_t friendly_type,
bitboard_t friendly_pieces,
bitboard_t enemy_pieces
);
+#endif // MOVES_INTERNAL
#endif // !MOVES_H
diff --git a/include/engine/threads.h b/include/engine/threads.h
new file mode 100644
index 0000000..4815a4c
--- /dev/null
+++ b/include/engine/threads.h
@@ -0,0 +1,53 @@
+#ifndef ENGINE_THREADS_H
+#define ENGINE_THREADS_H
+
+#include <pthread.h>
+#include <stdatomic.h>
+
+#include "bitboard.h"
+#include "ipc/engine_message.h"
+#include "ipc/go_args.h"
+
+struct thread_args {
+ // signal sent by threads manager
+ atomic_int stop;
+
+ // signal sent by thread
+ atomic_int finished;
+
+ int id;
+ position_t *position;
+ go_args_t *go_args;
+ engine_message_handler_t *message;
+};
+
+struct threads {
+ pthread_t *threads;
+ struct thread_args *args;
+ size_t count;
+ size_t capacity;
+
+ int running_count;
+ engine_messages_t *engine_messages;
+ go_args_t *go_args;
+ position_t *position;
+};
+
+#ifdef ENGINE_THREADS_INTERNAL
+void __threads_args_init(
+ struct thread_args* args,
+ struct threads *handler,
+ int i
+);
+#endif
+void threads_init(struct threads *handler, size_t capacity);
+void threads_deinit(struct threads *handler);
+void threads_reserve(struct threads *handler, size_t capacity);
+void threads_go(struct threads *handler);
+bool threads_go_loop(struct threads *handler);
+bool threads_all_done(struct threads *handler);
+void threads_cleanup(struct threads *handler);
+
+void *engine_thread(void *args);
+
+#endif // ENGINE_THREADS_H