This is the doxygen documentation for gtkboard.
.00001 /* This file is a part of gtkboard, a board games system. 00002 Copyright (C) 2003, Arvind Narayanan <arvindn@users.sourceforge.net> 00003 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or 00007 (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program; if not, write to the Free Software 00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA 00017 00018 */ 00019 #include <stdio.h> 00020 #include <string.h> 00021 #include <assert.h> 00022 #include <stdlib.h> 00023 00024 #include "game.h" 00025 #include "aaball.h" 00026 00027 #define BLET_CELL_SIZE 55 00028 #define BLET_NUM_PIECES 2 00029 00030 #define BLET_BOARD_WID 8 00031 #define BLET_BOARD_HEIT 8 00032 00033 #define BLET_EMPTY 0 00034 #define BLET_RP 1 00035 #define BLET_GP 2 00036 00037 static char blet_colors[6] = {140, 140, 180, 140, 140, 180}; 00038 00039 static int blet_init_pos [BLET_BOARD_WID*BLET_BOARD_HEIT] = 00040 { 00041 1 , 2 , 1 , 2 , 1 , 2 , 1 , 2 , 00042 2 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 00043 1 , 0 , 0 , 0 , 0 , 0 , 0 , 2 , 00044 2 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 00045 1 , 0 , 0 , 0 , 0 , 0 , 0 , 2 , 00046 2 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 00047 1 , 0 , 0 , 0 , 0 , 0 , 0 , 2 , 00048 2 , 1 , 2 , 1 , 2 , 1 , 2 , 1 , 00049 }; 00050 00051 SCORE_FIELD blet_score_fields[] = {SCORE_FIELD_USER, SCORE_FIELD_SCORE, SCORE_FIELD_TIME, SCORE_FIELD_DATE, SCORE_FIELD_NONE}; 00052 char *blet_score_field_names[] = {"User", "Flips", "Time", "Date", NULL}; 00053 00054 void blet_init (); 00055 00056 Game Blet = { BLET_CELL_SIZE, BLET_BOARD_WID, BLET_BOARD_HEIT, 00057 BLET_NUM_PIECES, 00058 blet_colors, blet_init_pos, NULL, "Blet", blet_init}; 00059 00060 static int blet_getmove (Pos *, int, int, GtkboardEventType, Player, byte **, int **); 00061 static ResultType blet_who_won (Pos *, Player , char **); 00062 unsigned char * blet_get_rgbmap (int, int); 00063 InputType blet_event_handler (Pos *pos, GtkboardEvent *event, MoveInfo *move_info_p); 00064 00065 void blet_init () 00066 { 00067 // game_getmove = blet_getmove; 00068 game_get_rgbmap = blet_get_rgbmap; 00069 game_single_player = TRUE; 00070 game_who_won = blet_who_won; 00071 game_scorecmp = game_scorecmp_def_iscore; 00072 game_score_fields = blet_score_fields; 00073 game_score_field_names = blet_score_field_names; 00074 game_event_handler = blet_event_handler; 00075 game_doc_about = 00076 "Blet\n" 00077 "Single player game\n" 00078 "Status: Partially implemented\n" 00079 "URL: "GAME_DEFAULT_URL("blet"); 00080 game_doc_rules = 00081 "Blet rules\n\n" 00082 "If a ball is surrounded by balls of the opposite color, you can click on the middle ball to flip all three.\n\n" 00083 "The goal is to get 23 green balls in as few flips as possible\n"; 00084 game_doc_strategy = 00085 "Blet strategy\n\n" 00086 "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"; 00087 } 00088 00089 static ResultType blet_who_won (Pos *pos, Player player, char **commp) 00090 { 00091 static char comment[32]; 00092 int ngreen, i; 00093 gboolean over; 00094 for (i=0, ngreen = 0; i < board_wid * board_heit; i++) 00095 if (pos->board[i] == BLET_GP) ngreen++; 00096 over = (ngreen == 23 ? TRUE : FALSE); 00097 if (over) snprintf (comment, 32, "You won! Flips: %d", pos->num_moves); 00098 else snprintf (comment, 32, "Green: %d; Flips: %d", ngreen, pos->num_moves); 00099 *commp = comment; 00100 return over ? RESULT_WON : RESULT_NOTYET; 00101 } 00102 00103 static int incx[] = { -1, 1, 0, 0}; 00104 static int incy[] = { 0, 0, 1, -1}; 00105 00106 #define FLIP(x) ((x)==BLET_RP?BLET_GP:BLET_RP) 00107 00108 InputType blet_event_handler (Pos *pos, GtkboardEvent *event, MoveInfo *move_info_p) 00109 { 00110 static byte move[32]; 00111 byte *mp = move; 00112 int val, k, x, y; 00113 if (event->type != GTKBOARD_BUTTON_RELEASE) 00114 return INPUT_NOTYET; 00115 x = event->x; 00116 y = event->y; 00117 if (x > 0 && x < board_wid - 1 && y > 0 && y < board_heit - 1) 00118 { 00119 move_info_p->help_message = "You must click on one of the balls."; 00120 return INPUT_ILLEGAL; 00121 } 00122 val = pos->board [y * board_wid + x]; 00123 for (k=0; k < 4; k++) 00124 { 00125 int newx = x + incx[k], newy = y + incy[k]; 00126 if (!ISINBOARD(newx, newy)) continue; 00127 if (pos->board[newy * board_wid + newx] == val) 00128 { 00129 move_info_p->help_message = "Both neighbors must be of the opposite color."; 00130 return INPUT_ILLEGAL; 00131 } 00132 if (pos->board[newy * board_wid + newx] == BLET_EMPTY) continue; 00133 *mp++ = newx; *mp++ = newy; *mp++ = val; 00134 } 00135 *mp++ = x; *mp++ = y; *mp++ = FLIP(val); 00136 *mp++ = -1; 00137 move_info_p->move = move; 00138 return INPUT_LEGAL; 00139 } 00140 00141 00142 unsigned char * blet_get_rgbmap (int idx, int color) 00143 { 00144 int fg, bg, i; 00145 char *colors; 00146 static char rgbbuf[3 * BLET_CELL_SIZE * BLET_CELL_SIZE]; 00147 colors = blet_colors; 00148 fg = (idx == BLET_GP ? 0xcc << 8 : 0xee << 16); 00149 if (color == BLACK) colors += 3; 00150 for(i=0, bg=0;i<3;i++) 00151 { int col = colors[i]; if (col<0) col += 256; bg += col * (1 << (16-8*i));} 00152 rgbmap_ball_shadow_gen(55, rgbbuf, fg, bg, 17.0, 35.0, 3); 00153 return rgbbuf; 00154 } 00155