~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-1/src/wordtris.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 <assert.h>
22
 
#include <stdlib.h>
23
 
#include <time.h>
24
 
#include <gdk/gdkkeysyms.h>
25
 
 
26
 
 
27
 
#include "game.h"
28
 
#include "../pixmaps/alpha.xpm"
29
 
#include "flwords.h"
30
 
 
31
 
 
32
 
#define WORDTRIS_CELL_SIZE 36
33
 
 
34
 
#define WORDTRIS_NUM_PIECES 27
35
 
 
36
 
#define WORDTRIS_BOARD_WID 4
37
 
#define WORDTRIS_BOARD_HEIT 14
38
 
 
39
 
#define WORDTRIS_LEN 4
40
 
 
41
 
#define WORDTRIS_EMPTY 0
42
 
#define WORDTRIS_WILDCARD 27
43
 
 
44
 
char wordtris_colors[9] = {0xd7, 0xd7, 0xd7, 0xd7, 0xd7, 0xd7, 0, 0, 0xff};
45
 
char wordtris_highlight_colors[9] = {0x0, 0x0, 0xff, 0, 0, 0, 0, 0, 0};
46
 
 
47
 
static char *smiley_xpm[] = 
48
 
{
49
 
        "36 36 2 1",
50
 
        "  c none",
51
 
        ". c #ffff77",
52
 
        "                                    ",
53
 
        "                                    ",
54
 
        "                                    ",
55
 
        "                                    ",
56
 
        "                                    ",
57
 
        "                                    ",
58
 
        "                                    ",
59
 
        "                                    ",
60
 
        "                                    ",
61
 
        "         ...              ...       ",
62
 
        "        .....            .....      ",
63
 
        "         ...              ...       ",
64
 
        "                                    ",
65
 
        "                                    ",
66
 
        "                  ..                ",
67
 
        "                  ..                ",
68
 
        "                  ..                ",
69
 
        "                  ..                ",
70
 
        "                  ..                ",
71
 
        "                  ..                ",
72
 
        "                  ..                ",
73
 
        "                                    ",
74
 
        "                                    ",
75
 
        "         ..                ..       ",
76
 
        "          ..              ..        ",
77
 
        "           ...          ...         ",
78
 
        "            ....      ....          ",
79
 
        "              ..........            ",
80
 
        "                ......              ",
81
 
        "                  ..                ",
82
 
        "                                    ",
83
 
        "                                    ",
84
 
        "                                    ",
85
 
        "                                    ",
86
 
        "                                    ",
87
 
        "                                    ",
88
 
};
89
 
 
90
 
static char **wordtris_pixmaps [] = 
91
 
{
92
 
        char_A_grey_36_36_xpm,
93
 
        char_B_grey_36_36_xpm,
94
 
        char_C_grey_36_36_xpm,
95
 
        char_D_grey_36_36_xpm,
96
 
        char_E_grey_36_36_xpm,
97
 
        char_F_grey_36_36_xpm,
98
 
        char_G_grey_36_36_xpm,
99
 
        char_H_grey_36_36_xpm,
100
 
        char_I_grey_36_36_xpm,
101
 
        char_J_grey_36_36_xpm,
102
 
        char_K_grey_36_36_xpm,
103
 
        char_L_grey_36_36_xpm,
104
 
        char_M_grey_36_36_xpm,
105
 
        char_N_grey_36_36_xpm,
106
 
        char_O_grey_36_36_xpm,
107
 
        char_P_grey_36_36_xpm,
108
 
        char_Q_grey_36_36_xpm,
109
 
        char_R_grey_36_36_xpm,
110
 
        char_S_grey_36_36_xpm,
111
 
        char_T_grey_36_36_xpm,
112
 
        char_U_grey_36_36_xpm,
113
 
        char_V_grey_36_36_xpm,
114
 
        char_W_grey_36_36_xpm,
115
 
        char_X_grey_36_36_xpm,
116
 
        char_Y_grey_36_36_xpm,
117
 
        char_Z_grey_36_36_xpm,
118
 
        smiley_xpm,
119
 
};
120
 
 
121
 
 
122
 
 
123
 
// TODO: change this so that we only need to specify pixmaps for individual squares
124
 
 
125
 
static const int lava_xpm_header_size = 253+1;
126
 
static char * lava_xpm_header[] = 
127
 
