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

« back to all changes in this revision

Viewing changes to .pc/debian-changes-0.11pre0+cvs.2003.11.02-2/src/towers.c

  • Committer: Bazaar Package Importer
  • Author(s): Barak A. Pearlmutter
  • Date: 2011-02-28 11:25:02 UTC
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20110228112502-e9aah248wxelm7ao
Tags: 0.11pre0+cvs.2003.11.02-2
autotools tweaks, most notably -lSDL to supplement -lSDL_mixer

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 <assert.h>
 
21
 
 
22
#include "game.h"
 
23
 
 
24
#define TOWERS_CELL_SIZE 16
 
25
#define TOWERS_NUM_PIECES 3
 
26
 
 
27
//#define TOWERS_NUM_RINGS 7
 
28
#define TOWERS_BOARD_HEIT_REAL(num_rings) (2 * num_rings + 4)
 
29
#define TOWERS_TOWER_WID_REAL(num_rings) (2 * num_rings + 3)
 
30
#define TOWERS_BOARD_WID_REAL(num_rings) (3 * TOWERS_TOWER_WID_REAL(num_rings))
 
31
#define TOWERS_TOWER_WID TOWERS_TOWER_WID_REAL(num_rings)
 
32
#define TOWERS_BOARD_WID TOWERS_BOARD_WID_REAL(num_rings)
 
33
#define TOWERS_BOARD_HEIT TOWERS_BOARD_HEIT_REAL(num_rings)
 
34
 
 
35
#define TOWERS_EMPTY 0
 
36
#define TOWERS_POLE 1
 
37
#define TOWERS_RING_TOP  2
 
38
#define TOWERS_RING_BOT  3
 
39
#define TOWERS_RING_MID  3
 
40
#define TOWERS_RING_LEFT 4
 
41
#define TOWERS_RING_RIGHT 5
 
42
 
 
43
char towers_colors[6] = {150, 150, 150, 150, 150, 150};
 
44
 
 
45
static int num_rings = -1;
 
46
 
 
47
static char *pole_16_16_xpm[] = {
 
48
"16 16 5 1",
 
49
"1 c #AAAA66",
 
50
"2 c #999955",
 
51
"3 c #888844",
 
52
"4 c #80803b",
 
53
"5 c #777733",
 
54
"5433221111223345",
 
55
"5433221111223345",
 
56
"5433221111223345",
 
57
"5433221111223345",
 
58
"5433221111223345",
 
59
"5433221111223345",
 
60
"5433221111223345",
 
61
"5433221111223345",
 
62
"5433221111223345",
 
63
"5433221111223345",
 
64
"5433221111223345",
 
65
"5433221111223345",
 
66
"5433221111223345",
 
67
"5433221111223345",
 
68
"5433221111223345",
 
69
"5433221111223345",
 
70
};
 
71
 
 
72
 
 
73
static char *ring_top_16_16_xpm[] = {
 
74
"16 16 2 1",
 
75
"  c #cccc99",
 
76
". c #aaaa77",
 
77
"................",
 
78
"................",
 
79
"                ",
 
80
"                ",
 
81
"                ",
 
82
"                ",
 
83
"                ",
 
84
"                ",
 
85
"                ",
 
86
"                ",
 
87
"                ",
 
88
"                ",
 
89
"                ",
 
90
"                ",
 
91
"                ",
 
92
"                ",
 
93
};
 
94
 
 
95
static char *ring_bot_16_16_xpm[] = {
 
96
"16 16 2 1",
 
97
"  c #cccc99",
 
98
". c #aaaa77",
 
99
"                ",
 
100
"                ",
 
101
"                ",
 
102
"                ",
 
103
"                ",
 
104
"                ",
 
105
"                ",
 
106
"                ",
 
107
"                ",
 
108
"                ",
 
109
"                ",
 
110
"                ",
 
111
"                ",
 
112
"                ",
 
113
"................",
 
114
"................",
 
115
};
 
116
 
 
117
 
 
118
static char **towers_pixmaps[] =
 
119
{
 
120
        pole_16_16_xpm,
 
121
        ring_top_16_16_xpm,
 
122
        ring_bot_16_16_xpm,
 
123
};
 
124
 
 
125
static int towers_init_pos4[] = 
 
126
{
 
127
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
128
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
129
        0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
 
130
        0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
 
131
        0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
 
132
        0, 0, 0, 0, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
 
133
        0, 0, 0, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
 
134
        0, 0, 0, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
 
135
        0, 0, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
 
136
        0, 0, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
 
137
        0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
 
138
        0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
 
139
};
 
140
 
 
141
static int towers_init_pos5[] = 
 
142
{
 
143
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
144
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
145
        0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
 
146
        0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
 
147
        0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
 
148
        0, 0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3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,  
 
199
};
 
200
 
 
201
 
 
202
void towers_init ();
 
