1
/* This file is a part of gtkboard, a board games system.
2
Copyright (C) 2003, Arvind Narayanan <arvindn@users.sourceforge.net>
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or
7
(at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
27
#define INFILTRATE_CELL_SIZE 40
28
#define INFILTRATE_NUM_PIECES 2
30
#define INFILTRATE_BOARD_WID 5
31
#define INFILTRATE_BOARD_HEIT 5
33
#define INFILTRATE_EMPTY 0
34
#define INFILTRATE_WP 1
35
#define INFILTRATE_BP 2
37
char infiltrate_colors[] =
41
int infiltrate_init_pos[] =
50
static int infiltrate_max_moves = 200;
53
void infiltrate_init ();
54
int infiltrate_getmove (Pos *, int, int, GtkboardEventType, Player, byte **, int **);
55
//ResultType infiltrate_who_won (byte *, int, char **);
56
byte *infiltrate_movegen (Pos *);
57
ResultType infiltrate_eval (Pos *, Player, float *);
58
guchar * infiltrate_get_rgbmap (int idx, int color);
59
void infiltrate_reset_uistate ();
62
{ INFILTRATE_CELL_SIZE, INFILTRATE_BOARD_WID, INFILTRATE_BOARD_HEIT,
63
INFILTRATE_NUM_PIECES,
64
infiltrate_colors, infiltrate_init_pos, NULL, "Infiltrate", NULL,
67
void infiltrate_init ()
69
game_getmove = infiltrate_getmove;
70
game_movegen = infiltrate_movegen;
71
//game_who_won = infiltrate_who_won;
72
game_eval = infiltrate_eval;
73
game_get_rgbmap = infiltrate_get_rgbmap;
74
game_reset_uistate = infiltrate_reset_uistate;
75
game_doc_about_status = STATUS_PARTIAL;
79
"Status: Partially implemented\n"
80
"URL: "GAME_DEFAULT_URL ("infiltrate");
82
"The pieces move diagonally, one square at a time. The objective is to get all your pieces to the starting squares of your opponent's pieces.\n";
85
byte * infiltrate_movegen (Pos *pos)
87
int i, j, diffx, diffy;
89
byte *movlist, *mp = movbuf;
90
byte *board = pos->board;
91
Player player = pos->player;
92
for (i=0; i<board_wid; i++)
93
for (j=0; j<board_heit; j++)
95
if (player == BLACK && (board [j * board_wid + i] != INFILTRATE_BP))
97
if (player == WHITE && (board [j * board_wid + i] != INFILTRATE_WP))
99
for (diffx = -1; diffx <= 1; diffx += 2)
100
for (diffy = -1; diffy <= 1; diffy += 2)
103
if (!ISINBOARD(x = i+diffx, y = j+diffy)) continue;
104
if (board [y * board_wid + x] != 0) continue;
105
*mp++ = i; *mp++ = j; *mp++ = 0;
106
*mp++ = i + diffx; *mp++ = j + diffy;
107
*mp++ = (player == WHITE ? INFILTRATE_WP : INFILTRATE_BP);
114
movlist = (byte *) (malloc (mp - movbuf));
115
memcpy (movlist, movbuf, (mp - movbuf));
119
ResultType infiltrate_eval (Pos *pos, Player to_play, float *eval)
123
for (i=0; i<board_wid; i++)
124
for (j=0; j<board_heit; j++)
125
if (pos->board [j * board_wid + i])
128
return RESULT_NOTYET;
132
static int oldx = -1, oldy = -1;
134
void infiltrate_reset_uistate ()
136
oldx = -1, oldy = -1;
139
int infiltrate_getmove (Pos *pos, int x, int y, GtkboardEventType type, Player to_play,
140
byte **movp, int ** rmovep)
142
static byte move[10];
144
byte *board = pos->board;
145
if (type != GTKBOARD_BUTTON_RELEASE) return 0;
148
int val = board [y * board_wid + x];
149
if ((val != INFILTRATE_BP && !(to_play == WHITE)) ||
150
(val != INFILTRATE_WP && !(to_play == BLACK)))
160
if (abs (diffx) != 1 || abs (diffy) != 1)
162
oldx = -1; oldy = -1;
165
if (board [y * board_wid + x] != INFILTRATE_EMPTY)
167
oldx = -1; oldy = -1;
170
*mp++ = oldx; *mp++ = oldy; *mp++ = 0;
171
*mp++ = x; *mp++ = y; *mp++ = board [oldy * board_wid + oldx];
180
guchar *infiltrate_get_rgbmap (int idx, int color)
182
static guchar rgbbuf[3*INFILTRATE_CELL_SIZE*INFILTRATE_CELL_SIZE];
185
colors = infiltrate_colors;
186
fg = (idx == INFILTRATE_WP ? 0xffffff : 0x0000ff);
187
if (color == BLACK) colors += 3;
188
for(i=0, bg=0;i<3;i++)
189
{ int col = colors[i]; if (col<0) col += 256; bg += col * (1 << (16-8*i));}
190
rgbmap_ball_shadow_gen(INFILTRATE_CELL_SIZE, rgbbuf, fg, bg, 8, 24, 2);
195
char ** infiltrate_get_pixmap (int idx, int color)
199
static char pixbuf[INFILTRATE_CELL_SIZE * (INFILTRATE_CELL_SIZE+1)];
200
for(i=0, bg=0;i<3;i++)
201
{ int col = infiltrate_colors[i];
202
if (col<0) col += 256; bg += col * (1 << (16-8*i));}
203
return pixmap_ball_gen (INFILTRATE_CELL_SIZE, pixbuf,
204
idx == INFILTRATE_WP ? 0xffffff : 0x0000ff, bg,