This is the doxygen documentation for gtkboard.

.
Main Page   Data Structures   File List   Data Fields   Globals  

game.h File Reference

Header file that must be included by all games. More...

#include <glib.h>

Go to the source code of this file.

Data Structures

struct  Game
 The Game struct gives essential information about the game. More...

struct  GtkboardEvent
 Abstraction of a user event. More...

struct  HeurTab
 If you have implemented more than one evaluation function then you put them in an array of structs of type HeurTab. Its unlikely that you'll need to know about this. See game_htab for more details. More...

struct  MoveInfo
 The move and all the info. associated with it. More...

struct  Pos
 A struct describing a position in a game. More...


Defines

#define byte   gint8
 Both moves and positions are arrays of bytes.

#define FILERANK_LABEL_TYPE_MASK   0x3
#define FILERANK_LABEL_DESC   (1 << 2)
 if game_file_label or game_rank_label is ORed with this the order of file/rank labels will be reversed.

#define GAME_EVAL_INFTY   (1.0e10)
 The return value of game_eval should be larger than GAME_EVAL_INFTY in absolute value to indicate that the game is over.

#define ISINBOARD(x, y)   ((x)>=0 && (y)>=0 && (x)<board_wid && (y)< board_heit)
 Indicates whether the square (x, y) is legal.

#define GAME_DEFAULT_URL(x)   "http://gtkboard.sourceforge.net/showgame.pl?game="x
 Home page for the game x.


Enumerations

enum  Player { WHITE, BLACK }
 Used in a two player game to represent whose move it is. More...

enum  GtkboardEventType {
  GTKBOARD_BUTTON_PRESS = 1, GTKBOARD_BUTTON_RELEASE, GTKBOARD_MOTION_NOTIFY, GTKBOARD_LEAVE_NOTIFY,
  GTKBOARD_KEY_PRESS, GTKBOARD_KEY_RELEASE, GTKBOARD_GAME_START, GTKBOARD_HUMAN_MOVE,
  GTKBOARD_MACHINE_MOVE, GTKBOARD_HISTORY_MOVE
}
 Used for representing the type of user input in game_getmove and game_getmove_kb. More...

enum  ResultType {
  RESULT_WHITE, RESULT_BLACK, RESULT_TIE, RESULT_NOTYET,
  RESULT_WON, RESULT_LOST, RESULT_MISC
}
 Used for representing the result of game_who_won. More...

enum  InputType { INPUT_ILLEGAL = -1, INPUT_NOTYET = 0, INPUT_LEGAL = 1 }
 The return type of game_event_handler. More...

enum  FILERANK_LABEL_TYPE { FILERANK_LABEL_TYPE_NONE, FILERANK_LABEL_TYPE_NUM, FILERANK_LABEL_TYPE_ALPHA, FILERANK_LABEL_TYPE_ALPHA_CAPS }
 values of game_file_label and game_rank_label. More...

enum  RenderType {
  RENDER_NONE, RENDER_HIGHLIGHT1, RENDER_HIGHLIGHT2, RENDER_HIGHLIGHT3,
  RENDER_SHADE1, RENDER_SHADE2, RENDER_SHADE3, RENDER_BUTTONIZE,
  RENDER_HIDE, RENDER_REPLACE
}
 How to render a square. More...

enum  SCORE_FIELD {
  SCORE_FIELD_NONE, SCORE_FIELD_RANK, SCORE_FIELD_USER, SCORE_FIELD_SCORE,
  SCORE_FIELD_TIME, SCORE_FIELD_DATE, SCORE_FIELD_MISC1, SCORE_FIELD_MISC2
}
 The columns that will be shown in the highscores. More...


Variables

ResultType (* game_eval )(Pos *pos, Player player, float *eval)
 A pointer to the game's evaluation function. More...

ResultType (* game_eval_incr )(Pos *pos, Player player, byte *move, float *eval)
 A pointer to the game's incremental evaluation function. More...

gboolean (* game_use_incr_eval )(Pos *pos, Player player)
 Should we use the incr eval function.