{
128
 
"144 504 253 2",
129
 
"       c #d7d7d7",
130
 
".      c #FFD800",
131
 
"+      c #FFAC00",
132
 
"@      c #FFA800",
133
 
"#      c #FF8000",
134
 
"$      c #FF0600",
135
 
"%      c #830000",
136
 
"&      c #310000",
137
 
"*      c #150000",
138
 
"=      c #1F0000",
139
 
"-      c #2D0000",
140
 
";      c #270000",
141
 
">      c #210000",
142
 
",      c #1B0000",
143
 
"'      c #230000",
144
 
")      c #1D0000",
145
 
"!      c #0B0000",
146
 
"~      c #010000",
147
 
"{      c #090000",
148
 
"]      c #2F0000",
149
 
"^      c #3B0000",
150
 
"/      c #630000",
151
 
"(      c #8B0000",
152
 
"_      c #930000",
153
 
":      c #8D0000",
154
 
"<      c #CF0000",
155
 
"[      c #FF6600",
156
 
"}      c #FF9E00",
157
 
"|      c #FF4C00",
158
 
"1      c #FF7A00",
159
 
"2      c #FF8E00",
160
 
"3      c #FF7600",
161
 
"4      c #FF5800",
162
 
"5      c #FF6200",
163
 
"6      c #FFB600",
164
 
"7      c #FFDA00",
165
 
"8      c #FF8C00",
166
 
"9      c #FF9400",
167
 
"0      c #FFCE00",
168
 
"a      c #FFD200",
169
 
"b      c #FF9A00",
170
 
"c      c #FF7800",
171
 
"d      c #FFF000",
172
 
"e      c #FFDE00",
173
 
"f      c #FFAE00",
174
 
"g      c #FF8400",
175
 
"h      c #FF7000",
176
 
"i      c #FF8200",
177
 
"j      c #FFA400",
178
 
"k      c #FFB000",
179
 
"l      c #FFA000",
180
 
"m      c #FF9800",
181
 
"n      c #FFAA00",
182
 
"o      c #FFEA00",
183
 
"p      c #FFD400",
184
 
"q      c #FF7400",
185
 
"r      c #FF6E00",
186
 
"s      c #FFCC00",
187
 
"t      c #FFBC00",
188
 
"u      c #FF7200",
189
 
"v      c #FFC400",
190
 
"w      c #FFEE00",
191
 
"x      c #FFA200",
192
 
"y      c #FF9200",
193
 
"z      c #FFB400",
194
 
"A      c #FFA600",
195
 
"B      c #FF9000",
196
 
"C      c #FF8800",
197
 
"D      c #FFD000",
198
 
"E      c #FF9C00",
199
 
"F      c #FF1000",
200
 
"G      c #D90000",
201
 
"H      c #FF0E00",
202
 
"I      c #FF5000",
203
 
"J      c #FF8600",
204
 
"K      c #FF9600",
205
 
"L      c #FF7E00",
206
 
"M      c #FF6C00",
207
 
"N      c #FF6000",
208
 
"O      c #FF4200",
209
 
"P      c #FF2600",
210
 
"Q      c #FF4400",
211
 
"R      c #FFE600",
212
 
"S      c #FF5C00",
213
 
"T      c #E50000",
214
 
"U      c #B30000",
215
 
"V      c #A90000",
216
 
"W      c #7F0000",
217
 
"X      c #550000",
218
 
"Y      c #5F0000",
219
 
"Z      c #890000",
220
 
"`      c #BF0000",
221
 
" .     c #F30000",
222
 
"..     c #ED0000",
223
 
"+.     c #AD0000",
224
 
"@.     c #7D0000",
225
 
"#.     c #DD0000",
226
 
"$.     c #FF2E00",
227
 
"%.     c #FF2C00",
228
 
"&.     c #FF1200",
229
 
"*.     c #370000",
230
 
"=.     c #110000",
231
 
"-.     c #070000",
232
 
";.     c #0F0000",
233
 
">.     c #130000",
234
 
",.     c #190000",
235
 
"'.     c #170000",
236
 
").     c #450000",
237
 
"!.     c #4D0000",
238
 
"~.     c #510000",
239
 
"{.     c #570000",
240
 
"].     c #9F0000",
241
 
"^.     c #FF3200",
242
 
"/.     c #FF4800",
243
 
"(.     c #D70000",
244
 
"_.     c #AF0000",
245
 
":.     c #E90000",
246
 
"<.     c #BD0000",
247
 
"[.     c #A30000",
248
 
"}.     c #FF8A00",
249
 
"|.     c #FF5200",
250
 
"1.     c #E30000",
251
 
"2.     c #9D0000",
252
 
"3.     c #FF3000",
253
 
"4.     c #FF0200",
254
 
"5.     c #FFD600",
255
 
"6.     c #910000",
256
 
"7.     c #C10000",
257
 
"8.     c #FF1E00",
258
 
"9.     c #FF3C00",
259
 
"0.     c #FF1800",
260
 
"a.     c #FF0800",
261
 
"b.     c #F10000",
262
 
"c.     c #E70000",
263
 
"d.     c #FF1400",
264
 
"e.     c #F50000",
265
 
"f.     c #970000",
266
 
"g.     c #FF4E00",
267
 
"h.     c #FF2A00",
268
 
"i.     c #FF1A00",
269
 
"j.     c #FF0400",
270
 
"k.     c #F70000",
271
 
"l.     c #F90000",
272
 
"m.     c #EF0000",
273
 
"n.     c #FF4000",
274
 
"o.     c #FF2800",
275
 
"p.     c #FF2200",
276
 
"q.     c #DB0000",
277
 
"r.     c #A50000",
278
 
"s.     c #D10000",
279
 
"t.     c #C50000",
280
 
"u.     c #670000",
281
 
"v.     c #6F0000",
282
 
"w.     c #9B0000",
283
 
"x.     c #AB0000",
284
 
"y.     c #DF0000",
285
 
"z.     c #8F0000",
286
 
"A.     c #A70000",
287
 
"B.     c #C90000",
288
 
"C.     c #FFB800",
289
 
"D.     c #FFE000",
290
 
"E.     c #FF0C00",
291
 
"F.     c #6D0000",
292
 
"G.     c #290000",
293
 
"H.     c #410000",
294
 
"I.     c #750000",
295
 
"J.     c #EB0000",
296
 
"K.     c #D50000",
297
 
"L.     c #5B0000",
298
 
"M.     c #000000",
299
 
"N.     c #050000",
300
 
"O.     c #390000",
301
 
"P.     c #770000",
302
 
"Q.     c #C30000",
303
 
"R.     c #B70000",
304
 
"S.     c #B50000",
305
 
"T.     c #FFB200",
306
 
"U.     c #A10000",
307
 
"V.     c #FFBA00",
308
 
"W.     c #FF5400",
309
 
"X.     c #FF0000",
310
 
"Y.     c #CB0000",
311
 
"Z.     c #870000",
312
 
"`.     c #D30000",
313
 
" +     c #4B0000",
314
 
".+     c #250000",
315
 
"++     c #FF6A00",
316
 
"@+     c #FFC000",
317
 
"#+     c #CD0000",
318
 
"$+     c #FF3600",
319
 
"%+     c #FF3400",
320
 
"&+     c #2B0000",
321
 
"*+     c #3F0000",
322
 
"=+     c #730000",
323
 
"-+     c #590000",
324
 
";+     c #850000",
325
 
">+     c #790000",
326
 
",+     c #3D0000",
327
 
"'+     c #B90000",
328
 
")+     c #330000",
329
 
"!+     c #030000",
330
 
"~+     c #430000",
331
 
"{+     c #690000",
332
 
"]+     c #FFBE00",
333
 
"^+     c #FFCA00",
334
 
"/+     c #FD0000",
335
 
"(+     c #FF3A00",
336
 
"_+     c #BB0000",
337
 
":+     c #490000",
338
 
"<+     c #7B0000",
339
 
"[+     c #810000",
340
 
"}+     c #6B0000",
341
 
"|+     c #650000",
342
 
"1+     c #E10000",
343
 
"2+     c #FF5E00",
344
 
"3+     c #B10000",
345
 
"4+     c #0D0000",
346
 
"5+     c #FFC600",
347
 
"6+     c #710000",
348
 
"7+     c #FFC800",
349
 
"8+     c #C70000",
350
 
"9+     c #470000",
351
 
"0+     c #FFE400",
352
 
"a+     c #FF0A00",
353
 
"b+     c #FF5A00",
354
 
"c+     c #FFC200",
355
 
"d+     c #FF5600",
356
 
"e+     c #FF1600",
357
 
"f+     c #990000",
358
 
"g+     c #FF7C00",
359
 
"h+     c #5D0000",
360
 
"i+     c #530000",
361
 
"j+     c #FF2400",
362
 
"k+     c #FFE200",
363
 
"l+     c #FF6400",
364
 
"m+     c #610000",
365
 
"n+     c #4F0000",
366
 
"o+     c #950000",
367
 
"p+     c #FF3E00",
368
 
"q+     c #FF2000",
369
 
"r+     c #350000",
370
 
"s+     c #FB0000",
371
 
"t+     c #FF6800",
372
 
"u+     c #FF1C00",
373
 
"v+     c #FF4A00",
374
 
"w+     c #FFEC00",
375
 
"x+     c #FF4600",
376
 
"y+     c #FF3800",
377
 
"z+     c #FFDC00",
378
 
"A+     c #FFE800",
379
 
"B+     c #FFF600",
380
 
"C+     c #FFF200",
381
 
"D+     c #FFF400",
382
 
};
383
 
 
384
 
