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 RGB_CELL_SIZE 55
28
#define RGB_NUM_PIECES 3
30
#define RGB_BOARD_WID 3
31
#define RGB_BOARD_HEIT 3
38
char rgb_colors[9] = {200, 200, 200, 200, 200, 200, 0, 0, 0};
40
int * rgb_init_pos = NULL;
44
Game Rgb = { RGB_CELL_SIZE, RGB_BOARD_WID, RGB_BOARD_HEIT,
46
rgb_colors, NULL, NULL, "Rgb", "k-in-a-row", rgb_init};
49
static int rgb_getmove (Pos *, int, int, GtkboardEventType, Player, byte **, int **);
50
static ResultType rgb_who_won (Pos *, Player, char **);
51
static void rgb_set_init_pos (Pos *pos);
53
static byte * rgb_movegen (Pos *);
54
static ResultType rgb_eval (Pos *, Player, float *eval);
56
static unsigned char * rgb_get_rgbmap (int idx, int color);
61
game_movegen = rgb_movegen;
62
game_getmove = rgb_getmove;
63
game_who_won = rgb_who_won;
64
game_set_init_pos = rgb_set_init_pos;
65
game_get_rgbmap = rgb_get_rgbmap;
66
game_draw_cell_boundaries = TRUE;
67
game_allow_flip = TRUE;
68
game_doc_about_status = STATUS_COMPLETE;
72
"Status: Fully implemented\n"
73
"URL: "GAME_DEFAULT_URL ("rgb");
75
"Rgb, short for red-green-blue, is a harder version of tic-tac-toe. The goal is to get 3 balls in a line (row, column, or diagonal) of any one color. Clicking on an empty square puts a red ball on it, clicking on a red ball turns it green, and clicking on a green ball turns it blue.";
78
static void rgb_set_init_pos (Pos *pos)
81
for (i=0; i<board_wid * board_heit; i++)
82
pos->board [i] = RGB_EMPTY;
85
static byte * rgb_movegen (Pos *pos)
89
byte *movlist, *movp = movbuf;
92
{0, 1}, {3, 1}, {6, 1},
93
{0, 3}, {1, 3}, {2, 3},
102
if (val >= 0 && pos->board[lines[i][0] + j * lines[i][1]] != val)
103
{ found = 0; break; }
104
val = pos->board[lines[i][0] + j * lines[i][1]];
105
if (val == RGB_EMPTY) { found = 0; break; }
112
for (i=0; i<board_wid; i++)
113
for (j=0; j<board_heit; j++)
114
if (pos->board[j * board_wid + i] != RGB_BP)
118
*movp++ = pos->board[j * board_wid + i] + 1;
123
movlist = (byte *) (malloc (movp - movbuf));
124
memcpy (movlist, movbuf, (movp - movbuf));
128
static ResultType rgb_who_won (Pos *pos, Player to_play, char **commp)
130
static char comment[32];
131
char *who_str [] = { "White won", "Black won"};
134
{0, 1}, {3, 1}, {6, 1},
135
{0, 3}, {1, 3}, {2, 3},
145
if (val >= 0 && pos->board[lines[i][0] + j * lines[i][1]] != val)
146
{ found = 0; break; }
147
val = pos->board[lines[i][0] + j * lines[i][1]];
148
if (val == RGB_EMPTY) { found = 0; break; }
152
*commp = who_str[to_play == WHITE ? 1 : 0];
153
return to_play == WHITE ? RESULT_BLACK : RESULT_WHITE;
157
return RESULT_NOTYET;
160
static int rgb_getmove (Pos *pos, int x, int y, GtkboardEventType type, Player to_play, byte **movp, int ** rmovep)
164
if (type != GTKBOARD_BUTTON_RELEASE)
166
val = pos->board [y * board_wid + x];
167
if (val == RGB_BP) return -1;
177
static unsigned char * rgb_get_rgbmap (int idx, int color)
181
static char rgbbuf[3 * RGB_CELL_SIZE * RGB_CELL_SIZE];
183
if (idx == RGB_RP) fg = 255 << 16;
184
else if (idx == RGB_GP) fg = 255 << 8;
185
else if (idx == RGB_BP) fg = 255;
187
for(i=0, bg=0;i<3;i++)
188
{ int col = colors[i]; if (col<0) col += 256; bg += col * (1 << (16-8*i));}
189
rgbmap_ball_shadow_gen(55, rgbbuf, fg, bg, 17.0, 35.0, 3);
194
static ResultType rgb_eval (Pos *pos, Player to_play, float *eval)
201
{0, 1}, {3, 1}, {6, 1},
203
{0, 3}, {1, 3}, {2, 3},
213
if (val >= 0 && pos->board[lines[i][0] + j * lines[i][1]] != val)
214
{ found = 0; break; }
215
val = pos->board[lines[i][0] + j * lines[i][1]];
216
if (val == RGB_EMPTY) { found = 0; break; }
220
*eval = (to_play == WHITE ? -2*GAME_EVAL_INFTY : 2*GAME_EVAL_INFTY);
221
return RESULT_NOTYET;
225
return RESULT_NOTYET;