GGTL-Reversi- GGTL extension for playing Reversi (aka Othello)
#include <ggtl/reversi.h> GGTL *reversi_init(GGTL *g, void *state); RMove *reversi_move_new(int x, int y, GGTL *g); RState *reversi_state_new(int size); void reversi_state_draw(RState *state); RStateCount reversi_state_count(RState *state); /* callback functions used by ggtl core */ void *reversi_state_clone(void *state, GGTL *g); int reversi_eval(void *state, GGTL *g); void reversi_state_free(void *state); GGTL_MOVE *reversi_get_moves(void *state, GGTL *g); void *reversi_move(void *s, void *mv, GGTL *g);
See reversi-demo(3) for a complete example of a self-playing Reversi game using this extension.
GGTL-Reversi is a GGTL extension for playing Reversi (aka Othello). It provides all the callback functions and datastructures GGTL needs to provide a Reversi AI, leaving you free to worry about other aspects of the game.
All even board sizes greater than 4x4 are supported and can be specified at run time.
Three data structures are used by this GGTL extension. They are:
typedef struct reversi_state {
int player;
int size;
int **board;
} RState;
typedef struct reversi_move {
int x;
int y;
} RMove;
typedef struct reversi_counts {
int c[3];
} RStateCount;
Returns a reversi state with a board of the desired size, or NULL on failure. The board is set up for the beginning of a game and player 1 is set to start.
Clone the state s (using a cached state from g if
available). Return the cloned state, or NULL on error.
It is assumed that cached states are the same size as the one being cloned.
Print a plain-text representation of a state to standard out.
Returns a new move, or NULL on failure.
Returns a new move, wrapped in a ggtl_mc container, or NULL
on failure. If g is non-NULL it will be asked for a cached move;
otherwise, a new move will be allocated.
Initialises a GGTL structure's vtable with functions for playing Reversi and set the provided state to be the starting state of the game.
Returns a structure containing the counts of empty, white & black squares in the given state.
These functions are used internally by GGTL; it is unlikely that you should have to worry about them. However, you are allowed to override these should you wish. See ggtl_vtab().
Evaluate a reversi state and return its fitness.
Returns the state resulting from applying move to state, or
NULL on failure.
Returns a list of the available moves at the given position, or NULL if no moves could be found.
Free up the memory held up by a state. This overrides the default
free_state() callback supplied by GGTL.
The code for performing a move was inspired by code found in Gnome Iagno by Ian Peters.
Stig Brautaset <stig@brautaset.org>
Copyright (C) 2005-2006 Stig Brautaset
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.