void (* game_search )(Pos *pos, byte **move)
 A function to search and return the best move - for games for which minimax is not appropriate.

byte* (* game_movegen )(Pos *)
 A pointer to the game's move generation function. More...

int (* game_getmove )(Pos *pos, int x, int y, GtkboardEventType type, Player to_play, byte **movp, int **renderp)
 This takes a mouse click and returns the move that it corresponds to. More...

InputType (* game_event_handler )(Pos *pos, GtkboardEvent *event, MoveInfo *move_info_p)
 The all-in-one function that makes game_getmove and game_getmove_kb deprecated.

int (* game_getmove_kb )(Pos *pos, int key, Player to_play, byte **movp, int **rmovp)
 Takes a keypress and returns the move that it corresponds to. More...

ResultType (* game_who_won )(Pos *pos, Player player, char **scorep)
 Checks if the game is over, and if so, who has won. More...

void (* game_set_init_pos )(Pos *pos)
 Pointer to function which sets the game's initial position. More...

void (* game_set_init_render )(Pos *pos)
 Sets the initial state of the rendering hints.

void (* game_get_render )(Pos *pos, byte *move, int **rmovp)
 The rendering hints associated with the move.

char** (* game_get_pixmap )(int piece, int color)
 Returns the pixmap for a piece. More...

guchar* (* game_get_rgbmap )(int piece, int color)
 Same as game_get_pixmap but returns a rgbmap instead of pixmap.

int (* game_animate )(Pos *pos, byte **movp)
 Pointer to animation callback which will be called periodically.

void* (* game_newstate )(Pos *pos, byte *move)
 Pointer to function which will compute the new state from the current position and the move. More...

void (* game_free )()
 Called at the end of every game.

void (* game_reset_uistate )()
 This is called after each move the user completes. More...

int board_wid
int board_heit
int cell_size
int num_pieces
int game_single_player
 Are we a single player game or a two-player game? DEFAULT: FALSE.

gboolean game_allow_undo
 Is the user allowed to undo move and still get on the highscores (only for single player games; default: FALSE).

int game_animation_time
 Determines how frequently to call the game's animation callback function (game_animate). Default: 0.

gboolean game_animation_use_movstack
 Whether or not to consider animations "moves". Default: TRUE.

gboolean game_stateful
 Are we a stateful game. Default: FALSE.

gboolean game_draw_cell_boundaries
 Should the lines between the rows and columns be drawn. Default: FALSE. More...

char* game_highlight_colors
 Colors to use for highlighting squares.

gboolean game_allow_back_forw
 Should we allow the user to move back and forward in the game. Default: TRUE. More...

gboolean game_start_immediately
 Should the user's clock start ticking as soon as the game is selected. Default: FALSE. More...

gboolean game_allow_flip
 (Only for two player games) Is Settings->Flip Board active. For single player games it is always inactive.

gboolean game_file_label
 How to display names of rows and columns. This should be of type FILERANK_LABEL_TYPE, optionally ORed with FILERANK_LABEL_DESC.

gboolean game_rank_label
 How to display names of rows and columns. This should be of type FILERANK_LABEL_TYPE, optionally ORed with FILERANK_LABEL_DESC.

int game_state_size
 Size of the Pos::state structure. More...

HeurTabgame_htab
 Array of structs representing evaluation functions.

gchar* game_doc_about
 The text to be shown in the About dialog for the game (Help->GameName->About).

gchar* game_doc_rules
 The text to be shown in the Rules dialog for the game (Help->GameName->Rules).

gchar* game_doc_strategy
 The text to be shown in the Strategy dialog for the game (Help->GameName->Strategy).

gchar* game_white_string
 User visible labels for white and black.

gchar * game_black_string
 User visible labels for white and black.

char** game_bg_pixmap
 Background image for the board.

SCORE_FIELDgame_score_fields
 Used to override the default highscore columns. More...

gchar** game_score_field_names
 The names of the column titles in the highscores. More...