static char *lava_xpm_data[] =
385
 
{
386
 
". + @ # $ % & * = - - ; > , = ' ) ! ~ { = ] ^ / ( _ : ( < [ } [ | 1 2 3 4 5 6 7 6 8 3 3 9 0 a b c 9 a d e f g h h i j k j l m 8 9 n a o d p 9 q r q 9 s t r u v w o p 6 x x x x } y 9 f z A A z n B # 3 c C n D E F G H I h 1 J y E K L h r M N O P Q f R a @ m S T U V W X Y Z `  ...+.@.W #.8 ",
387
 
"} $.%.&._ *.=.-.{ ;.>.,.) ,., > , ! ~ -.'.) ) ] ).!.~.{.].^./.(._.:. .<.[.:.}.z |.1.[.2. .B @ 3.< 4.m 5.} %.` _ 6.7.8.9.0.a.b.G c.d.5 A D K e.2.: f...g C d.$.n . 6 C g.h.i.j.k.l.m.k.n.I o.3./.p.q.U ].r.s.%.} 1 t.u.v.Z w.x.7.G ..y.+.z._ w.A.B.4.|.C.D.k 5 n.E.V W Z F.*.G.H.I.B.J.V {.).+.1 ",
388
 
"i m.J.K.L.=.~ M.M.~ N.>.= = ) = '.-.~ N.=.>.! ;.= - *.O.P.E.3.Q.Z R.< S.+.l.B T.n.x.H.] U.r V.S :.$ 9 C.W.< Y ] - u.(.X.Y.r.6.% Z.w.B.%.l J `. += .+( I g 9.++@+@ |.$.d.4.q.: F.( V #+$.I $.$+%+y.W ).G.& F.T i M V *.; &+& *+{.u.=+/ *.] -+Z +.T 9.# k a s l [ X.].I.;+>+,+'.) H.6.#.'+{.)+w.q ",
389
 
"C e.c.(./ * !+M.M.M.{ , G.; .+; , { ~ N.=.=.-.{ ) O.~+,+{+m.O d.Y.q.%.5 h J ]+^+C /+v.O.Z.(+6 t y 9 @+x o._+=+!.:+<+< :.S.[+}+{+}+|+P...2 f O _+|+*.>+3.x f v 6 | 1+(.1. .(.>+~+P.q.P g + l A }.o.S.-+' ' L.q.# M V *..+- *+X {+P.>+/ ).F.y.9.5 3 J h 2+9 p 7 2 j.3+_ U.A.P.,+.+&+/ ` t.F.~+r.c ",
390
 
"b $.8.E.U. +; >.N.N.>.; - ' > G.' 4+!+! >.=.-.{ *.Z.+.V R.X.n.3.1+J.h 5+6 i h C x ++y.6+{+t.Q m 7+7+b 4 4.8+].<+>+r.B.Y._.P. +9+~.!.F.k.C C.A h 8.Q.B.O t 0+v I R.W _+J.H a+'+% < b+@ D s + c+^+j I K.W }+: l.8 r x.O.- !.W r.U _+_+2._ ..N # ++d+%+a.e+[ v D.8  .+.f+]._+R.;+!.&  +2.7.[+~._.g+",
391
 
"@+B L 4 e.].F.~+= '..+& ; * * .+G.'.;.* '.;.N.>.=+i.M h M q 1 Q 8+Y.q 6 W.#+w.s.I 9 n.+.L.h+2.i.} 9 F <.V [.6.W f.8+Q.x.r.Z.i+9+~.X Z i.J 2 l ]+f g+q j . 0+B <  +u.k.5 C i Q j+M c+k+k+x 9.W.9 v c+# (+8.p.4 + q +.^ ,+>+_+Y.<._+S.].t.Q u &.+.Z.<+_.9.l D p g m.2.% P.( +.x.W  +).% U Z.X A.++",
392
 
"z 8 l+3.1+U.;+v.!.O.*.] , { ! ' & ; ) ,.>.4+>.*+B.# V.j T.7+c+5 x.V l+L #+*+) !.1.L r `.Y O.X (.i M V ). +/ m+h+6.1+K.f.2.2.F.-+-+L.6.i.g i 1 j l 3 3 } 6 c+u _.:+w.| } b f 6 6 s 7+6 5+i 1+S.b.N V.p 7+t C.v p 3 A.^ n+6.+.% L.i+i+{.A.(+9.w.- >.' o+l+V.K M 3.#+z.I.|+h+=+w.U.6+ +<+U ].>+V %.",
393
 
"n.X.S.Z u.~.X }+6+{.*.) ! !+{ = & ] = ;.4+; }+8+W.V.b Q N n s h x.x.5 N 6.* ~ , Z p+L q+_+f++.&.9 l+z.> &+:+:+H.>+1+:.A.U B.6.h+9+).v.s.(+M 1 ++i.` 8+i.| u r X.` E.c S 0.d+z e v l+$+8 h R.X |+Q.|.V.e k+D.0+7 r 2.,+m+o+% H.'.=.>..+% 0.H F.=.!+) ].M E j+U ( [+@.{+h+{.L.@._.f+h+}++.< Y.B.y.",
394
 
"_.;+X O.- G.]  +P.F.r+;.!+M.N.* .+; * -.=.}+F g+V.@+[ s+$ S T.}.s+s+i 5 ( =.M.-.9+G N # M [ q E @+5 Z = G.~+ +9+=+K.s+1+4.p.:.Z.9+O.9+u.].e.%+H w.H.i+R./+q+g.|./.l+N ..w.b.1 7+8 1+B.[ N f+.+) ~.#+Q u 3 c g 8 (+( ).6+6./ .+{ -.{ ,.6+j.a+P.> * ] r.t+A o.I.& !.}+|+X i+Y @._+B.% {.I.x.t.Q.` ",
395
 
"F./ -+~.9+O.- O.u.<+ +'.-.-.! >.> &+' , *+8+L V.m t+u+1+..3.2 k }.B @+M 6.* M.~ , }+J.| M C ]+a f (+>+, ' ^ ).9+u.S...$ %.d+Q Y.-+*.*.r+!.2.1+t.|+> G.P.Q.1+e.j+p+O u+V ;+1.2+6 h _.V 2+S ( >.N..+=++._.U.U.t.s+q.{+H.F.% X ) N.N.-.* h+c.0._.{.H.:+_ $+A 4 ( &+^ L.u.{.:+-+[+B. .S.-+9+L.}+W [.",
396
 
"W v.F.P.v.!.r+& !.=+Y - ,.'.,.) - X W _ #+W.V.K j+ .y.#+s.m.o.2+# f ^+L S.G.N.-.>.*.P.+.` X.8 f d+:.|+> ' & )+& 9+;+R.G  .%.4 l.6+H.*+*+n+: `.K.( ).- ).[+_._+J.a.d.H G `.a.v+@ J y.t.l+2+( >.!+= X {+9+&+G.-+3+` @./ @.% X = N.~ !+>.n+8+p.k.A.[+}+=+1.i [ U.*.^ {.}+|+!. +{+U a.T =+*+)+] n+o+",
397
 
"A.Z.W ( [+-+*.&+*./ =+!.- ) ,.= n+Q.(+t+g C.@+t+e.(.t.V V x.+.<.:.p+}.2 j.i+=.,.&+,+~.-+{.V ++B 8.< ( L. +~+*..+- Y z.x.8+&.d+&.w.=+>+>+=+Z._+T K.].v.-+=+w.'+T J.T $ 0.0.4.d.2 z /.a.3 ++[.; >.- Y |+*.,.> -+Q./+c.`.` : i+> -.~ 4+)+P.s.0.F 1+8+U.<+7.r M 3+^ )+~.v.=+L.).).Z H F 6.).G., ~+].",
398
 
"_+( ;+6.% |+9+r+O.Y Z W X - > ~+U W.C.6 8 g u %. .Y.2.Z f+2._ _ 3+ .I m Q @.= ; *.,+*+O.r+o+l+B %.&.H m.Y._.: i+- H.v.6.` u+d+e+Y.Q.(.K.3+( 6.Q.:.T #+3+V U `./+K.2.+.K.s.U.+.n.z C 9.8 B X.w.% 6.[.% ,+.+:+( 1.^.4 I H _.u.)+>.* *+( s.l.F s+q.s.t.2.B.r 3 Q.~+&+:+6+>+Y ~+r+I.F $.x.H.,.;.*+V ",
399
 
"S.6+I.6.[+/  +^ ^ L.o+'+r.W Z < |.V.c+M a+/+&.X.K.].;+o++._.r.3+s.F c t q R.~+& ] > ,.>.> o+M k i 2 l B 3 t+n.G {+^ :+|+f.l.| P q.8+`.s.` +.x.Q.1+:.k.a.X.m.4.E.7.{+-+u.Y 9+Y c.B @ 3 + V.q O $+9.o.(.}+i+<+f+x.(.d.h.a.G _.P.i+u.+...l.../+$ :.(.G ` G q K a+Z.~.{.I.[+{+~+&+h+e.n.#+).>.>.:+U ",
400
 
"+.-+L.( @.n+O.] &+*+v.+.`. .O J t c+c j.t.s.1.#+[.( w.S.'+r.o++.G 8.B p f q+[+,+G.=.N.{ ^ #+2 7 p 7 p V.T.+ m 5 J.W X {.=+R.u+%+c.2.<+6+@.f+` 1.b.T y./+e+d.a+:.o+~.,+:+~.h+;+e.K D 5+7+} 4 p+Q b+u v+q.].f.>+!.:+|+<+o+S.B.8+8+:.H X.B.r.S.< #+< .. .e+K 7+i H A.v.m+}+|+*+) O.7.Q a+P.~+i+Z q.",
401
 
"f.).H.W @.).' * ;.* - u.#+Q f v b N a+t.S._+S.U._ r.Q.t.A.@.v.f.<.T d+c+^+d+A.:+- >.{ - r.I 5+o w+o s j l y y n g+0.s._.6.;+7.F  .w.X O.^ X ;+<.c.m.8+_.` s.Q.2.}+ + +u.Z R.s+W.k R o 6 p+K.<.< $ [ 8 ^.'+I.~+,.{ 4+,.)+-+Z t.e.a.c.3+[+{+/ v.% U H I g @+p k [ 4.Z H.).L.).,.) _ x+/.Q.2.Y.k.e+",
402
 
"=+*+*+<+% :+, { ~ ~ { O.Q.q s E 8.`._.w.f+w.w.f.[._+8+x.@.L.|+f+3+'+d.} T.^.w.L.9+] G.P.3.6 a c+c+5.D @+v ]+t 5.p k }.d+J.W P.t.c.R.<+X ).:+Y <+r.q.G U 2.o+W {+Y m+6+f.K.o.L f v 0+o m m.[+6+f+m.q 2 a+=+] * N.M.M.-.'.G.!.;+r.o+F.-+!.O..+' H.r.O l j i [ I v+y+<.~+& i+ +) * Z.W.t+G S.1.e...",
403
 
"v.L.Y Z f+u.&+! M.M.~ ' _.1 @+5 `.6.( : _ f+o+o+].A.f+@./ m+W x._+_+X.B x %.< _+S.r.U...C 5+B d+W.r L 9 @+z+0+o 0+R A+^+M T U.r.#+8+3+U.6.Z Z.>+>+2.7.8+_+].I.|+6+( x.1+9.K a k+e w+o b  .[+u.:  .J q R.- -.~ M.M.~ ! ) - ,+:+~+- ' ] ] ,.-.N..+r.[ j n.Q.z.6.(.^.X.6+r+~.n+.+> o+N [ R.@.A._.w.",
404
 
"% I.<+2._+[.{.'.~ M.M.* _ t+b 0.V : o+A.+.].z.z.: <+F.{+{+F.[+[.Q.q.q+E @+2 r ++++[ ++2 v j %+e.1+t.'+1.Q E 5.0+. A+B+C+0 2 O /+k.4.j.b.` [.o+Z.% <+P.( x.+.;+v.@.x...n.y 5+R w+0+k+e z x+7.I.Z X.2 ++w.= !+M.M.~ 4+&+~.{+u.9+= { ;.; ; ;.!+-.&+_.r c Q.^ * > v.X.3.'+~.i+|+Y W :.# N f+~.@.U.V ",
405
 
"[.F.u.: t.(._ )+-.M.M.=.( 5 }.a.3+V <.B.U : [+;+I.m+{+P.F.Y v.U.y.p.S y 9 u 5 5 t+3 b 5+D L s+7.2.m+,+-+S.%+n 5.p e w+D+d z+6 8 # C }.I #+<+m+}+: Z -+ +<+U.f.( w.q.Q K z c+z+0 y u r q t+0.U 3+q+} q U ^ ,.! ! = ).% _+(.8+Z *+, , &+; >.>.& {+1+# 5 6.* M.N.r+` (+k.6+|+A.m.y+1 x Q W & {.f.s.",
406
 
"Q.|+^ X w.y.Y./ ) ! { ,.6.t+@ /.e.(.s._+( }+6+6+/ }+% @.m+m+( #+e+W.N (+k.S.f+].S.m.|.l } 9.Y.U [.F.X @.< %.++q h u 9 0 0 9 r N l+g V.y ../ & ~+[+[.6+H.6+8+:.m.a+v+l ^+5+D . }.J.f.6._+8.I 3.%.++z c 7.-+*+)+,+F.r.K.c.m.l.T x.<+m+n+*+O.-+w.1+(+l [ z.* M.M.,.Z %.p.2.[.e+++L q I y.!.>..+v.(.",
407
 
":.W H.,+F.B...f+^ , ,.G.f.++7+9 P `.A.Z.u./ v.{+/ P.W Y ~.@.Q.j.p+|.8.s.f.Y r+& |+#.d+M y+:.Q.1+k.1+T 0.O %.c.V z.w.b.}.}. .w.Z o+:.J V.x+_ *.r+P.'+2.m+2.y+i }.B + 0 7 . D.c+%+P.) * *+3+^.2+5 g k 2+[.n+ +L.@.+.t.S.z.W A.:.H H b.t.r.U.B.l.F p+E c U ; !+M.;.P.%.| k.q+q ++F t.f+-+, !+=.Y 1.",
408
 
"a+U.{+Y }+_.b._+n+) ,..+@.y+V.l F 2.P.{+/ {+F.u.{+I.|+*+i+x.s+$+4 %+1._.o+=+).] I.E.g.s+A.].Q.k.^.d+5 4 h.G [+,+= - ].[ q _+r+>.) >+9.t 9 j.f.u._ m.X.#+4.8 t 8 ++[ M h y v }.Y.r+N.~ >.h+< 0.n.8 b &.|+' - ~.[+f.% X - = ,+Z q.8.v+W.v+p.k.s._.y.++9 a.-+4+!+, Z /.2 u i r s+W ).& ,.-.M.=.{+/+",
409
 
"u+V P.=+>+[...s.L.= '.,  +y.8 l o.s.R.f+I.Y -+Y {+u.~.).% e.v+l+n...S.f+% <+u.X o+u+$.U >+_ r.A.s.&.i.#.f+=+h+^ > - 6.I C s+~.! 4+-+E.n 0 b /.b.a.M y g+}.C.2 X.U.: ( 2.e.i h 3+- ! { ) {+q.j+W.x 3 S.&+-.4+&+X L.,+' ;.N.4+; X r.8.c b I t.{+ +W 0.y S x.*.& F.1+g 7+6 g+4.<+- , ,.=.-.~ =.F.d.",
410
 
"o.A.v.P.( 7.F 4.2.u./ |+W y.h + 2 3 l+d.f.X ~./ {+h+L.Z.b.S g+/.:.x.f.I.i+|+( +.m.g.v+T _+S.: X !.u.v.~.r+O.!.:+^ ,+P.d.2 W.].)+^ x.W.v 0+k+^+} l @+C.g t+l+$.].O.,.>.] U.| g+$ Z n+).6+#.v+q K c+[ ( >.M.~ '.,+*+.+'.4+!+M.!+* F.u+8 J d.@.] = ~+` N 2 $.7.t.j+L V.t 1 a+W G.;.4+=.>.4+-.=.6+j+",
411
 
"9.J.< q.e.$.t+2+i.s+s+l.l.E.h.I l+i n l+<.u.6+6.A.+.8+&.u 2 I #.f+z.W n+G.~+2.0.3 x # q+q.V 6+,+= '., ) ) &+,+,+r+& :+'+2+C 8._+< /.k t A v e . ]+2 Q q.2.f.f.=+,+'.! .+[+j.M u P < U 1+(+2+/.u 6 [ Z =.M.~ * O.^ = * =.N.M.M.=.W v+y h.].).= * )+: u+g 9 g+C k f g+y+y.% ] { N.! =.>.;.{ =.6+%.",
412
 
"u u c L J B C l+%+H 4.l.J.t.f+Z f...i 8 a.R.Q.j.p+2+3 y B | G <+|+=+h+r+' ^ ].O m L y+K.Z.{.*+& > =.4+>.> )+r+.+'.=., m+k.3 B 3 i k n g.E.(+t+r Q J.2.i+.+> O.{.{.^ ' & }+_+q+q [ &.:.j.o.a.1+3.l l+( =.M.~ * *.^ > * =.N.M.~ > A.t+q < X ] ' ' 9+z.1.%.5 C c+t |.B.% u.).,.-.! * ,.* ;.-.;.F.j+",
413
 
"A K q l+S x+&.:.7.: I.=+|+:+G.'..+( g.@ i I | h g+i B g+P R.|+,+~+Y / / @.U.J.2+N m.6.i+G.* * ' G.= >.;.) O.O.) { !+N..+Z.0.g+2 3 l+j+V Y v.Z o+: {+9+.+;.-.* *.X -+:+9+{+f.K.%.n.a+m./+l.7.Y.d+C.N Z.=.M.~ =.& ^ .+,.=.N.M.{ n+e.# /.f.^ )+*+i+P.w.+.U <.4.2 } a.m+- *+^ ,.4+* ,.* 4+N.~ ! h+k.",
414
 
"[ &.R.z.Z.<+6+P.F.~+&+> '.! N.N.* Y ..2+K f j u $.i.j+/+U.~.- .+& L.2.c.3.S 1 J ^.o+^ , ! N.-.'.G.- .+'.) ,+ +*+- ,.4+, -+Y.e+X.7.o+{+- ;.4+>.) ; - &+> '.>.=.) *.n+n+!.}+f+B.$ p.e+E.4.`.f+s.g+T.%.u.4+M.~ ;.G.*.&+) >.N.!+> f.v+g+e./ - ^ {+f.+.[.% }+m++.M 6 9.>+&+^ ^ ) * '.;.-.~ M.M.! !.Q.",
415
 
"G >+&+>.;.=.= 9+L.H.> 4+!+M.~ ! ,.)+/ V i.8 9 p+X.k.1.[.L.] = , .+/ :.S c u 5 $+#+-+G..+' = ,.'.> ] r+] ]  +6+Z.W / i+Y z.`.G : ).> ;.!+M.M.!+{ =.) &+)+*.)+.+, > r+^ ^ L._ #+e.H p.P /+U ( y.i i B.)+!+M.N.>..+)+- = >.{ ,.u./+1 | [.O.; H.>+U.2.@.h+~.n+o+I c+g #+X 9+H.' ,.=.N.M.M.M.!+>.9+2.",
416
 
"f+,+{ M.M.M.4+] n+~+, N.M.M.N.=.'.>.>.] f+$+r n.&.T U.Y *.> >.* )+Z p.u $.K.V W n+- ] 9+h+Y  +O.H.L.P.Z.;+Z.o+r.V +.` K.c.c.3+{.= -.M.M.~ -.4+* ,.' *. +X ~.*+&+= ; )+*.9+P.U < :.j+| $.1.8+e+y t+6.* ~ ~ { * > ] &+) ,., ~.G S 5 :.Y &+] ).|+6+h+n+n+-+L.Z.8.k ]+n.U./ n+- ,.4+!+M.M.!+4+) :+o+",
417
 
"A.!.>.!+M.M.N.= H.,+'.~ M.!+4+* =.N.M.! -+ .W.y+y.Z ).' , * 4+.+v.Y.3.b+e.=+O..+, = r+h+% Z P.6+o+8+..j.$ T _.@.6+6.` K.#+x.F.] ;.!+!+-.4+* ,., ,.= & 9+i+X n+~+)+] *.,+!.v.w.3+s.H p+9.p.p.4 @ [ Z =.!+{ >.,.= &+G.) G.-+<.| q 4.@.r+; ] O.9+X -+|+v.I.{+@. .2 0 1 B.>+Y r+'.-.~ M.!+4+* ) *+Z ",
418
 
"G 6.~.; 4+!+N.) *+^ * !+!+4+* * ! !+M.N.^ 3+E.:.>+- ;.{ =.* ,.n+_.:.a.%.:./ > =.;., r+{.I.P.>+: <.1.J.m.s+b.+.i+&+,+/ }+-+~+- '.! -.4+* ,.,.* ;.! ! =.) ' G.*.i+P.% =+m+u.P.z.U.3+t.s.#. .E.Q l l+( >.N.;.'.* , G.G.G./ K.x+i n.2.*.) '.* ,.)+m+W W v.Y ~.m+Q.5 @+# `.[+u.*+) ! !+!+4+* * =.- }+",
419
 
"$ s+K._ n+> >.&+9+O.'.{ ;.,., =.{ -.-.4+] <+Q.U n+>.-.{ * ; !.w.1+K.7.l.J.>+& > > ]  +m+F.}+@.f+U V % P._ 7.x.{..+&+H.*+&+> > = , = ; &+; > ,.* =.=.>.>.* '.- <+k.$+e+y.Y.t.R.r.U.2.: ( 2.3+X.C [ f.' '.' G..+&+*.*.~.8+| 3 | #.Y ' ,.'.* = :+Z f.{+H.,+n+6+Q.S ]+i s.>+u.X *.) ;.;.'.,.=.4+' ~.",
420
 
"^.b+W.H U Y & ^  +^ ' , ) = , >.;.>.'.) )+|+A.U F.,+& - *+=+8+u+%+X.1.q+o.`.[.w.2.V _+Q.t.R.S.G ..s.V w.S.m.s+t.2.w.x.V o+: z.z.z.o+w.f.6.: Z Z Z Z Z Z.[+P.Z T 3 @+z K J h p+a.e.m.q.B.B.G j+} }...f.: f.2.].2.: P.U.h.J t+u+G [.: ( Z Z o+7.b.y.: u.( _+1.j+9 D L s.6+|+F.}+{.H.*.)+)+] - O.~.",
421
 
"@ C.b (+q.Z.:+H. +9+^ - = ,.=.4+>.= ' ; )+-+U.B.3+o+% I.: J.5 x l i i } y N 5 q c 1 i g g+| 8.4 J i q h 3 B b J 3 3 1 1 u h M r r u q h h r r r r M M ++4 (+9.3 5+w d w+A+z+@+l m K 8 i # J A 5.D 9 u h u 3 u b+i.T /+r C.f 2 1 h M M M M u J B [ a...(+1 y + 5.7 1 q.>+|+@.].x.f+I.m+{+v.6+6+I.",
422
 
};
423
 
 
424
 
 
425
 
