summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorscw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2005-08-08 04:21:12 +0800
committerscw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2005-08-08 04:21:12 +0800
commitf9f4c71a8beec3d7c2931a266d3df20d00abaeba (patch)
treee4ca0bb95cc1a5bbd1dd0724ba73348112c7b604 /include
parentb3bb4b2108f3c2d60bb005fd63dafc5e8a72045a (diff)
downloadpttbbs-f9f4c71a8beec3d7c2931a266d3df20d00abaeba.tar
pttbbs-f9f4c71a8beec3d7c2931a266d3df20d00abaeba.tar.gz
pttbbs-f9f4c71a8beec3d7c2931a266d3df20d00abaeba.tar.bz2
pttbbs-f9f4c71a8beec3d7c2931a266d3df20d00abaeba.tar.lz
pttbbs-f9f4c71a8beec3d7c2931a266d3df20d00abaeba.tar.xz
pttbbs-f9f4c71a8beec3d7c2931a266d3df20d00abaeba.tar.zst
pttbbs-f9f4c71a8beec3d7c2931a266d3df20d00abaeba.zip
New chess framework
* Provides common parts of all chess games * Chinese chess fully ported * Improved watching * Leaving possibility to implement replaying !!!NOTE!!! Protocal not backward compatible, STOP ALL clients before upgrade. git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3002 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'include')
-rw-r--r--include/bbs.h1
-rw-r--r--include/chc.h6
-rw-r--r--include/chess.h175
-rw-r--r--include/proto.h3
-rw-r--r--include/pttstruct.h5
5 files changed, 184 insertions, 6 deletions
diff --git a/include/bbs.h b/include/bbs.h
index 326fd49c..81be4808 100644
--- a/include/bbs.h
+++ b/include/bbs.h
@@ -52,6 +52,7 @@ typedef time_t time4_t;
#include "perm.h"
#include "modes.h"
#include "chc.h"
+#include "chess.h"
#include "proto.h"
#ifdef ASSESS
diff --git a/include/chc.h b/include/chc.h
index 7ae4257b..31aa49bc 100644
--- a/include/chc.h
+++ b/include/chc.h
@@ -59,3 +59,9 @@ typedef struct chc_act_list{
struct chc_act_list *next;
} chc_act_list;
+#define BRD_ROW 10
+#define BRD_COL 9
+
+typedef int board_t[BRD_ROW][BRD_COL];
+typedef int (*board_p)[BRD_COL];
+
diff --git a/include/chess.h b/include/chess.h
new file mode 100644
index 00000000..82b72a6e
--- /dev/null
+++ b/include/chess.h
@@ -0,0 +1,175 @@
+/* $Id$ */
+
+#ifndef INCLUDE_CHESS_H
+#define INCLUDE_CHESS_H
+
+#define CHESS_DRAWING_TIME_ROW 128
+#define CHESS_DRAWING_TURN_ROW 129
+#define CHESS_DRAWING_WARN_ROW 130
+#define CHESS_DRAWING_STEP_ROW 131
+#define CHESS_DRAWING_HELP_ROW 132
+
+#define CHESS_PHOTO_LINE 15
+#define CHESS_PHOTO_COLUMN (256 + 25)
+
+struct ChessBroadcastList;
+struct ChessActions;
+struct ChessConstants;
+
+#define const
+#define static
+#define private
+
+typedef struct {
+ char userid[IDLEN + 1];
+ int win;
+ int lose;
+ int tie;
+ unsigned short rating;
+ unsigned short orig_rating; // 原始 rating, 因為遊戲開始先算輸一場, rating 值就跑掉了
+} ChessUser;
+
+private typedef struct {
+ int used;
+ int size;
+ void *body;
+} ChessHistory;
+
+private typedef struct ChessBroadcastListNode {
+ int sock;
+ struct ChessBroadcastListNode *next;
+} ChessBroadcastListNode;
+
+private typedef struct ChessBroadcastList {
+ struct ChessBroadcastListNode head; /* dummy node */
+} ChessBroadcastList;
+
+
+typedef struct {
+ int limit_hand;
+ int limit_time;
+ int free_time;
+ enum {
+ CHESS_TIMEMODE_MULTIHAND, /* 限時限步 */
+ CHESS_TIMEMODE_COUNTING /* 讀秒 */
+ } time_mode;
+} ChessTimeLimit;
+
+typedef enum {
+ CHESS_MODE_VERSUS, /* 對奕 */
+ CHESS_MODE_WATCH, /* 觀棋 */
+ CHESS_MODE_PERSONAL, /* 打譜 */
+ CHESS_MODE_REPLAY /* 看譜 */
+} ChessGameMode;
+
+typedef enum {
+ CHESS_RESULT_CONTINUE,
+ CHESS_RESULT_WIN,
+ CHESS_RESULT_LOST,
+ CHESS_RESULT_TIE,
+ CHESS_RESULT_END /* watching or replaying */
+} ChessGameResult;
+
+typedef struct ChessInfo {
+ private const static
+ struct ChessActions* actions; /* vtable */
+ private const static
+ struct ChessConstants* constants;
+
+ rc_t cursor;
+
+ /* 計時用, [0] = mine, [1] = his */
+ int lefttime[2];
+ int lefthand[2]; /* 限時限步時用, = 0 表為自由時間或非限時限步模式 */
+ const ChessTimeLimit* timelimit;
+
+ const ChessGameMode mode;
+ const ChessUser user1;
+ const ChessUser user2;
+ const char my; /* 我方顏色 */
+
+ char turn;
+ char ipass, hepass;
+ char warnmsg[64];
+ char last_movestr[36];
+ char *photo;
+
+ void *board;
+ void *tag;
+
+ private int sock;
+ private ChessHistory history;
+ private ChessBroadcastList broadcast_list;
+ private ChessGameResult (*play_func[2])(struct ChessInfo* info);
+
+ private int current_step; /* used by watch and replay */
+ private char step_tmp[0];
+} ChessInfo;
+
+#undef const
+#undef static
+#undef private
+
+typedef struct ChessActions {
+ /* initial */
+ void (*init_user) (const userec_t* rec, ChessUser* user);
+ void (*init_board) (const ChessInfo* info, void* board);
+
+ /* playing */
+ void (*drawline) (const ChessInfo* info, int line);
+ void (*movecur) (int r, int c);
+ void (*prepare_play)(ChessInfo* info);
+ int (*select) (ChessInfo* info, rc_t location,
+ ChessGameResult* result);
+ void (*prepare_step)(ChessInfo* info, const void* step);
+ int (*apply_step) (void* board, const void* step);
+ void (*drawstep) (ChessInfo* info, const void* step);
+
+ /* ending */
+ void (*gameend) (ChessInfo* info, ChessGameResult result);
+ void (*genlog) (ChessInfo* info, FILE* fp, ChessGameResult result);
+} ChessActions;
+
+typedef struct ChessConstants {
+ int step_entry_size;
+ int traditional_timeout;
+ int board_height;
+ int board_width;
+ char *photo_file_name;
+ char *log_board;
+ char *turn_color[2];
+ char *turn_str[2];
+} ChessConstants;
+
+typedef enum {
+ CHESS_STEP_NORMAL, CHESS_STEP_PASS,
+ CHESS_STEP_DROP, CHESS_STEP_FAILURE,
+ CHESS_STEP_NOP /* for wake up */
+} ChessStepType;
+
+
+int ChessTimeCountDown(ChessInfo* info, int who, int length);
+void ChessStepMade(ChessInfo* info, int who);
+
+ChessStepType ChessStepReceive(ChessInfo* info, void* step);
+int ChessStepSendOpposite(ChessInfo* info, const void* step);
+void ChessStepBroadcast(ChessInfo* info, const void* step);
+int ChessStepSend(ChessInfo* info, const void* step);
+
+void ChessHistoryAppend(ChessInfo* info, void* step);
+const void* ChessHistoryRetrieve(ChessInfo* info, int n);
+
+void ChessPlay(ChessInfo* info);
+int ChessStartGame(char func_char, int sig, const char* title);
+int ChessWatchGame(void (*play)(int, ChessGameMode),
+ int game, const char* title);
+
+ChessInfo* NewChessInfo(const ChessActions* actions,
+ const ChessConstants* constants, int sock, ChessGameMode mode);
+void DeleteChessInfo(ChessInfo* info);
+
+void ChessEstablishRequest(int sock);
+void ChessAcceptingRequest(int sock);
+void ChessShowRequest(void);
+
+#endif /* INCLUDE_CHESS_H */
diff --git a/include/proto.h b/include/proto.h
index d4e8c785..932933ab 100644
--- a/include/proto.h
+++ b/include/proto.h
@@ -192,7 +192,7 @@ int card_99(void);
int t_chat(void);
/* chc */
-void chc(int s, int mode);
+void chc(int s, ChessGameMode mode);
int chc_main(void);
int chc_personal(void);
int chc_watch(void);
@@ -331,6 +331,7 @@ int x_love(void);
/* mail */
int load_mailalert(const char *userid);
+int mailalert(const char *userid);
int mail_muser(const userec_t muser, const char *title, const char *filename);
int mail_id(const char* id, const char *title, const char *filename, const char *owner);
int m_read(void);
diff --git a/include/pttstruct.h b/include/pttstruct.h
index 8837f814..05025248 100644
--- a/include/pttstruct.h
+++ b/include/pttstruct.h
@@ -608,11 +608,6 @@ typedef struct {
int r, c;
} rc_t;
-#define BRD_ROW 10
-#define BRD_COL 9
-
-typedef int board_t[BRD_ROW][BRD_COL];
-
/* name.c 中運用的資料結構 */
typedef struct word_t {
char *word;