summaryrefslogtreecommitdiff
path: root/plugins/entertain/entertain_chess.h
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/entertain/entertain_chess.h')
-rw-r--r--plugins/entertain/entertain_chess.h88
1 files changed, 88 insertions, 0 deletions
diff --git a/plugins/entertain/entertain_chess.h b/plugins/entertain/entertain_chess.h
new file mode 100644
index 0000000..9d7026c
--- /dev/null
+++ b/plugins/entertain/entertain_chess.h
@@ -0,0 +1,88 @@
+/*
+ * Entertain plugin — chess.h (internal)
+ * Chess game engine for HyBBX Entertain area.
+ */
+#ifndef ENTERTAIN_CHESS_H
+#define ENTERTAIN_CHESS_H
+
+#include "hybbx/types.h"
+
+struct hybbx_session;
+struct hybbx_service;
+
+#define CHESS_BOARD_SIZE 8
+#define CHESS_GAME_MAX 16
+#define CHESS_SPECTATOR_MAX 32
+#define CHESS_REFRESH_SEC 15
+#define CHESS_DEFAULT_MAX 8
+#define CHESS_NAME_MAX 32
+#define CHESS_SAN_MAX 8
+#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[CHESS_NAME_MAX];
+ char black_name[CHESS_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;
+
+/* Lifecycle */
+void chess_init(unsigned max_games);
+void chess_shutdown(void);
+unsigned chess_max_games(void);
+
+/* Game management */
+chess_game_t *chess_create_game(struct hybbx_session *white, const char *name);
+chess_game_t *chess_find_open_game(void);
+chess_game_t *chess_find_game_by_id(const char *id);
+chess_game_t *chess_get_game(unsigned index);
+int chess_join_game(chess_game_t *g, struct hybbx_session *black, const char *name);
+int chess_add_spectator(chess_game_t *g, struct hybbx_session *spec);
+void chess_remove_spectator(chess_game_t *g, struct hybbx_session *spec);
+int chess_is_player(const chess_game_t *g, const struct hybbx_session *s);
+int chess_is_spectator(const chess_game_t *g, const struct hybbx_session *s);
+chess_color_t chess_player_color(const chess_game_t *g, const struct hybbx_session *s);
+
+/* Session slot (for future use) */
+unsigned chess_session_slot(const struct hybbx_session *s);
+void chess_session_set_slot(struct hybbx_session *s, unsigned slot);
+
+/* Moves + display */
+int chess_make_move(chess_game_t *g, const char *from, const char *to,
+ char promote, char *err, size_t errlen);
+void chess_send_board(chess_game_t *g, struct hybbx_session *s);
+void chess_resign(chess_game_t *g, struct hybbx_session *who);
+void chess_offer_draw(chess_game_t *g, struct hybbx_session *who);
+
+/* Tick — call from plugin tick every 1s */
+void chess_tick(struct hybbx_service *service);
+
+#endif /* ENTERTAIN_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