203
 
 
204
Game Towers = { TOWERS_CELL_SIZE, TOWERS_BOARD_WID_REAL(4), TOWERS_BOARD_HEIT_REAL(4),
 
205
        TOWERS_NUM_PIECES, 
 
206
        towers_colors, towers_init_pos4, towers_pixmaps, 
 
207
        "Tower of Hanoi", "Logic puzzles", 
 
208
        towers_init};
 
209
 
 
210
Game Towers5 = { TOWERS_CELL_SIZE, TOWERS_BOARD_WID_REAL(5), TOWERS_BOARD_HEIT_REAL(5),
 
211
        TOWERS_NUM_PIECES, 
 
212
        towers_colors, towers_init_pos5, towers_pixmaps, 
 
213
        "Tower of Hanoi 5", NULL, 
 
214
        towers_init};
 
215
 
 
216
Game Towers6 = { TOWERS_CELL_SIZE, TOWERS_BOARD_WID_REAL(6), TOWERS_BOARD_HEIT_REAL(6),
 
217
        TOWERS_NUM_PIECES, 
 
218
        towers_colors, towers_init_pos6, towers_pixmaps, 
 
219
        "Tower of Hanoi 6", NULL, 
 
220
        towers_init};
 
221
 
 
222
Game Towers7 = { TOWERS_CELL_SIZE, TOWERS_BOARD_WID_REAL(7), TOWERS_BOARD_HEIT_REAL(7),
 
223
        TOWERS_NUM_PIECES, 
 
224
        towers_colors, towers_init_pos7, towers_pixmaps, 
 
225
        "Tower of Hanoi 7", NULL,
 
226
        towers_init};
 
227
 
 
228
SCORE_FIELD towers_score_fields[] = {SCORE_FIELD_RANK, SCORE_FIELD_USER, SCORE_FIELD_SCORE, SCORE_FIELD_TIME, SCORE_FIELD_DATE, SCORE_FIELD_NONE};
 
229
char *towers_score_field_names[] = {"Rank", "User", "Moves", "Time", "Date", NULL};
 
230
 
 
231
static int towers_getmove (Pos *, int, int, GtkboardEventType, Player, byte **, int **);
 
232
static ResultType towers_who_won (Pos *, Player, char **);
 
233
void towers_reset_uistate ();
 
234
void towers_get_render (Pos *pos, byte *move, int **rmovp);
 
235
 
 
236
GameLevel towers_levels[] =
 
237
{
 
238
        {"4 rings", &Towers},
 
239
        {"5 rings", &Towers5},
 
240
        {"6 rings", &Towers6},
 
241
        {"7 rings", &Towers7},
 
242
        { NULL, NULL }
 
243
};
 
244
 
 
245
void towers_init (Game *game)
 
246
{
 
247
        game_single_player = TRUE;
 
248
        game_getmove = towers_getmove;
 
249
        game_who_won = towers_who_won;
 
250
        game_scorecmp = game_scorecmp_def_iscore;
 
251
        game_score_fields =  towers_score_fields;
 
252
        game_score_field_names = towers_score_field_names;
 
253
        game_reset_uistate = towers_reset_uistate;
 
254
        game_get_render = towers_get_render;
 
255
        game_levels = towers_levels;
 
256
        game_doc_about_status = STATUS_COMPLETE;
 
257
        game_doc_about = 
 
258
                "Towers\n"
 
259
                "Single player game\n"
 
260
                "Status: Fully implemented\n"
 
261
                "URL: "GAME_DEFAULT_URL("towers");
 
262
        game_doc_rules = 
 
263
                " Transfer all the rings from the first pole to the last. A ring can never lie on a smaller one.";
 
264
                ;
 
265
 
 
266
        if (game == &Towers)
 
267
                num_rings = 4;
 
268
        else if (game == &Towers5)
 
269
                num_rings = 5;
 
270
        else if (game == &Towers6)
 
271
                num_rings = 6;
 
272
        else if (game == &Towers7)
 
273
                num_rings = 7;
 
274
}
 
275
 
 
276
static gboolean towers_over (byte *board)
 
277
{
 
278
        return board [TOWERS_TOWER_WID/2] != TOWERS_RING_BOT && 
 
279
                board [TOWERS_TOWER_WID/2+TOWERS_TOWER_WID] != TOWERS_RING_BOT;
 
280
}
 
281
 
 
282
ResultType towers_who_won (Pos *pos, Player to_play, char **commp)
 
283
{
 
284
        static char comment[32];
 
285
        gboolean over = towers_over (pos->board);
 
286
        char *scorestr = over ? "You won. Moves:" : "Moves:";
 
287
        snprintf (comment, 32, "%s %d", scorestr, pos->num_moves);
 
288
        *commp = comment;
 
289
        return over ? RESULT_WON : RESULT_NOTYET;
 
290
}
 
291
 
 
292
 
 
293
static int cur_row = -1;
 
