~ubuntu-branches/ubuntu/natty/gtkboard/natty

« back to all changes in this revision

Viewing changes to .pc/debian-changes-0.11pre0-12/src/blet.c

  • Committer: Bazaar Package Importer
  • Author(s): Barak A. Pearlmutter
  • Date: 2011-03-15 12:43:00 UTC
  • mfrom: (3.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20110315124300-zf9hkdc5vjyqge7e
Tags: 0.11pre0+cvs.2003.11.02-3
static size unknown gcc-4.5 fix src/{menu,wordtris}.c (closes: #564999)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  This file is a part of gtkboard, a board games system.
2
 
    Copyright (C) 2003, Arvind Narayanan <arvindn@users.sourceforge.net>
3
 
 
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.
8
 
 
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.
13
 
 
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
17
 
 
18
 
*/
19
 
#include <stdio.h>
20
 
#include <string.h>
21
 
#include <assert.h>
22
 
#include <stdlib.h>
23
 
 
24
 
#include "game.h"
25
 
#include "aaball.h"
26
 
 
27
 
#define BLET_CELL_SIZE 55
28
 
#define BLET_NUM_PIECES 2
29
 
 
30
 
#define BLET_BOARD_WID 8
31
 
#define BLET_BOARD_HEIT 8
32
 
 
33
 
#define BLET_EMPTY 0
34
 
#define BLET_RP 1
35
 
#define BLET_GP 2
36
 
 
37
 
static char blet_colors[6] = {140, 140, 180, 140, 140, 180};
38
 
 
39
 
static int blet_init_pos [BLET_BOARD_WID*BLET_BOARD_HEIT] = 
40
 
{
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 ,
49
 
};
50
 
 
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};
53
 
 
54
 
void blet_init ();
55
 
 
56
 
Game Blet = { BLET_CELL_SIZE, BLET_BOARD_WID, BLET_BOARD_HEIT, 
57
 
        BLET_NUM_PIECES,
58
 
        blet_colors, blet_init_pos, NULL, "Blet", "Logic puzzles", blet_init};
59
 
 
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);
64
 
 
65
 
void blet_init ()
66
 
{
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;
76
 
        game_doc_about = 
77
 
                "Blet\n"
78
 
                "Single player game\n"
79
 
                "Status: Partially implemented\n"
80
 
                "URL: "GAME_DEFAULT_URL("blet");
81
 
        game_doc_rules = 
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";
84
 
        game_doc_strategy = 
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";
86
 
}
87
 
 
88
 
static ResultType blet_who_won (Pos *pos, Player player, char **commp)
89
 
{
90
 
        static char comment[32];
91
 
        int ngreen, i;
92
 
        gboolean over;
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);
98
 
        *commp = comment;
99
 
        return over ? RESULT_WON : RESULT_NOTYET;
100
 
}
101
 
 
102
 
static int incx[] = { -1, 1, 0, 0};
103
 
static int incy[] = { 0, 0, 1, -1};
104
 
 
105
 
#define FLIP(x) ((x)==BLET_RP?BLET_GP:BLET_RP)
106
 
 
107
 
InputType blet_event_handler (Pos *pos, GtkboardEvent *event, MoveInfo *move_info_p)
108
 
{
109
 
        static byte move[32];
110
 
        byte *mp = move;
111
 
        int val, k, x, y;
112
 
        if (event->type != GTKBOARD_BUTTON_RELEASE)
113
 
                return INPUT_NOTYET;
114
 
        x = event->x;
115
 
        y = event->y;
116
 
        if (x > 0 && x < board_wid - 1 && y > 0 && y < board_heit - 1)
117
 
        {
118
 
                move_info_p->help_message = "You must click on one of the balls.";
119
 
                return INPUT_ILLEGAL;
120
 
        }
121
 
        val = pos->board [y * board_wid + x];
122
 
        for (k=0; k < 4; k++)
123
 
        {
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)
127
 
                {       
128
 
                        move_info_p->help_message = "Both neighbors must be of the opposite color.";
129
 
                        return INPUT_ILLEGAL;
130
 
                }
131
 
                if (pos->board[newy * board_wid + newx] == BLET_EMPTY) continue;
132
 
                *mp++ = newx; *mp++ = newy; *mp++ = val;
133
 
        }
134
 
        *mp++ = x; *mp++ = y; *mp++ = FLIP(val);
135
 
        *mp++ = -1;
136
 
        move_info_p->move = move;
137
 
        return INPUT_LEGAL;
138
 
}
139
 
 
140
 
 
141
 
unsigned char * blet_get_rgbmap (int idx, int color)
142
 
{
143
 
        int fg, bg, i;
144
 
        char *colors;
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);
152
 
        return rgbbuf;
153
 
}
154