#include
#include
#include
#include
#include \"game.h\"
#include \"aaball.h\"
#define CHECKERS_CELL_SIZE 40
#define CHECKERS_NUM_PIECES 4
#define CHECKERS_BOARD_WID 8
#define CHECKERS_BOARD_HEIT 8
#define CHECKERS_WK 1
#define CHECKERS_WP 2
#define CHECKERS_BK 3
#define CHECKERS_BP 4
#define CHECKERS_ISKING(x) (x == 1 || x == 3)
#define CHECKERS_ISPAWN(x) (x == 2 || x == 4)
#define CHECKERS_ISWHITE(x) (x >= 1 && x <= 2)
#define CHECKERS_ISBLACK(x) (x >= 3 && x <= 4)
char checkers_colors[] =
{200, 200, 200,
220,220,255};
int checkers_init_pos[] =
{
0 , 4 , 0 , 4 , 0 , 4 , 0 , 4 ,
4 , 0 , 4 , 0 , 4 , 0 , 4 , 0 ,
0 , 4 , 0 , 4 , 0 , 4 , 0 , 4 ,
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
2 , 0 , 2 , 0 , 2 , 0 , 2 , 0 ,
0 , 2 , 0 , 2 , 0 , 2 , 0 , 2 ,
2 , 0 , 2 , 0 , 2 , 0 , 2 , 0 ,
};
static int checkers_max_moves = 200;
void checkers_init ();
int checkers_getmove (Pos *, int, int, GtkboardEventType, Player, byte **, int **);
ResultType checkers_who_won (Pos *, Player, char **);
byte *checkers_movegen (Pos *);
ResultType checkers_eval (Pos *, Player, float *);
char ** checkers_get_pixmap (int idx, int color);
void checkers_reset_uistate ();
Game Checkers =
{ CHECKERS_CELL_SIZE, CHECKERS_BOARD_WID,
CHECKERS_BOARD_HEIT,
CHECKERS_NUM_PIECES,
checkers_colors, checkers_init_pos, NULL, \"Checkers\",
checkers_init};
void checkers_init ()
{
game_getmove = checkers_getmove;
game_movegen = checkers_movegen;
game_who_won = checkers_who_won;
game_eval = checkers_eval;
game_get_pixmap = checkers_get_pixmap;
game_reset_uistate = checkers_reset_uistate;
game_file_label = FILERANK_LABEL_TYPE_ALPHA;
game_rank_label = FILERANK_LABEL_TYPE_NUM | FILERANK_LABEL_DESC;
game_allow_flip = TRUE;
game_doc_about =
\"Checkers\ \"
\"Two player game\ \"
\"Status: Partially implemented (currently unplayable)\ \"
\"URL: \"GAME_DEFAULT_URL(\"checkers\");
}
ResultType checkers_who_won (Pos *pos, Player player, char **commp)
{
static char comment[32];
char *who_str [2] = { \"white won\", \"black won\"};
int found_w = 0, found_b = 0;
int i;
for (i=0; iboard[i])) found_w = 1;
else if (CHECKERS_ISBLACK (pos->board[i])) found_b = 1;
if (!found_b)
{
strncpy (comment, who_str[0], 31);
*commp = comment;
return RESULT_WHITE;
}
if (!found_w)
{
strncpy (comment, who_str[1], 31);
*commp = comment;
return RESULT_BLACK;
}
return RESULT_NOTYET;
}
byte * checkers_movegen (Pos *pos)
{
int i, j, diffx, diffy;
byte movbuf [256];
byte *movlist, *mp = movbuf;
byte *board = pos->board;
Player player = pos->player;
for (i=0; iboard [j * board_wid + i])
{
case CHECKERS_WK: sum += (5 - fabs ((i-3.5) * (j-3.5)) / 10); break;
case CHECKERS_WP: sum += (1 + j / 10.0); break;
case CHECKERS_BK: sum -= (5 - fabs ((i-3.5) * (j-3.5)) / 10); break;
case CHECKERS_BP: sum -= (1 + (board_heit - 1 - j) / 10.0); break;
}
}
*eval = sum;
return RESULT_NOTYET;
}
static int oldx = -1, oldy = -1;
void checkers_reset_uistate ()
{
oldx = -1, oldy = -1;
}
int checkers_getmove (Pos *pos, int x, int y, Gtkboa.