typedef struct
426
 
{
427
 
        int score;
428
 
        int lives;
429
 
} Wordtris_state;
430
 
 
431
 
static int total_lives = 10;
432
 
 
433
 
 
434
 
static int wordtris_wordcmp (const void *p1, const void *p2)
435
 
{
436
 
        return strcmp ((char *)p1, *(char **)p2);
437
 
}
438
 
 
439
 
static void wordtris_init ();
440
 
int wordtris_getmove (Pos *, int, int, GtkboardEventType, Player, byte **, int **);
441
 
int wordtris_getmove_kb (Pos *, int, byte **, int **);
442
 
void wordtris_free ();
443
 
ResultType wordtris_who_won (Pos *, Player , char **);
444
 
int wordtris_animate (Pos *pos, byte **movp);
445
 
static void *wordtris_newstate (Pos *, byte *);
446
 
 
447
 
Game Wordtris = { WORDTRIS_CELL_SIZE, WORDTRIS_BOARD_WID, WORDTRIS_BOARD_HEIT, 
448
 
        WORDTRIS_NUM_PIECES, 
449
 
        wordtris_colors, NULL, wordtris_pixmaps, 
450
 
        "Wordtris", "Word games", 
451
 
        wordtris_init};
452
 
 
453
 
/* This list was produced using
454
 
 
455
 
  $  egrep -x [a-z]{4} /usr/share/dict/words | perl -e 'while (<>) {foreach $i ((0 .. 3)) {$count{substr($_,$i,1)}++}} foreach $c (("a" .. "z")) {print $count{$c}, "\n"}'
456
 
 
457
 
  Perl totally rocks
458
 
*/
459
 
 
460
 
