~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/infiltrate.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 <string.h>
 
21
#include <stdlib.h>
 
22
#include <math.h>
 
23
 
 
24
#include "game.h"
 
25
#include "aaball.h"
 
26
 
 
27
#define INFILTRATE_CELL_SIZE 40
 
28
#define INFILTRATE_NUM_PIECES 2
 
29
 
 
30
#define INFILTRATE_BOARD_WID 5
 
31
#define INFILTRATE_BOARD_HEIT 5
 
32
 
 
33
#define INFILTRATE_EMPTY 0
 
34
#define INFILTRATE_WP 1
 
35
#define INFILTRATE_BP 2
 
36
 
 
37
char infiltrate_colors[] = 
 
38
        {180, 180, 180, 
 
39
        200, 200, 200};
 
40
        
 
41
int     infiltrate_init_pos[] = 
 
42
{
 
43
         2 , 2 , 2 , 2 , 2 ,
 
44
         2 , 0 , 0 , 0 , 2 ,
 
45
         0 , 0 , 0 , 0 , 0 ,
 
46
         1 , 0 , 0 , 0 , 1 ,
 
47
         1 , 1 , 1 , 1 , 1 ,
 
48
};
 
49
 
 
50
static int infiltrate_max_moves = 200;
 
51
 
 
52
 
 
53
void infiltrate_init ();
 
54
int infiltrate_getmove (Pos *, int, int, GtkboardEventType, Player, byte **, int **);
 
55
//ResultType infiltrate_who_won (byte *, int, char **);
 
56
byte *infiltrate_movegen (Pos *);
 
57
ResultType infiltrate_eval (Pos *, Player, float *);
 
58
guchar * infiltrate_get_rgbmap (int idx, int color);
 
59
void infiltrate_reset_uistate ();
 
60
        
 
61
Game Infiltrate = 
 
62
        { INFILTRATE_CELL_SIZE, INFILTRATE_BOARD_WID, INFILTRATE_BOARD_HEIT, 
 
63
        INFILTRATE_NUM_PIECES,
 
64
        infiltrate_colors, infiltrate_init_pos, NULL, "Infiltrate", NULL,
 
65
        infiltrate_init};
 
66
 
 
67
void infiltrate_init ()
 
68
{
 
69
        game_getmove = infiltrate_getmove;
 
70
        game_movegen = infiltrate_movegen;
 
71
        //game_who_won = infiltrate_who_won;
 
72
        game_eval = infiltrate_eval;
 
73
        game_get_rgbmap = infiltrate_get_rgbmap;
 
74
        game_reset_uistate = infiltrate_reset_uistate;
 
75
        game_doc_about_status = STATUS_PARTIAL;
 
76
        game_doc_about = 
 
77
                "Infiltrate\n"
 
78
                "Two player game\n"
 
79
                "Status: Partially implemented\n"
 
80
                "URL: "GAME_DEFAULT_URL ("infiltrate");
 
81
        game_doc_rules = 
 
82
                "The pieces move diagonally, one square at a time. The objective is to get all your pieces to the starting squares of your opponent's pieces.\n";
 
83
}
 
84
 
 
85
byte * infiltrate_movegen (Pos *pos)
 
86
{
 
87
        int i, j, diffx, diffy;
 
88
        byte movbuf [256];
 
89
        byte *movlist, *mp = movbuf;
 
90
        byte *board = pos->board;
 
91
        Player player = pos->player;
 
92
        for (i=0; i<board_wid; i++)
 
93
        for (j=0; j<board_heit; j++)
 
94
        {
 
95
                if (player == BLACK && (board [j * board_wid + i] != INFILTRATE_BP))
 
96
                        continue;
 
97
                if (player == WHITE && (board [j * board_wid + i] != INFILTRATE_WP))
 
98
                        continue;
 
99
                for (diffx = -1; diffx <= 1; diffx += 2)
 
100
                for (diffy = -1; diffy <= 1; diffy += 2)
 
101
                {
 
102
                        int x, y;
 
103
                        if (!ISINBOARD(x = i+diffx, y = j+diffy)) continue;
 
104
                        if (board [y * board_wid + x] != 0) continue;
 
105
                        *mp++ = i; *mp++ = j; *mp++ = 0;
 
106
                        *mp++ = i + diffx; *mp++ = j + diffy; 
 
107
                        *mp++ = (player == WHITE ? INFILTRATE_WP : INFILTRATE_BP);
 
108
                        *mp++ = -1;
 
109
                }
 
110
        }
 
111
        if (mp == movbuf)
 
112
                *mp++ = -1;
 
113
        *mp++ = -2;
 
114
        movlist = (byte *) (malloc (mp - movbuf));
 
115
        memcpy (movlist, movbuf, (mp - movbuf));
 
116
        return movlist;
 
117
}
 