int (* game_scorecmp )(gchar *, int, gchar *, int)
 Pointer to the comparison function used to order highscores. More...

int (* game_scorecmp_def_dscore )(gchar *, int, gchar *, int)
 Default highscore comparison function: decreasing order of Score field.

int (* game_scorecmp_def_iscore )(gchar *, int, gchar *, int)
 Default highscore comparison function: increasing order of Score field.

int (* game_scorecmp_def_time )(gchar *, int, gchar *, int)
 Default highscore comparison function: increasing order of Time field.


Detailed Description

Header file that must be included by all games.

This is the only file that the games need to include.

Definition in file game.h.


Define Documentation

#define FILERANK_LABEL_DESC   (1 << 2)
 

if game_file_label or game_rank_label is ORed with this the order of file/rank labels will be reversed.

Definition at line 138 of file game.h.

#define FILERANK_LABEL_TYPE_MASK   0x3
 

Definition at line 135 of file game.h.

#define GAME_DEFAULT_URL( x )   "http://gtkboard.sourceforge.net/showgame.pl?game="x
 

Home page for the game x.

Definition at line 147 of file game.h.

Referenced by antichess_init(), ataxx_init(), blet_init(), breakthrough_init(), checkers_init(), chess_init(), cpento_init(), dnb_init(), eightqueens_init(), fifteen_init(), flw_init(), hiq_init(), hypermaze_init(), infiltrate_init(), knights_init(), kttour_init(), mastermind_init(), maze_init(), memory_init(), ninemm_init(), othello_init(), pacman_init(), pentaline_init(), plot4_init(), quarto_init(), rgb_init(), samegame_init(), stopgate_init(), tetris_init(), towers_init(), and wordtris_init().

#define GAME_EVAL_INFTY   (1.0e10)
 

The return value of game_eval should be larger than GAME_EVAL_INFTY in absolute value to indicate that the game is over.

Definition at line 141 of file game.h.

#define ISINBOARD( x, y )   ((x)>=0 && (y)>=0 && (x)<board_wid && (y)< board_heit)
 

Indicates whether the square (x, y) is legal.

Definition at line 144 of file game.h.

Referenced by add_hints(), antichess_movegen(), antichess_movegen_line(), antichess_movegen_square(), blet_event_handler(), breakthrough_movegen(), checkers_movegen(), chess_movegen(), chess_movegen_line(), chess_movegen_square(), eval_disconnected(), eval_max_path_len(), get_chain_info(), get_degree(), get_min_degree(), infiltrate_movegen(), knights_eval_real(), knights_movegen(), othello_eval_liberty(), pentaline_newstate(), recursive_pathgen(), and stopgate_movegen().

#define byte   gint8
 

Both moves and positions are arrays of bytes.

Definition at line 32 of file game.h.


Enumeration Type Documentation

enum FILERANK_LABEL_TYPE
 

values of game_file_label and game_rank_label.

Enumeration values:
FILERANK_LABEL_TYPE_NONE  
FILERANK_LABEL_TYPE_NUM  
FILERANK_LABEL_TYPE_ALPHA  
FILERANK_LABEL_TYPE_ALPHA_CAPS  

Definition at line 133 of file game.h.

enum GtkboardEventType
 

Used for representing the type of user input in game_getmove and game_getmove_kb.

This layer of abstraction exists so that to write a game it will not be necessary to have the g[dt]k headers

Enumeration values:
GTKBOARD_BUTTON_PRESS  
GTKBOARD_BUTTON_RELEASE  
GTKBOARD_MOTION_NOTIFY  
GTKBOARD_LEAVE_NOTIFY  
GTKBOARD_KEY_PRESS  
GTKBOARD_KEY_RELEASE  
GTKBOARD_GAME_START  
GTKBOARD_HUMAN_MOVE  
GTKBOARD_MACHINE_MOVE  
GTKBOARD_HISTORY_MOVE  

Definition at line 43 of file game.h.

enum InputType
 

The return type of game_event_handler.

