This is the doxygen documentation for gtkboard.

.
Main Page   Data Structures   File List   Data Fields   Globals  

game.h

Go to the documentation of this file.
00001 /*  This file is a part of gtkboard, a board games system.
00002     Copyright (C) 2003, Arvind Narayanan <arvindn@users.sourceforge.net>
00003 
00004     This program is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or
00007     (at your option) any later version.
00008 
00009     This program is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with this program; if not, write to the Free Software
00016     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
00017 
00018 */
00019 #ifndef _GAME_H_
00020 #define _GAME_H_
00021 
00022 #include<glib.h>
00023 
00030 
00031 #ifndef byte 
00032 #define byte gint8
00033 #endif
00034 
00036 /* White is always the player that moves first. Internally they
00037  are always called white and black even if the game wants the user to
00038  see them as red and blue, or Bob and Sue etc.*/
00039 typedef enum {WHITE, BLACK} Player;
00040 
00042 
00043 typedef enum 
00044 {
00045         GTKBOARD_BUTTON_PRESS = 1, 
00046         GTKBOARD_BUTTON_RELEASE, 
00047         GTKBOARD_MOTION_NOTIFY,
00048         GTKBOARD_LEAVE_NOTIFY,
00049         GTKBOARD_KEY_PRESS,
00050         GTKBOARD_KEY_RELEASE,
00051         GTKBOARD_GAME_START,
00052         GTKBOARD_HUMAN_MOVE,
00053         GTKBOARD_MACHINE_MOVE,
00054         GTKBOARD_HISTORY_MOVE
00055 } GtkboardEventType;
00056 
00058 typedef struct 
00059 {
00061         GtkboardEventType type;
00062 
00064         int x;
00065 
00066         // y coordinate of the cell
00067         int y;
00068 
00070         int pixel_x;
00071 
00073         int pixel_y;
00074 
00076         int key;
00077 
00079         byte *move;
00080 } GtkboardEvent;
00081 
00083 typedef enum 
00084 {
00086         RESULT_WHITE, 
00088         RESULT_BLACK, 
00090         RESULT_TIE, 
00092         RESULT_NOTYET,
00094         RESULT_WON,
00096 
00097         RESULT_LOST,
00099         RESULT_MISC
00100 } ResultType;
00101 
00103 typedef enum
00104 {
00105         INPUT_ILLEGAL = -1,
00106         INPUT_NOTYET = 0,
00107         INPUT_LEGAL = 1
00108 } InputType;
00109 
00111 typedef struct
00112 {
00114 
00117         byte *move;
00118 
00120         int *rmove;
00122 
00123         gchar *custom;
00124 
00126         gchar *help_message;
00127 
00129         gchar *human_readable;
00130 }MoveInfo;
00131 
00133 typedef enum {FILERANK_LABEL_TYPE_NONE, FILERANK_LABEL_TYPE_NUM, FILERANK_LABEL_TYPE_ALPHA, FILERANK_LABEL_TYPE_ALPHA_CAPS} FILERANK_LABEL_TYPE;
00134 
00135 #define FILERANK_LABEL_TYPE_MASK 0x3
00136 
00138 #define FILERANK_LABEL_DESC (1 << 2)
00139 
00141 #define GAME_EVAL_INFTY (1.0e10)
00142 
00144 #define ISINBOARD(x,y) ((x)>=0 && (y)>=0 && (x)<board_wid && (y)< board_heit)
00145 
00147 #define GAME_DEFAULT_URL(x) "http://gtkboard.sourceforge.net/showgame.pl?game="x
00148 
00150 
00156 typedef struct
00157 {
00159         int cell_size;
00160 
00162         int board_wid;
00163 
00165         int board_heit;
00166 
00168 
00175         int num_pieces;
00176 
00178         char *colors;
00179 
00181         int * init_pos;
00182 
00184         char *** pixmaps;
00185 
00186         char *name;
00188         void (*game_init) ();
00189 }Game;
00190 
00192 typedef enum 
00193 {
00195         RENDER_NONE, 
00197         RENDER_HIGHLIGHT1, RENDER_HIGHLIGHT2, RENDER_HIGHLIGHT3,
00199         RENDER_SHADE1, RENDER_SHADE2, RENDER_SHADE3,
00201         RENDER_BUTTONIZE,
00203         RENDER_HIDE,
00205 
00208         RENDER_REPLACE,
00209 } RenderType;
00210 
00212 typedef struct
00213 {
00215 
00220         byte *board;
00221 
00223 
00224         /* A note on why this is int* while board is byte*: the latter will
00225          be used by the engine, and so size is important. But render can be 
00226          big because it will be used only by the engine which will have only
00227          once instance of Pos*/
00228         int *render;
00229 
00231 
00233         Player player;
00234 
00236 
00242         void *state;
00243 
00245 
00246         int num_moves;
00247 
00249         void *ui_state;
00250 }Pos;
00251 
00253 typedef struct
00254 {
00256         char *name;
00257 
00259         float (*eval_fun) (Pos *, int);
00260 
00262         char *comment;
00263 
00265         char *args;
00266 }HeurTab;
00267 
00269 
00271 extern ResultType (*game_eval) (Pos *pos, Player player, float *eval);
00272 
00274 
00283 extern ResultType (*game_eval_incr) (Pos *pos, Player player, byte *move, float *eval);
00284 
00286 extern gboolean (*game_use_incr_eval) (Pos *pos, Player player);
00287 
00289 extern void (*game_search) (Pos *pos, byte **move);
00290 
00292 
00302 extern byte * (*game_movegen) (Pos *);
00303 
00304 
00306 
00317 extern int (*game_getmove) (Pos *pos, int x, int y, GtkboardEventType type, Player to_play, byte ** movp, int **renderp);
00318 
00320 
00321 extern InputType (*game_event_handler) (Pos *pos, GtkboardEvent *event, MoveInfo *move_info_p);
00322 
00324 
00330 extern int (*game_getmove_kb) (Pos *pos, int key, Player to_play, byte ** movp, int **rmovp);
00331 
00333 
00336 extern ResultType (*game_who_won) (Pos *pos, Player player, char ** scorep);
00337 
00339 
00340 extern void (*game_set_init_pos) (Pos *pos);
00341 
00343 extern void (*game_set_init_render) (Pos *pos);
00344 
00346 extern void (*game_get_render) (Pos *pos, byte *move, int **rmovp);
00347 
00349 
00350 extern char ** (*game_get_pixmap) (int piece, int color);
00351 
00353 extern guchar * (*game_get_rgbmap) (int piece, int color);
00354 
00356 extern int (*game_animate) (Pos *pos, byte ** movp);
00357 
00359 
00360 extern void * (*game_newstate) (Pos *pos, byte * move);
00361 
00363 extern void (*game_free) ();
00364 
00366 //extern void game_set_init_pos_def (Pos *);
00367 
00369 
00371 extern void (*game_reset_uistate) ();
00372 
00373 extern int board_wid, board_heit, cell_size, num_pieces;
00374 
00376 extern int game_single_player;
00377 
00379 extern gboolean game_allow_undo;
00380 
00382 extern int game_animation_time;
00383 
00385 extern gboolean game_animation_use_movstack;
00386 
00388 extern gboolean game_stateful;
00389 
00391 
00393 extern gboolean game_draw_cell_boundaries;
00394 
00396 extern char *game_highlight_colors;
00397 
00399 
00401 extern gboolean game_allow_back_forw;
00402 
00404 
00405 extern gboolean game_start_immediately;
00406 
00408 extern gboolean game_allow_flip;
00409 
00411 extern gboolean game_file_label, game_rank_label;
00412         
00414 
00415 extern int game_state_size;
00416 
00418 extern HeurTab *game_htab;
00419 
00421 extern gchar *game_doc_about;
00423 extern gchar *game_doc_rules;
00425 extern gchar *game_doc_strategy;
00426 
00428 extern gchar *game_white_string, *game_black_string;
00429 
00430 
00432 extern char ** game_bg_pixmap;
00433 
00434 
00436 
00438 typedef enum {
00439         SCORE_FIELD_NONE, 
00440         SCORE_FIELD_RANK, SCORE_FIELD_USER, SCORE_FIELD_SCORE, SCORE_FIELD_TIME, SCORE_FIELD_DATE, 
00441         SCORE_FIELD_MISC1, SCORE_FIELD_MISC2
00442 } SCORE_FIELD;
00443 
00445 
00446 extern SCORE_FIELD * game_score_fields;
00447 
00449 
00450 extern gchar **game_score_field_names;
00451 
00453 
00457 extern int (*game_scorecmp) (gchar *, int, gchar*, int);
00458 
00460 extern int (*game_scorecmp_def_dscore) (gchar *, int, gchar*, int);
00462 extern int (*game_scorecmp_def_iscore) (gchar *, int, gchar*, int);
00464 extern int (*game_scorecmp_def_time) (gchar *, int, gchar*, int);
00465 
00466 #endif