118
 
 
119
ResultType infiltrate_eval (Pos *pos, Player to_play, float *eval)
 
120
{
 
121
        float sum = 0;
 
122
        int i, j;
 
123
        for (i=0; i<board_wid; i++)
 
124
        for (j=0; j<board_heit; j++)
 
125
                if (pos->board [j * board_wid + i])
 
126
                        sum += j;
 
127
        *eval = sum;
 
128
        return RESULT_NOTYET;
 
129
 
 
130
}
 
131
 
 
132
static int oldx = -1, oldy = -1;
 
133
 
 
134
void infiltrate_reset_uistate ()
 
135
{
 
136
        oldx = -1, oldy = -1;
 
137
}
 
138
        
 
139
int infiltrate_getmove (Pos *pos, int x, int y, GtkboardEventType type, Player to_play, 
 
140
                byte **movp, int ** rmovep)
 
141
{
 
142
        static byte move[10];
 
143
        byte *mp = move;
 
144
        byte *board = pos->board;
 
145
        if (type != GTKBOARD_BUTTON_RELEASE) return 0;
 
146
        if (oldx < 0)
 
147
        {
 
148
                int val = board [y * board_wid + x];
 
149
                if ((val != INFILTRATE_BP && !(to_play == WHITE)) ||
 
150
                (val != INFILTRATE_WP && !(to_play == BLACK)))
 
151
                        return -1;
 
152
                oldx = x; oldy = y;
 
153
                return 0;
 
154
        }
 
155
        else
 
156
        {
 
157
                int diffx, diffy;
 
158
                diffx = x - oldx;
 
159
                diffy = y - oldy;
 
160
                if (abs (diffx) != 1 || abs (diffy) != 1)
 
161
                {
 
162
                        oldx = -1; oldy = -1;
 
163
                        return -1;
 
164
                }
 
165
                if (board [y * board_wid + x] != INFILTRATE_EMPTY)
 
166
                {
 
167
                        oldx = -1; oldy = -1;
 
168
                        return -1;
 
169
                }
 
170
                *mp++ = oldx; *mp++ = oldy; *mp++ = 0;
 
171
                *mp++ = x; *mp++ = y; *mp++ = board [oldy * board_wid + oldx];
 
172
                *mp++ = -1;
 
173
                *movp = move;
 
174
                oldx = oldy = -1;
 
175
                return 1;
 
176
 
 
177
        }
 
178
}
 
179
 
 
180
guchar *infiltrate_get_rgbmap (int idx, int color)
 
181
{
 
182
        static guchar rgbbuf[3*INFILTRATE_CELL_SIZE*INFILTRATE_CELL_SIZE];
 
183
        int fg, bg, i;
 
184
        char *colors;
 
185
        colors = infiltrate_colors;
 
186
        fg = (idx == INFILTRATE_WP ? 0xffffff : 0x0000ff);
 
187
        if (color == BLACK) colors += 3;
 
188
        for(i=0, bg=0;i<3;i++) 
 
189
        { int col = colors[i]; if (col<0) col += 256; bg += col * (1 << (16-8*i));}
 
190
        rgbmap_ball_shadow_gen(INFILTRATE_CELL_SIZE, rgbbuf, fg, bg, 8, 24, 2);
 
191
        return rgbbuf;
 
192
}
 
193
 
 
194
/*
 
195
char ** infiltrate_get_pixmap (int idx, int color)
 
196
{
 
197
        int bg;
 
198
        int i;
 
199
        static char pixbuf[INFILTRATE_CELL_SIZE * (INFILTRATE_CELL_SIZE+1)];
 
200
        for(i=0, bg=0;i<3;i++) 
 
201
        { int col = infiltrate_colors[i]; 
 
202
                if (col<0) col += 256; bg += col * (1 << (16-8*i));}
 
203
        return pixmap_ball_gen (INFILTRATE_CELL_SIZE, pixbuf,
 
204
                        idx == INFILTRATE_WP ? 0xffffff : 0x0000ff, bg, 
 
205
                        8, 24);
 
206
}
 
207
*/