Enumeration values:
INPUT_ILLEGAL  
INPUT_NOTYET  
INPUT_LEGAL  

Definition at line 103 of file game.h.

enum Player
 

Used in a two player game to represent whose move it is.

Enumeration values:
WHITE  
BLACK  

Definition at line 39 of file game.h.

enum RenderType
 

How to render a square.

Enumeration values:
RENDER_NONE   Just use the default pixmap.
RENDER_HIGHLIGHT1   Draw a colored border around the square. See game_highlight_colors.
RENDER_HIGHLIGHT2  
RENDER_HIGHLIGHT3  
RENDER_SHADE1   Shade the square. Not yet implemented.
RENDER_SHADE2  
RENDER_SHADE3  
RENDER_BUTTONIZE   Make the square look like a button.
RENDER_HIDE   Hide the square (show the background color).
RENDER_REPLACE   Use a different pixmap.

The pixmap must be specified in the 8-15th bits, i.e, if you want to use the pixmap of the piece p, then you must set the render value to p << 8 | RENDER_REPLACE

Definition at line 192 of file game.h.

enum ResultType
 

Used for representing the result of game_who_won.

Enumeration values:
RESULT_WHITE   White won.
RESULT_BLACK   Black won.
RESULT_TIE   Draw.
RESULT_NOTYET   Game not over yet.
RESULT_WON   User completed the game successfully (single player game).
RESULT_LOST   User failed to complete game (single player game).

eg: exhausted all rows in mastermind (mastermind_who_won())

RESULT_MISC   Anything else.

Definition at line 83 of file game.h.

enum SCORE_FIELD
 

The columns that will be shown in the highscores.

SCORE_FIELD_NONE acts as a NULL terminator for the game_score_fields array. Note that highscores make sense only for single player games.

Enumeration values:
SCORE_FIELD_NONE  
SCORE_FIELD_RANK  
SCORE_FIELD_USER  
SCORE_FIELD_SCORE  
SCORE_FIELD_TIME  
SCORE_FIELD_DATE  
SCORE_FIELD_MISC1  
SCORE_FIELD_MISC2  

Definition at line 438 of file game.h.


Variable Documentation

int board_heit
 

Definition at line 373 of file game.h.

int board_wid
 

Definition at line 373 of file game.h.

int cell_size
 

Definition at line 373 of file game.h.

gboolean game_allow_back_forw
 

Should we allow the user to move back and forward in the game. Default: TRUE.

You should not set this to FALSE unless you have a compelling reason to do so. Don't worry about the user cheating and getting a highscore that they don't deserve -- if the user ever clicks back, highscores will be disabled for that game :-) Currently only tetris (tetris.c) sets this to FALSE, because of some complex client-server related issues.

Definition at line 401 of file game.h.

gboolean game_allow_flip
 

(Only for two player games) Is Settings->Flip Board active. For single player games it is always inactive.

Definition at line 408 of file game.h.

gboolean game_allow_undo
 

Is the user allowed to undo move and still get on the highscores (only for single player games; default: FALSE).

Definition at line 379 of file game.h.

int(* game_animate)(Pos *pos, byte **movp)
 

Pointer to animation callback which will be called periodically.

Definition at line 356 of file game.h.

int game_animation_time
 

Determines how frequently to call the game's animation callback function (game_animate). Default: 0.

Definition at line 382 of file game.h.

gboolean game_animation_use_movstack
 

Whether or not to consider animations "moves". Default: TRUE.

Definition at line 385 of file game.h.

char ** game_bg_pixmap
 

Background image for the board.

Definition at line 432 of file game.h.

gchar * game_black_string
 

User visible labels for white and black.

Definition at line 428 of file game.h.

gchar * game_doc_about
 

The text to be shown in the About dialog for the game (Help->GameName->About).

Definition at line 421 of file game.h.

gchar * game_doc_rules
 

The text to be shown in the Rules dialog for the game (Help->GameName->Rules).

Definition at line 423 of file game.h.

gchar * game_doc_strategy
 

The text to be shown in the Strategy dialog for the game (Help->GameName->Strategy).

