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 BLET_CELL_SIZE 55
28
#define BLET_NUM_PIECES 2
30
#define BLET_BOARD_WID 8
31
#define BLET_BOARD_HEIT 8
37
static char blet_colors[6] = {140, 140, 180, 140, 140, 180};
39
static int blet_init_pos [BLET_BOARD_WID*BLET_BOARD_HEIT] =
41
1 , 2 , 1 , 2 , 1 , 2 , 1 , 2 ,
42
2 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ,
43
1 , 0 , 0 , 0 , 0 , 0 , 0 , 2 ,
44
2 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ,
45
1 , 0 , 0 , 0 , 0 , 0 , 0 , 2 ,
46
2 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ,
47
1 , 0 , 0 , 0 , 0 , 0 , 0 , 2 ,
48
2 , 1 , 2 , 1 , 2 , 1 , 2 , 1 ,
51
SCORE_FIELD blet_score_fields[] = {SCORE_FIELD_USER, SCORE_FIELD_SCORE, SCORE_FIELD_TIME, SCORE_FIELD_DATE, SCORE_FIELD_NONE};
52
char *blet_score_field_names[] = {"User", "Flips", "Time", "Date", NULL};
56
Game Blet = { BLET_CELL_SIZE, BLET_BOARD_WID, BLET_BOARD_HEIT,
58
blet_colors, blet_init_pos, NULL, "Blet", "Logic puzzles", blet_init};
60
static int blet_getmove (Pos *, int, int, GtkboardEventType, Player, byte **, int **);
61
static ResultType blet_who_won (Pos *, Player , char **);
62
unsigned char * blet_get_rgbmap (int, int);
63
InputType blet_event_handler (Pos *pos, GtkboardEvent *event, MoveInfo *move_info_p);
67
// game_getmove = blet_getmove;
68
game_get_rgbmap = blet_get_rgbmap;
69
game_single_player = TRUE;
70
game_who_won = blet_who_won;
71
game_scorecmp = game_scorecmp_def_iscore;
72
game_score_fields = blet_score_fields;
73
game_score_field_names = blet_score_field_names;
74
game_event_handler = blet_event_handler;
75
game_doc_about_status = STATUS_COMPLETE;
78
"Single player game\n"
79
"Status: Partially implemented\n"
80
"URL: "GAME_DEFAULT_URL("blet");
82
"If a ball is surrounded by balls of the opposite color, you can click on the middle ball to flip all three.\n\n"
83
"The goal is to get 23 green balls in as few flips as possible\n";
85
"Blet was invented by Villegas, Sadun and Voloch. A research paper showing the optimal strategy as well as an online version of the game (which requires a tcl browser plugin) can be found at: http://www.ma.utexas.edu/users/voloch/blet.html";
88
static ResultType blet_who_won (Pos *pos, Player player, char **commp)
90
static char comment[32];
93
for (i=0, ngreen = 0; i < board_wid * board_heit; i++)
94
if (pos->board[i] == BLET_GP) ngreen++;
95
over = (ngreen == 23 ? TRUE : FALSE);
96
if (over) snprintf (comment, 32, "You won! Flips: %d", pos->num_moves);
97
else snprintf (comment, 32, "Green: %d; Flips: %d", ngreen, pos->num_moves);
99
return over ? RESULT_WON : RESULT_NOTYET;
102
static int incx[] = { -1, 1, 0, 0};
103
static int incy[] = { 0, 0, 1, -1};
105
#define FLIP(x) ((x)==BLET_RP?BLET_GP:BLET_RP)
107
InputType blet_event_handler (Pos *pos, GtkboardEvent *event, MoveInfo *move_info_p)
109
static byte move[32];
112
if (event->type != GTKBOARD_BUTTON_RELEASE)
116
if (x > 0 && x < board_wid - 1 && y > 0 && y < board_heit - 1)
118
move_info_p->help_message = "You must click on one of the balls.";
119
return INPUT_ILLEGAL;
121
val = pos->board [y * board_wid + x];
122
for (k=0; k < 4; k++)
124
int newx = x + incx[k], newy = y + incy[k];
125
if (!ISINBOARD(newx, newy)) continue;
126
if (pos->board[newy * board_wid + newx] == val)
128
move_info_p->help_message = "Both neighbors must be of the opposite color.";
129
return INPUT_ILLEGAL;
131
if (pos->board[newy * board_wid + newx] == BLET_EMPTY) continue;
132
*mp++ = newx; *mp++ = newy; *mp++ = val;
134
*mp++ = x; *mp++ = y; *mp++ = FLIP(val);
136
move_info_p->move = move;
141
unsigned char * blet_get_rgbmap (int idx, int color)
145
static char rgbbuf[3 * BLET_CELL_SIZE * BLET_CELL_SIZE];
146
colors = blet_colors;
147
fg = (idx == BLET_GP ? 0xcc << 8 : 0xee << 16);
148
if (color == BLACK) colors += 3;
149
for(i=0, bg=0;i<3;i++)
150
{ int col = colors[i]; if (col<0) col += 256; bg += col * (1 << (16-8*i));}
151
rgbmap_ball_shadow_gen(55, rgbbuf, fg, bg, 17.0, 35.0, 3);