static float charcounts[26] = 
461
 
{
462
 
        629,
463
 
        223,
464
 
        205,
465
 
        302,
466
 
        746,
467
 
        152,
468
 
        186,
469
 
        182,
470
 
        395,
471
 
        30,
472
 
        167,
473
 
        460,
474
 
        234,
475
 
        338,
476
 
        503,
477
 
        272,
478
 
        6,
479
 
        395,
480
 
        622,
481
 
        404,
482
 
        276,
483
 
        63,
484
 
        173,
485
 
        24,
486
 
        125,
487
 
        28,
488
 
};
489
 
 
490
 
static char ** wordtris_getbgxpm ()
491
 
{
492
 
        int i;
493
 
        static char *xpm[lava_xpm_header_size + WORDTRIS_CELL_SIZE * WORDTRIS_BOARD_HEIT];
494
 
        static char emptyline[WORDTRIS_CELL_SIZE * WORDTRIS_BOARD_WID * 2];
495
 
        for (i=0; i<WORDTRIS_CELL_SIZE * WORDTRIS_BOARD_WID * 2; i++)
496
 
                emptyline[i] = ' ';
497
 
        for (i=0; i<lava_xpm_header_size; i++)
498
 
                xpm[i] = lava_xpm_header[i];
499
 
        for (i=0; i<WORDTRIS_CELL_SIZE*WORDTRIS_BOARD_HEIT; i++)
500
 
                xpm[i+lava_xpm_header_size] = emptyline;
501
 
        for (i=WORDTRIS_CELL_SIZE; i<2*WORDTRIS_CELL_SIZE; i++)
502
 
                xpm[WORDTRIS_CELL_SIZE * (WORDTRIS_BOARD_HEIT-3)+i+lava_xpm_header_size] = lava_xpm_data [i-WORDTRIS_CELL_SIZE];
503
 
        return xpm;
504
 
}
505
 
 
506
 