294
 
 
295
#define POLE_ROW(x) (((x)/TOWERS_TOWER_WID)*TOWERS_TOWER_WID+TOWERS_TOWER_WID/2)
 
296
 
 
297
// Find the heit and len of the top ring in the tower corresp to row
 
298
static void get_top_ring (byte *board, int row, int *heit, int *len)
 
299
{
 
300
        int pole_row = POLE_ROW (row);
 
301
        int i, j;
 
302
        for (j = board_heit - 1; j >= 0; j--)
 
303
                if (board [j * board_wid + pole_row] == TOWERS_RING_TOP)
 
304
                        break;
 
305
        if (j < 0)
 
306
        {
 
307
                if (heit) *heit = -1;
 
308
                if (len) *len = -1;
 
309
                return; 
 
310
        }
 
311
        for (i=0; ; i++)
 
312
                if (board [j * board_wid + pole_row + i] != TOWERS_RING_TOP)
 
313
                        break;
 
314
        if (heit) *heit = j;
 
315
        if (len) *len = i;
 
316
}
 
317
 
 
318
int towers_getmove 
 
319
        (Pos *pos, int x, int y, GtkboardEventType type, Player to_play, byte **movp, int ** rmovep)
 
320
{
 
321
        static byte move[512];
 
322
        static int rmove[512];
 
323
        byte *mp = move;
 
324
        int *rp = rmove;
 
325
        int heit1, heit2, len1, len2;
 
326
        int i, j, pole_row;
 
327
        
 
328
        if (type != GTKBOARD_BUTTON_RELEASE)
 
329
                return 0;
 
330
        if (cur_row < 0)
 
331
        {
 
332
                get_top_ring (pos->board, x, &heit1, &len1);
 
333
                if (heit1 < 0)
 
334
                        return -1;
 
335
                cur_row = x;
 
336
                pole_row = POLE_ROW(x);
 
337
                for (j=0; j<=1; j++)
 
338
                for (i = pole_row - len1 + 1; i <= pole_row + len1 - 1; i++)
 
339
                {
 
340
                        *rp++ = i;
 
341
                        *rp++ = heit1 - j;
 
342
                        *rp++ = RENDER_SHADE1;
 
343
                }
 
344
                *rp++ = -1;
 
345
                *rmovep = rmove;
 
346
                return 0;
 
347
        }
 
348
        
 
349
        get_top_ring (pos->board, cur_row, &heit1, &len1);
 
350
        get_top_ring (pos->board, x, &heit2, &len2);
 
351
 
 
352
        pole_row = POLE_ROW(cur_row);
 
353
        for (j=0; j<=1; j++)
 
354
        for (i = pole_row - len1 + 1; i <= pole_row + len1 - 1; i++)
 
355
        {
 
356
                *mp++ = i;
 
357
                *mp++ = heit1 - j;
 
358
                *mp++ = i == pole_row ? TOWERS_POLE : TOWERS_EMPTY;
 
359
                *rp++ = i;
 
360
                *rp++ = heit1 - j;
 
361
                *rp++ = 0;
 
362
        }
 
363
        *rp++ = -1;
 
364
        *rmovep = rmove;
 
365
 
 
366
        if (POLE_ROW(cur_row) == POLE_ROW(x))
 
367
        {
 
368
                cur_row = -1;
 
369
                return 0;
 
370
        }
 
371
        
 
372
        if (heit2 >= 0 && len1 > len2)
 
373
        {
 
374
                cur_row = -1;
 
375
                return -1;
 
376
        }
 
377
 
 
378
        heit2 += 2;
 
379
 
 
380
        pole_row = POLE_ROW(x);
 
381
        for (j=0; j<=1; j++)
 
382
        for (i = pole_row - len1 + 1; i <= pole_row + len1 - 1; i++)
 
383
        {
 
384
                *mp++ = i;
 
385
                *mp++ = heit2 - j;
 
386
                *mp++ = j == 0 ? TOWERS_RING_TOP : TOWERS_RING_BOT;
 
387
        }
 
388
        *mp++ = -1;
 
389
        *movp = move;
 
390
        cur_row = -1;
 
391
        return 1;
 
392
}
 
393
 
 
394
void towers_reset_uistate ()
 
395
{
 
396
        cur_row = -1;
 
397
}
 
398
 
 
399
void towers_get_render (Pos *pos, byte *move, int **rmovp)
 
400
{
 
401
        static int rmove[512];
 
402
        int *rp = rmove;
 
403
        int i, j;
 
404
        for (i=0; i<board_wid; i++)
 
405
        for (j=0; j<board_heit; j++)
 
406
                if (pos->render[j * board_wid + i] != RENDER_NONE)
 
407
                {
 
408
                        *rp++ = i;
 
409
                        *rp++ = j;
 
410
                        *rp++ = RENDER_NONE;
 
411
                }
 
412
        *rp++ = -1;
 
413
        *rmovp = rmove;
 
414
}