Definition at line 425 of file game.h.

gboolean game_draw_cell_boundaries
 

Should the lines between the rows and columns be drawn. Default: FALSE.

Example of game which draws boundaries: pentaline (pentaline.c) Example of game which doesn't draw boundaries: memory (memory.c)

Definition at line 393 of file game.h.

ResultType(* game_eval)(Pos *pos, Player player, float *eval)
 

A pointer to the game's evaluation function.

Only for two player games. It must be implemented if you want the computer to be able to play the game.

Definition at line 271 of file game.h.

ResultType(* game_eval_incr)(Pos *pos, Player player, byte *move, float *eval)
 

A pointer to the game's incremental evaluation function.

Only for two player games. This is an advanced feature: if you feel that being forced to look at the whole board for each call to game_eval is inefficient, you can write an incremental evaluation function which takes a position and the move being made and returns the difference in the eval of the original and final positions. Note that you still need to implement game_eval even if you implement this function. Since premature optimization is the root of all evil, it is highly recommended that you get your game working and stable before you think of implementing this function :)

Definition at line 283 of file game.h.

InputType(* game_event_handler)(Pos *pos, GtkboardEvent *event, MoveInfo *move_info_p)
 

The all-in-one function that makes game_getmove and game_getmove_kb deprecated.

Definition at line 321 of file game.h.

gboolean game_file_label
 

How to display names of rows and columns. This should be of type FILERANK_LABEL_TYPE, optionally ORed with FILERANK_LABEL_DESC.

Definition at line 411 of file game.h.

void(* game_free)()
 

Called at the end of every game.

Definition at line 363 of file game.h.

char **(* game_get_pixmap)(int piece, int color)
 

Returns the pixmap for a piece.

In many games, the pixmaps are generated at runtime (see aaball.c). Such games use this function. The second argument color is 0 or 1 depending on whether the piece will be shown on a light square or a dark square. If your pixmap is antialiased you need this.

Definition at line 350 of file game.h.

void(* game_get_render)(Pos *pos, byte *move, int **rmovp)
 

The rendering hints associated with the move.

Definition at line 346 of file game.h.

guchar *(* game_get_rgbmap)(int piece, int color)
 

Same as game_get_pixmap but returns a rgbmap instead of pixmap.

Definition at line 353 of file game.h.

int(* game_getmove)(Pos *pos, int x, int y, GtkboardEventType type, Player to_play, byte **movp, int **renderp)
 

This takes a mouse click and returns the move that it corresponds to.

Parameters:
pos  
x   x coordinate of the square that was clicked
y   y coordinate of the square that was clicked
type   type of event
to_play   whose turn is it
movp   a pointer to store the move in if the move is valid
returns:   >0 if move is valid, 0 if more information is needed, -1 if move is illegal // TODO: there should be an enum for this

pentaline_getmove() is a good example of a minimal getmove function.

Definition at line 317 of file game.h.

int(* game_getmove_kb)(Pos *pos, int key, Player to_play, byte **movp, int **rmovp)
 

Takes a keypress and returns the move that it corresponds to.

Parameters:
pos  
key   the key that the user pressed
to_play  
movp   a pointer to the move. The game must allocate memory for this (statically).
rmovp   pointer to rendering change

Definition at line 330 of file game.h.

char * game_highlight_colors
 

Colors to use for highlighting squares.

Definition at line 396 of file game.h.

HeurTab * game_htab
 

Array of structs representing evaluation functions.

Definition at line 418 of file game.h.

byte *(* game_movegen)(Pos *)
 

A pointer to the game's move generation function.

Only for two player games. It must be implemented if you want the computer to be able to play the game.

It returns a list of moves possible in a given position. See move.h for documentation of the MOVLIST format. Plot4's movegen function (plot4_movegen()) is a good example of a simple movegen function.

The move list (array) should be malloc'd inside this function and will be freed by the caller.

Definition at line 302 of file game.h.

void *(* game_newstate)(Pos *pos, byte *move)
 

