summaryrefslogtreecommitdiff
path: root/include/hybbx
diff options
context:
space:
mode:
authorinfo@mode42.com <info@mode42.com>2026-08-09 05:27:00 +0000
committerinfo@mode42.com <info@mode42.com>2026-08-09 05:27:00 +0000
commit1cad8f1308e4af86027f9ae25523b8a8b3f6592c (patch)
tree7fa911b052986a69728343a09f8dde3d1c206c9b /include/hybbx
parent20cb29c2f8c5c87bc590896854a20b1473ceb358 (diff)
Next development steps
Diffstat (limited to 'include/hybbx')
-rw-r--r--include/hybbx/chess.h105
1 files changed, 105 insertions, 0 deletions
diff --git a/include/hybbx/chess.h b/include/hybbx/chess.h
new file mode 100644
index 0000000..beb1fe9
--- /dev/null
+++ b/include/hybbx/chess.h
@@ -0,0 +1,105 @@
+#ifndef HYBBX_CHESS_H
+#define HYBBX_CHESS_H
+
+#include "hybbx/types.h"
+#include "hybbx/limits.h"
+#include "hybbx/storage.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define CHESS_BOARD_SIZE 8
+#define CHESS_SQ_MAX 4
+#define CHESS_MOVE_MAX 8
+#define CHESS_SAN_MAX 8
+#define CHESS_GAME_MAX 16 /* array upper bound */
+#define CHESS_SPECTATOR_MAX 32
+#define CHESS_REFRESH_SEC 15
+#define CHESS_DEFAULT_MAX 8 /* default active games if INI omits [chess] */
+
+#define CHESS_EMPTY '.'
+
+typedef enum {
+ CHESS_COLOR_NONE = 0,
+ CHESS_WHITE,
+ CHESS_BLACK
+} chess_color_t;
+
+typedef enum {
+ CHESS_RESULT_NONE = 0,
+ CHESS_WHITE_WINS,
+ CHESS_BLACK_WINS,
+ CHESS_DRAW_STALEMATE,
+ CHESS_DRAW_AGREEMENT
+} chess_result_t;
+
+typedef struct chess_board {
+ char sq[CHESS_BOARD_SIZE][CHESS_BOARD_SIZE];
+} chess_board_t;
+
+typedef struct chess_game {
+ int active;
+ char white_name[HYBBX_USER_NAME_MAX];
+ char black_name[HYBBX_USER_NAME_MAX];
+ struct hybbx_session *white_session;
+ struct hybbx_session *black_session;
+ struct hybbx_session *spectators[CHESS_SPECTATOR_MAX];
+ unsigned spectator_count;
+ chess_board_t board;
+ chess_color_t turn;
+ unsigned move_number;
+ chess_result_t result;
+ char last_move_san[CHESS_SAN_MAX];
+ unsigned tick_counter;
+ char game_id[8];
+} chess_game_t;
+
+void hybbx_chess_init(void);
+void hybbx_chess_shutdown(void);
+void hybbx_chess_config_apply(const struct hybbx_config *config);
+unsigned hybbx_chess_max_games(void);
+void hybbx_chess_shutdown(void);
+
+chess_game_t *hybbx_chess_create_game(struct hybbx_session *white,
+ const char *white_name);
+chess_game_t *hybbx_chess_find_open_game(void);
+chess_game_t *hybbx_chess_find_game_by_id(const char *id);
+chess_game_t *hybbx_chess_get_game(unsigned index);
+int hybbx_chess_join_game(chess_game_t *game,
+ struct hybbx_session *black,
+ const char *black_name);
+int hybbx_chess_add_spectator(chess_game_t *game,
+ struct hybbx_session *spec);
+void hybbx_chess_remove_spectator(chess_game_t *game,
+ struct hybbx_session *spec);
+int hybbx_chess_is_player(const chess_game_t *game,
+ const struct hybbx_session *session);
+int hybbx_chess_is_spectator(const chess_game_t *game,
+ const struct hybbx_session *session);
+chess_color_t hybbx_chess_player_color(const chess_game_t *game,
+ const struct hybbx_session *session);
+int hybbx_chess_make_move(chess_game_t *game,
+ const char *from, const char *to,
+ char promote, char *err, size_t errlen);
+void hybbx_chess_render_board(const chess_board_t *board,
+ struct hybbx_session *session,
+ const char *label);
+void hybbx_chess_send_board(chess_game_t *game,
+ struct hybbx_session *session);
+void hybbx_chess_tick(struct hybbx_service *service);
+void hybbx_chess_resign(chess_game_t *game,
+ struct hybbx_session *who);
+void hybbx_chess_offer_draw(chess_game_t *game,
+ struct hybbx_session *who);
+
+/* Command handler - called from command.c dispatch */
+hybbx_result_t cmd_chess(struct hybbx_service *service,
+ struct hybbx_session *session,
+ const struct hybbx_parsed_command *cmd);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* HYBBX_CHESS_H */
git clone -b <branch> https://cgit.mode42.com/<repo>.git
git clone -b <branch> git://cgit.mode42.com/<repo>.git

info@mode42.com