// returns hamming distance
507
 
static int diffcnt (const char *w1, const char *w2, int len)
508
 
{
509
 
        int cnt = 0, i;
510
 
        for (i=0; i<len; i++)
511
 
                if (w1[i] != w2[i])
512
 
                        cnt++;
513
 
        return cnt;
514
 
}
515
 
 
516
 
static void wordtris_set_init_pos (Pos *pos)
517
 
{
518
 
        int i, j;
519
 
        const char *word;
520
 
        for (i=0; i<board_wid * board_heit; i++)
521
 
                pos->board[i] = 0;
522
 
        // make sure we have a neighbor
523
 
        while (1)
524
 
        {
525
 
                word = flwords [random() % num_flwords];
526
 
                for (i=0; i<WORDTRIS_LEN; i++)
527
 
                        pos->board [i] = word[i] - 'a' + 1;
528
 
                for (j=0; j<num_flwords; j++)
529
 
                        if (diffcnt (word, flwords[j], WORDTRIS_LEN) == 1)
530
 
                                return;
531
 
        }
532
 
}
533
 
 
534
 
static void wordtris_set_init_render (Pos *pos)
535
 
{
536
 
        pos->render [0] = RENDER_HIGHLIGHT1;
537
 
}
538
 
 
539
 
static void wordtris_init ()
540
 