Pointer to function which will compute the new state from the current position and the move.

The returned state should be a pointer to a statically declared structure.

Definition at line 360 of file game.h.

gboolean game_rank_label
 

How to display names of rows and columns. This should be of type FILERANK_LABEL_TYPE, optionally ORed with FILERANK_LABEL_DESC.

Definition at line 411 of file game.h.

void(* game_reset_uistate)()
 

This is called after each move the user completes.

The user may have made some clicks which do not complete a move and then clicked the back button, for example. Then the game must forget the saved clicks.

Definition at line 371 of file game.h.

gchar ** game_score_field_names
 

The names of the column titles in the highscores.

If you set game_score_fields you also have to set game_score_field_names which gives the titles to use for the respective columns.

Definition at line 450 of file game.h.

SCORE_FIELD * game_score_fields
 

Used to override the default highscore columns.

By default, the columns shown in the highscores are User, Score, Time and Date. This sequence can be overridden by specifying a game_score_fields array terminated by SCORE_FIELD_NONE. SCORE_FIELD_MISC1 and SCORE_FIELD_MISC2 are used to specify some field which is none of the 5 available by default. The MISC functionality is currently unimplemented

Definition at line 446 of file game.h.

int(* game_scorecmp)(gchar *, int, gchar *, int)
 

Pointer to the comparison function used to order highscores.

Highscores work by applying the comparison function on the score string returned by game_who_won. Three defaults are availble (see below), one of which will likely fit what you want. If not you can write your own function and set this pointer to it.

Definition at line 457 of file game.h.

int(* game_scorecmp_def_dscore)(gchar *, int, gchar *, int)
 

Default highscore comparison function: decreasing order of Score field.

Definition at line 460 of file game.h.

int(* game_scorecmp_def_iscore)(gchar *, int, gchar *, int)
 

Default highscore comparison function: increasing order of Score field.

Definition at line 462 of file game.h.

int(* game_scorecmp_def_time)(gchar *, int, gchar *, int)
 

Default highscore comparison function: increasing order of Time field.

Definition at line 464 of file game.h.

void(* game_search)(Pos *pos, byte **move)
 

A function to search and return the best move - for games for which minimax is not appropriate.

Definition at line 289 of file game.h.

void(* game_set_init_pos)(Pos *pos)
 

Pointer to function which sets the game's initial position.

In some games such as maze (maze.c), the initial position is not constant but randomly generated. Such functions use game_set_init_pos. The function is expected to set the value of pos->board.

Definition at line 340 of file game.h.

void(* game_set_init_render)(Pos *pos)
 

Sets the initial state of the rendering hints.

Definition at line 343 of file game.h.

int game_single_player
 

Are we a single player game or a two-player game? DEFAULT: FALSE.

Definition at line 376 of file game.h.

gboolean game_start_immediately
 

Should the user's clock start ticking as soon as the game is selected. Default: FALSE.

Doesn't make a lot of sense for two player games. In games like maze (maze.c), the user can solve the maze without even making a move, so it would be unfair to let them look at the maze without starting the clock.

Definition at line 405 of file game.h.

int game_state_size
 

Size of the Pos::state structure.

For stateful games, you need to specify the size of the state structure (as defined by the sizeof operator.)

Definition at line 415 of file game.h.

gboolean game_stateful
 

Are we a stateful game. Default: FALSE.

Definition at line 388 of file game.h.

gboolean(* game_use_incr_eval)(Pos *pos, Player player)
 

Should we use the incr eval function.

Definition at line 286 of file game.h.

gchar * game_white_string
 

User visible labels for white and black.

Definition at line 428 of file game.h.

ResultType(* game_who_won)(Pos *pos, Player player, char **scorep)
 

Checks if the game is over, and if so, who has won.

This function is called after every move, both for single player and two player games.

Parameters:
scorep   pointer to the "score". If game_who_won sets this, the score will be displayed in the score field of the statusbar.

Definition at line 336 of file game.h.

int num_pieces
 

Definition at line 373 of file game.h.