{
541
 
        int i;
542
 
        static char emptyline[WORDTRIS_BOARD_WID * WORDTRIS_CELL_SIZE];
543
 
        static char dottedline[WORDTRIS_BOARD_WID * WORDTRIS_CELL_SIZE];
544
 
        game_single_player = TRUE;
545
 
        game_set_init_pos = wordtris_set_init_pos;
546
 
        game_free = wordtris_free;
547
 
        game_getmove = wordtris_getmove;
548
 
        game_getmove_kb = wordtris_getmove_kb;
549
 
        game_who_won = wordtris_who_won;
550
 
        game_scorecmp = game_scorecmp_def_dscore;
551
 
        game_animation_time = 2000;
552
 
        game_animate =  wordtris_animate;
553
 
        game_stateful = TRUE;
554
 
        game_state_size = sizeof (Wordtris_state);
555
 
        game_newstate = wordtris_newstate;
556
 
        game_bg_pixmap = wordtris_getbgxpm ();
557
 
        game_highlight_colors = wordtris_highlight_colors;
558
 
        game_set_init_render = wordtris_set_init_render;
559
 
        game_doc_about_status = STATUS_COMPLETE;
560
 
        game_doc_about = 
561
 
                "Wordtris\n"
562
 
                "Single player game\n"
563
 
                "Status: Partially implemented (playable)\n"
564
 
                "URL: "GAME_DEFAULT_URL("wordtris");
565
 
        game_doc_rules = 
566
 
                "Press Ctrl+G to start the game.\n\n"
567
 
                " Click one of the letters of the word at the bottom and type the letter on one of the falling blocks to change that letter to the new letter. The new word must be legal.\n"
568
 
                "The smiley face acts as a wildcard and can be used as an arbitrary letter.\n"
569
 
                "\n"
570
 
                "You get a point for every new word you make. You have a total of ten lives. You lose a life when a block falls to the bottom row. The game ends when you lose all your lives.";
571
 
        game_doc_strategy = 
572
 
                "Try to replace rarely occuring letters with more commonly occuring     letters\n";
573
 
}
574
 
 
575
 
static int wordtris_curx = 0, wordtris_cury = 0;
576
 
 
577
 
ResultType wordtris_who_won (Pos *pos, Player to_play, char **commp)
578
 
{
579
 
        static char comment[32];
580
 
        int i;
581
 
        *commp = comment;
582
 
        for (i=0; i<WORDTRIS_LEN; i++)
583
 
                if (pos->board [2 * board_wid + i] != WORDTRIS_EMPTY 
584
 
                                && pos->state && ((Wordtris_state *)pos->state)->lives == 0)
585
 
                {
586
 
                        snprintf (comment, 32, "Game over. Score: %d", 
587
 
                                        pos->state ? ((Wordtris_state *)pos->state)->score: 0);
588
 
                        return RESULT_WON;
589
 
                }
590
 
        snprintf (comment, 32, "Score: %d;  Lives: %d", 
591
 
                                        pos->state ? ((Wordtris_state *)pos->state)->score: 0,
592
 
                                        pos->state ? ((Wordtris_state *)pos->state)->lives: total_lives);
593
 
        return RESULT_NOTYET;
594
 
}
595
 
 
596
 
void *wordtris_newstate (Pos *pos, byte *move)
597
 
{
598
 
        static Wordtris_state state;
599
 
        int i, score = 0, count = 0, died = 0;
600
 
        for (i=0; move[3*i] >= 0; i++)
601
 
        {
602
 
                if (move[3*i+1] == 0)
603
 
                        score = 1;
604
 
                if (move[3*i+2] == WORDTRIS_EMPTY) 
605
 
                        count--;
606
 
                else
607
 
                        count++;
608
 
        }
609
 
        if (count + score < 1) died = 1;
610
 
        state.score = (pos->state ? ((Wordtris_state *)pos->state)->score : 0) + score;
611
 
        state.lives = (pos->state ? ((Wordtris_state *)pos->state)->lives : total_lives) - died;
612
 
        return &state;
613
 
}
614
 
 
615
 
int wordtris_getmove (Pos *pos, int x, int y, GtkboardEventType type, Player to_play, 
616
 
                byte **movp, int ** rmovep)
617
 
{
618
 
        static int rmove[7];
619
 
        int *rp = rmove;
620
 
        if (type != GTKBOARD_BUTTON_RELEASE)
621
 
                return 0;
622
 
        if (y != 0) return 0;
623
 
        if (wordtris_curx != x)
624
 
        {
625
 
                *rp++ = wordtris_curx;
626
 
                *rp++ = 0;
627
 
                *rp++ = 0;
628
 
                *rp++ = x;
629
 
                *rp++ = 0;
630
 
                *rp++ = RENDER_HIGHLIGHT1;
631
 
                *rp++ = -1;             
632
 
                *rmovep = rmove;
633
 
        }
634
 
        wordtris_curx = x;
635
 
        return 0;
636
 
}
637
 
 
638
 
 
639
 
gboolean wordtris_findletter (byte *board, int letter, int *x, int *y)
640
 
{
641
 
        int i, j;
642
 
        int minx = -1, miny = board_heit, minval = WORDTRIS_WILDCARD;
643
 
        for (i=0; i < WORDTRIS_LEN; i++)
644
 
        {
645
 
                for (j=1; j<board_heit; j++)
646
 
                {
647
 
                        int val = board [j * board_wid + i];
648
 
                        if (val == letter || val == WORDTRIS_WILDCARD)
649
 
                        {
650
 
                                if ((j < miny 
651
 
                                                && (val != WORDTRIS_WILDCARD || minval == WORDTRIS_WILDCARD))
652
 
                                                || (minval == WORDTRIS_WILDCARD && val != WORDTRIS_WILDCARD))
653
 
                                {
654
 
                                        minx = i;
655
 
                                        miny = j;
656
 
                                        minval = val;
657
 
                                }
658
 
                        }
659
 
#ifdef ONLY_LOWEST
660
 
                        else if (val != WORDTRIS_EMPTY)
661
 
                                break;
662
 
#endif
663
 
                }
664
 
        }
665
 
        if (miny >= board_heit) return FALSE;
666
 
        *x = minx;
667
 
        *y = miny;
668
 
        return TRUE;
669
 
}
670
 
 
671
 
int wordtris_getmove_kb (Pos *pos, int key, byte **movp, int **rmovp)
672
 
{
673
 
        static int rmove[10];
674
 
        static byte move[10];
675
 
        byte *mp = move;
676
 
        int *rp = rmove;
677
 
        if (key == GDK_Right)
678
 
        {
679
 
                *rp++ = wordtris_curx;
680
 
                *rp++ = 0;
681
 
                *rp++ = 0;
682
 
                if (++wordtris_curx == WORDTRIS_LEN) wordtris_curx = 0;
683
 
                *rp++ = wordtris_curx;
684
 
                *rp++ = 0;
685
 
                *rp++ = RENDER_HIGHLIGHT1;
686
 
                *rp++ = -1;
687
 
                *rmovp = rmove;
688
 
                return 0;
689
 
        }
690
 
        if (key == GDK_Left)
691
 
        {
692
 
                *rp++ = wordtris_curx;
693
 
                *rp++ = 0;
694
 
                *rp++ = 0;
695
 
                if (--wordtris_curx < 0) wordtris_curx = WORDTRIS_LEN - 1;
696
 
                *rp++ = wordtris_curx;
697
 
                *rp++ = 0;
698
 
                *rp++ = RENDER_HIGHLIGHT1;
699
 
                *rp++ = -1;
700
 
                *rmovp = rmove;
701
 
                return 0;
702
 
        }
703
 
        if (key >= GDK_A && key <= GDK_Z)
704
 
                key = key + GDK_a - GDK_A;
705
 
        if (key >= GDK_a && key <= GDK_z)
706
 
        {
707
 
                int i, x, y;
708
 
                char word [WORDTRIS_LEN+1];
709
 
                gboolean found = wordtris_findletter (pos->board, key - GDK_a + 1, &x, &y);
710
 
                if (!found) return -1;
711
 
                if (wordtris_curx < 0) return -1;
712
 
                for (i=0; i<WORDTRIS_LEN; i++)
713
 
                        word[i] = pos->board [i] - 1 + 'a';
714
 
                word [WORDTRIS_LEN] = '\0';
715
 
                if (word [wordtris_curx] == key - GDK_a + 'a') return -1;
716
 
                word [wordtris_curx] = key - GDK_a + 'a';
717
 
                if (!bsearch (word, flwords, num_flwords, sizeof (flwords[0]), wordtris_wordcmp))
718
 
                        return -1;
719
 
                *mp++ = wordtris_curx; *mp++ = wordtris_cury; *mp++ = key - GDK_a + 1;
720
 
                *mp++ = x; *mp++ = y; *mp++ = WORDTRIS_EMPTY;
721
 
                *mp++ = -1;
722
 
                *movp = move;
723
 
                return 1;
724
 
        }
725
 
        return -1;
726
 
}
727
 
 
728
 
void wordtris_free ()
729
 
{
730
 
        wordtris_curx = wordtris_cury = 0;
731
 
}
732
 
 
733
 
int wordtris_get_rand_char ()
734
 
{
735
 
        int i, sum, thresh;
736
 
        if (random () % 10 == 0)
737
 
                return WORDTRIS_WILDCARD;
738
 
        for (i=0, sum=0; i<26; i++)
739
 
                sum += charcounts[i];
740
 
        thresh = random() % sum;
741
 
        for (i=0, sum=0; i<26; i++)
742
 
                if ((sum += charcounts[i]) > thresh)
743
 
                        return i + 1;
744
 
        assert (0);
745
 
        return -1;
746
 
}
747
 
 
748
 
int wordtris_animate (Pos *pos, byte **movp)
749
 
{
750
 
        static byte move[1024];
751
 
        int i, j;
752
 
        byte *mp = move;
753
 
        byte *board = pos->board;
754
 
        for (i=0; i<board_wid; i++)
755
 
        for (j=board_heit-1; j>=1; j--)
756
 
        {
757
 
                int val;
758
 
                if ((val = pos->board [j * board_wid + i]) != WORDTRIS_EMPTY)
759
 
                {
760
 
                        *mp++ = i;
761
 
                        *mp++ = j;
762
 
                        *mp++ = WORDTRIS_EMPTY;
763
 
                        if (j > 2)
764
 
                        {
765
 
                                *mp++ = i;
766
 
                                *mp++ = j-1;
767
 
                                *mp++ = val;
768
 
                        }
769
 
                }
770
 
        }
771
 
        while (1)
772
 
        {
773
 
                i = random() % WORDTRIS_LEN;
774
 
                if (pos->board [(board_heit - 1) * board_wid + i])
775
 
                        continue;
776
 
                *mp++ = i;
777
 
                *mp++ = board_heit - 1;
778
 
                *mp++ = wordtris_get_rand_char();
779
 
                break;
780
 
        }
781
 
        *mp = -1;
782
 
        *movp = move;
783
 
        return 1;
784
 
}
785
 
 
786
 
 
787