diff options
author | Dave Chapman <dave@dchapman.com> | 2006-03-03 15:01:37 +0000 |
---|---|---|
committer | Dave Chapman <dave@dchapman.com> | 2006-03-03 15:01:37 +0000 |
commit | 7ceadd79db71cee6b2ae7f89f992e896fd11c02c (patch) | |
tree | 7e71c901a5d55804d1538905d3eef589ee0add86 /apps/plugins/chessbox/chessbox.c | |
parent | 8dccb294a851f8814f739cefa5d5e290ffd68371 (diff) | |
download | rockbox-7ceadd79db71cee6b2ae7f89f992e896fd11c02c.tar.gz rockbox-7ceadd79db71cee6b2ae7f89f992e896fd11c02c.zip |
Patch #4736 for Chessbox from Miguel A. Arévalo - Added support for user interaction while thinking, you can force move now with PLAY and quit with OFF (iRiver example). Yield only on Search as any Evaluate will be preceded by a Search. Plus some minor code policing from me to remove tabs in both the patch and the original code
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8896 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/chessbox/chessbox.c')
-rw-r--r-- | apps/plugins/chessbox/chessbox.c | 634 |
1 files changed, 334 insertions, 300 deletions
diff --git a/apps/plugins/chessbox/chessbox.c b/apps/plugins/chessbox/chessbox.c index 161de45e90..2e863b957b 100644 --- a/apps/plugins/chessbox/chessbox.c +++ b/apps/plugins/chessbox/chessbox.c | |||
@@ -26,9 +26,9 @@ | |||
26 | 26 | ||
27 | /* type definitions */ | 27 | /* type definitions */ |
28 | struct cb_command { | 28 | struct cb_command { |
29 | int type; | 29 | int type; |
30 | char mv_s[5]; | 30 | char mv_s[5]; |
31 | unsigned short mv; | 31 | unsigned short mv; |
32 | }; | 32 | }; |
33 | 33 | ||
34 | /* External bitmaps */ | 34 | /* External bitmaps */ |
@@ -131,7 +131,7 @@ PLUGIN_HEADER | |||
131 | #define TILE_WIDTH 8 | 131 | #define TILE_WIDTH 8 |
132 | #define TILE_HEIGHT 8 | 132 | #define TILE_HEIGHT 8 |
133 | #else | 133 | #else |
134 | #error BEJEWELED: Unsupported LCD | 134 | #error CHESSBOX: Unsupported LCD |
135 | #endif | 135 | #endif |
136 | 136 | ||
137 | /* Calculate Offsets */ | 137 | /* Calculate Offsets */ |
@@ -139,11 +139,15 @@ PLUGIN_HEADER | |||
139 | #define YOFS ((LCD_HEIGHT-8*TILE_HEIGHT)/2) | 139 | #define YOFS ((LCD_HEIGHT-8*TILE_HEIGHT)/2) |
140 | 140 | ||
141 | /* commands enum */ | 141 | /* commands enum */ |
142 | #define COMMAND_MOVE 1 | 142 | #define COMMAND_NOP 0 |
143 | #define COMMAND_PLAY 2 | 143 | #define COMMAND_MOVE 1 |
144 | #define COMMAND_LEVEL 3 | 144 | #define COMMAND_PLAY 2 |
145 | /*#define COMMAND_RESTART 4*/ | 145 | #define COMMAND_LEVEL 3 |
146 | #define COMMAND_QUIT 5 | 146 | /*#define COMMAND_RESTART 4*/ |
147 | #define COMMAND_QUIT 5 | ||
148 | |||
149 | /* "While thinking" command */ | ||
150 | int wt_command = COMMAND_NOP; | ||
147 | 151 | ||
148 | /* GCC wants this to be present for some targets */ | 152 | /* GCC wants this to be present for some targets */ |
149 | void* memcpy(void* dst, const void* src, size_t size) | 153 | void* memcpy(void* dst, const void* src, size_t size) |
@@ -153,278 +157,298 @@ void* memcpy(void* dst, const void* src, size_t size) | |||
153 | 157 | ||
154 | /* ---- Get the board column and row (e2 f.e.) for a physical x y ---- */ | 158 | /* ---- Get the board column and row (e2 f.e.) for a physical x y ---- */ |
155 | void xy2cr ( short x, short y, short *c, short *r ) { | 159 | void xy2cr ( short x, short y, short *c, short *r ) { |
156 | if (computer == black ) { | 160 | if (computer == black ) { |
157 | *c = x ; | 161 | *c = x ; |
158 | *r = y ; | 162 | *r = y ; |
159 | } else { | 163 | } else { |
160 | *c = 7 - x ; | 164 | *c = 7 - x ; |
161 | *r = 7 - y ; | 165 | *r = 7 - y ; |
162 | } | 166 | } |
163 | } | 167 | } |
164 | 168 | ||
165 | /* ---- get physical x y for a board column and row (e2 f.e.) ---- */ | 169 | /* ---- get physical x y for a board column and row (e2 f.e.) ---- */ |
166 | void cr2xy ( short c, short r, short *x, short *y ) { | 170 | void cr2xy ( short c, short r, short *x, short *y ) { |
167 | if ( computer == black ) { | 171 | if ( computer == black ) { |
168 | *x = c ; | 172 | *x = c ; |
169 | *y = r ; | 173 | *y = r ; |
170 | } else { | 174 | } else { |
171 | *x = 7 - c ; | 175 | *x = 7 - c ; |
172 | *y = 7 - r ; | 176 | *y = 7 - r ; |
173 | } | 177 | } |
174 | } | 178 | } |
175 | 179 | ||
176 | /* ---- Draw a complete board ---- */ | 180 | /* ---- Draw a complete board ---- */ |
177 | static void cb_drawboard (void) { | 181 | static void cb_drawboard (void) { |
178 | short r , c , x , y ; | 182 | short r , c , x , y ; |
179 | short l , piece , p_color ; | 183 | short l , piece , p_color ; |
180 | int b_color=1; | 184 | int b_color=1; |
181 | 185 | ||
182 | rb->lcd_clear_display(); | 186 | rb->lcd_clear_display(); |
183 | 187 | ||
184 | for (r = 0; r < 8; r++) { | 188 | for (r = 0; r < 8; r++) { |
185 | for (c = 0; c < 8; c++) { | 189 | for (c = 0; c < 8; c++) { |
186 | l = locn[r][c]; | 190 | l = locn[r][c]; |
187 | piece = board[l] ; | 191 | piece = board[l] ; |
188 | p_color = color[l] ; | 192 | p_color = color[l] ; |
189 | cr2xy ( c , r , &x , &y ); | 193 | cr2xy ( c , r , &x , &y ); |
190 | if ( piece == no_piece ) { | 194 | if ( piece == no_piece ) { |
191 | rb->lcd_bitmap_part ( chessbox_pieces , 0 , | 195 | rb->lcd_bitmap_part ( chessbox_pieces , 0 , |
192 | TILE_HEIGHT * b_color , | 196 | TILE_HEIGHT * b_color , |
193 | TILE_WIDTH , | 197 | TILE_WIDTH , |
194 | XOFS + x*TILE_WIDTH , | 198 | XOFS + x*TILE_WIDTH , |
195 | YOFS + ( 7 - y )*TILE_HEIGHT , | 199 | YOFS + ( 7 - y )*TILE_HEIGHT , |
196 | TILE_WIDTH , | 200 | TILE_WIDTH , |
197 | TILE_HEIGHT ); | 201 | TILE_HEIGHT ); |
198 | } else { | 202 | } else { |
199 | rb->lcd_bitmap_part ( chessbox_pieces , | 203 | rb->lcd_bitmap_part ( chessbox_pieces , |
200 | 0 , | 204 | 0 , |
201 | 2 * TILE_HEIGHT + | 205 | 2 * TILE_HEIGHT + |
202 | 4 * TILE_HEIGHT * ( piece - 1 ) + | 206 | 4 * TILE_HEIGHT * ( piece - 1 ) + |
203 | 2 * TILE_HEIGHT * p_color + | 207 | 2 * TILE_HEIGHT * p_color + |
204 | TILE_HEIGHT * b_color , | 208 | TILE_HEIGHT * b_color , |
205 | TILE_WIDTH , | 209 | TILE_WIDTH , |
206 | XOFS + x*TILE_WIDTH , | 210 | XOFS + x*TILE_WIDTH , |
207 | YOFS + (7 - y)*TILE_HEIGHT , | 211 | YOFS + (7 - y)*TILE_HEIGHT , |
208 | TILE_WIDTH , | 212 | TILE_WIDTH , |
209 | TILE_HEIGHT ); | 213 | TILE_HEIGHT ); |
210 | } | 214 | } |
211 | b_color = (b_color == 1) ? 0 : 1 ; | 215 | b_color = (b_color == 1) ? 0 : 1 ; |
212 | } | 216 | } |
213 | b_color = (b_color == 1) ? 0 : 1 ; | 217 | b_color = (b_color == 1) ? 0 : 1 ; |
218 | } | ||
219 | |||
220 | /* draw board limits */ | ||
221 | if ( LCD_WIDTH > TILE_WIDTH*8 ) { | ||
222 | rb->lcd_set_drawmode ( DRMODE_FG ); | ||
223 | rb->lcd_drawline ( XOFS - 1 , YOFS , | ||
224 | XOFS - 1 , YOFS + TILE_HEIGHT*8 ); | ||
225 | rb->lcd_drawline ( XOFS + 8*TILE_WIDTH , YOFS , | ||
226 | XOFS + 8*TILE_WIDTH , YOFS + TILE_HEIGHT*8 ); | ||
227 | } | ||
228 | if ( LCD_HEIGHT > TILE_HEIGHT*8 ) { | ||
229 | rb->lcd_set_drawmode ( DRMODE_FG ); | ||
230 | rb->lcd_drawline ( XOFS , YOFS - 1 , | ||
231 | XOFS + TILE_WIDTH*8 , YOFS - 1 ); | ||
232 | rb->lcd_drawline ( XOFS , YOFS + TILE_HEIGHT*8 , | ||
233 | XOFS + 8*TILE_WIDTH , YOFS + TILE_HEIGHT*8 ); | ||
214 | } | 234 | } |
215 | 235 | rb->lcd_update(); | |
216 | /* draw board limits */ | ||
217 | if ( LCD_WIDTH > TILE_WIDTH*8 ) { | ||
218 | rb->lcd_set_drawmode ( DRMODE_FG ); | ||
219 | rb->lcd_drawline ( XOFS - 1 , YOFS , | ||
220 | XOFS - 1 , YOFS + TILE_HEIGHT*8 ); | ||
221 | rb->lcd_drawline ( XOFS + 8*TILE_WIDTH , YOFS , | ||
222 | XOFS + 8*TILE_WIDTH , YOFS + TILE_HEIGHT*8 ); | ||
223 | } | ||
224 | if ( LCD_HEIGHT > TILE_HEIGHT*8 ) { | ||
225 | rb->lcd_set_drawmode ( DRMODE_FG ); | ||
226 | rb->lcd_drawline ( XOFS , YOFS - 1 , | ||
227 | XOFS + TILE_WIDTH*8 , YOFS - 1 ); | ||
228 | rb->lcd_drawline ( XOFS , YOFS + TILE_HEIGHT*8 , | ||
229 | XOFS + 8*TILE_WIDTH , YOFS + TILE_HEIGHT*8 ); | ||
230 | } | ||
231 | rb->lcd_update(); | ||
232 | } | 236 | } |
233 | 237 | ||
234 | /* ---- Switch mark on board ---- */ | 238 | /* ---- Switch mark on board ---- */ |
235 | void cb_switch ( short x , short y ) { | 239 | void cb_switch ( short x , short y ) { |
236 | rb->lcd_set_drawmode ( DRMODE_COMPLEMENT ); | 240 | rb->lcd_set_drawmode ( DRMODE_COMPLEMENT ); |
237 | rb->lcd_drawrect ( XOFS + x*TILE_WIDTH + 1 , | 241 | rb->lcd_drawrect ( XOFS + x*TILE_WIDTH + 1 , |
238 | YOFS + ( 7 - y )*TILE_HEIGHT +1 , | 242 | YOFS + ( 7 - y )*TILE_HEIGHT +1 , |
239 | TILE_WIDTH-2 , TILE_HEIGHT-2 ); | 243 | TILE_WIDTH-2 , TILE_HEIGHT-2 ); |
240 | rb->lcd_update(); | 244 | rb->lcd_update(); |
245 | } | ||
246 | |||
247 | /* ---- callback for capturing interaction while thinking ---- */ | ||
248 | void cb_wt_callback ( void ) { | ||
249 | int button = BUTTON_NONE; | ||
250 | |||
251 | wt_command = COMMAND_NOP; | ||
252 | button = rb->button_get(false); | ||
253 | switch (button) { | ||
254 | case CB_QUIT: | ||
255 | wt_command = COMMAND_QUIT; | ||
256 | timeout = true; | ||
257 | break; | ||
258 | case CB_PLAY: | ||
259 | wt_command = COMMAND_PLAY; | ||
260 | timeout = true; | ||
261 | break; | ||
262 | } | ||
241 | } | 263 | } |
242 | 264 | ||
243 | /* ---- increase playing level ---- */ | 265 | /* ---- increase playing level ---- */ |
244 | void cb_levelup ( void ) { | 266 | void cb_levelup ( void ) { |
245 | Level ++; | 267 | Level ++; |
246 | if ( Level == 8 ) Level = 1; | 268 | if ( Level == 8 ) Level = 1; |
247 | switch (Level) { | 269 | switch (Level) { |
248 | case 1 : | 270 | case 1 : |
249 | TCmoves = 60; | 271 | TCmoves = 60; |
250 | TCminutes = 5; | 272 | TCminutes = 5; |
251 | rb->splash ( 50 , true , "Level 1: 60 moves / 5 min" ); | 273 | rb->splash ( 50 , true , "Level 1: 60 moves / 5 min" ); |
252 | break; | 274 | break; |
253 | case 2 : | 275 | case 2 : |
254 | TCmoves = 60; | 276 | TCmoves = 60; |
255 | TCminutes = 15; | 277 | TCminutes = 15; |
256 | rb->splash ( 50 , true , "Level 2: 60 moves / 15 min" ); | 278 | rb->splash ( 50 , true , "Level 2: 60 moves / 15 min" ); |
257 | break; | 279 | break; |
258 | case 3 : | 280 | case 3 : |
259 | TCmoves = 60; | 281 | TCmoves = 60; |
260 | TCminutes = 30; | 282 | TCminutes = 30; |
261 | rb->splash ( 50 , true , "Level 3: 60 moves / 30 min" ); | 283 | rb->splash ( 50 , true , "Level 3: 60 moves / 30 min" ); |
262 | break; | 284 | break; |
263 | case 4 : | 285 | case 4 : |
264 | TCmoves = 40; | 286 | TCmoves = 40; |
265 | TCminutes = 30; | 287 | TCminutes = 30; |
266 | rb->splash ( 50 , true , "Level 4: 40 moves / 30 min" ); | 288 | rb->splash ( 50 , true , "Level 4: 40 moves / 30 min" ); |
267 | break; | 289 | break; |
268 | case 5 : | 290 | case 5 : |
269 | TCmoves = 40; | 291 | TCmoves = 40; |
270 | TCminutes = 60; | 292 | TCminutes = 60; |
271 | rb->splash ( 50 , true , "Level 5: 40 moves / 60 min" ); | 293 | rb->splash ( 50 , true , "Level 5: 40 moves / 60 min" ); |
272 | break; | 294 | break; |
273 | case 6 : | 295 | case 6 : |
274 | TCmoves = 40; | 296 | TCmoves = 40; |
275 | TCminutes = 120; | 297 | TCminutes = 120; |
276 | rb->splash ( 50 , true , "Level 6: 40 moves / 120 min" ); | 298 | rb->splash ( 50 , true , "Level 6: 40 moves / 120 min" ); |
277 | break; | 299 | break; |
278 | case 7 : | 300 | case 7 : |
279 | TCmoves = 40; | 301 | TCmoves = 40; |
280 | TCminutes = 240; | 302 | TCminutes = 240; |
281 | rb->splash ( 50 , true , "Level 7: 40 moves / 240 min" ); | 303 | rb->splash ( 50 , true , "Level 7: 40 moves / 240 min" ); |
282 | break; | 304 | break; |
283 | case 8 : | 305 | case 8 : |
284 | TCmoves = 1; | 306 | TCmoves = 1; |
285 | TCminutes = 15; | 307 | TCminutes = 15; |
286 | rb->splash ( 50 , true , "Level 8: 1 move / 15 min" ); | 308 | rb->splash ( 50 , true , "Level 8: 1 move / 15 min" ); |
287 | break; | 309 | break; |
288 | case 9 : | 310 | case 9 : |
289 | TCmoves = 1; | 311 | TCmoves = 1; |
290 | TCminutes = 60; | 312 | TCminutes = 60; |
291 | rb->splash ( 50 , true , "Level 9: 1 move / 60 min" ); | 313 | rb->splash ( 50 , true , "Level 9: 1 move / 60 min" ); |
292 | break; | 314 | break; |
293 | case 10 : | 315 | case 10 : |
294 | TCmoves = 1; | 316 | TCmoves = 1; |
295 | TCminutes = 600; | 317 | TCminutes = 600; |
296 | rb->splash ( 50 , true , "Level 10: 1 move / 600 min" ); | 318 | rb->splash ( 50 , true , "Level 10: 1 move / 600 min" ); |
297 | break; | 319 | break; |
298 | } | 320 | } |
299 | TCflag = (TCmoves > 1); | 321 | TCflag = (TCmoves > 1); |
300 | SetTimeControl(); | 322 | SetTimeControl(); |
301 | }; | 323 | }; |
302 | 324 | ||
303 | /* ---- main user loop ---- */ | 325 | /* ---- main user loop ---- */ |
304 | struct cb_command cb_getcommand (void) { | 326 | struct cb_command cb_getcommand (void) { |
305 | static short x = 4 , y = 4 ; | 327 | static short x = 4 , y = 4 ; |
306 | short c , r , l; | 328 | short c , r , l; |
307 | int button, lastbutton = BUTTON_NONE; | 329 | int button, lastbutton = BUTTON_NONE; |
308 | int marked = false , from_marked = false ; | 330 | int marked = false , from_marked = false ; |
309 | short marked_x = 0 , marked_y = 0 ; | 331 | short marked_x = 0 , marked_y = 0 ; |
310 | struct cb_command result = { 0, {0,0,0,0,0}, 0 }; | 332 | struct cb_command result = { 0, {0,0,0,0,0}, 0 }; |
311 | 333 | ||
312 | cb_switch ( x , y ); | 334 | cb_switch ( x , y ); |
313 | /* main loop */ | 335 | /* main loop */ |
314 | while ( true ) { | 336 | while ( true ) { |
315 | button = rb->button_get(true); | 337 | button = rb->button_get(true); |
316 | switch (button) { | 338 | switch (button) { |
317 | case CB_QUIT: | 339 | case CB_QUIT: |
318 | result.type = COMMAND_QUIT; | 340 | result.type = COMMAND_QUIT; |
319 | return result; | 341 | return result; |
320 | /* case CB_RESTART: | 342 | #if 0 |
321 | result.type = COMMAND_RESTART; | 343 | case CB_RESTART: |
322 | return result;*/ | 344 | result.type = COMMAND_RESTART; |
323 | case CB_LEVEL: | 345 | return result; |
324 | result.type = COMMAND_LEVEL; | 346 | #endif |
325 | return result; | 347 | case CB_LEVEL: |
326 | case CB_PLAY: | 348 | result.type = COMMAND_LEVEL; |
349 | return result; | ||
350 | case CB_PLAY: | ||
327 | #ifdef CB_PLAY_PRE | 351 | #ifdef CB_PLAY_PRE |
328 | if (lastbutton != CB_PLAY_PRE) | 352 | if (lastbutton != CB_PLAY_PRE) |
329 | break; | 353 | break; |
330 | #endif | 354 | #endif |
331 | result.type = COMMAND_PLAY; | 355 | result.type = COMMAND_PLAY; |
332 | return result; | 356 | return result; |
333 | case CB_UP: | 357 | case CB_UP: |
334 | if ( !from_marked ) cb_switch ( x , y ); | 358 | if ( !from_marked ) cb_switch ( x , y ); |
335 | y++; | 359 | y++; |
336 | if ( y == 8 ) { | 360 | if ( y == 8 ) { |
337 | y = 0; | 361 | y = 0; |
338 | x--; | 362 | x--; |
339 | if ( x < 0 ) x = 7; | 363 | if ( x < 0 ) x = 7; |
340 | } | 364 | } |
341 | if ( marked && ( marked_x == x ) && ( marked_y == y ) ) { | 365 | if ( marked && ( marked_x == x ) && ( marked_y == y ) ) { |
342 | from_marked = true ; | 366 | from_marked = true ; |
343 | } else { | 367 | } else { |
344 | from_marked = false ; | 368 | from_marked = false ; |
345 | cb_switch ( x , y ); | 369 | cb_switch ( x , y ); |
346 | } | 370 | } |
347 | break; | 371 | break; |
348 | case CB_DOWN: | 372 | case CB_DOWN: |
349 | if ( !from_marked ) cb_switch ( x , y ); | 373 | if ( !from_marked ) cb_switch ( x , y ); |
350 | y--; | 374 | y--; |
351 | if ( y < 0 ) { | 375 | if ( y < 0 ) { |
352 | y = 7; | 376 | y = 7; |
353 | x++; | 377 | x++; |
354 | if ( x == 8 ) x = 0; | 378 | if ( x == 8 ) x = 0; |
355 | } | 379 | } |
356 | if ( marked && ( marked_x == x ) && ( marked_y == y ) ) { | 380 | if ( marked && ( marked_x == x ) && ( marked_y == y ) ) { |
357 | from_marked = true ; | 381 | from_marked = true ; |
358 | } else { | 382 | } else { |
359 | from_marked = false ; | 383 | from_marked = false ; |
360 | cb_switch ( x , y ); | 384 | cb_switch ( x , y ); |
361 | } | 385 | } |
362 | break; | 386 | break; |
363 | case CB_LEFT: | 387 | case CB_LEFT: |
364 | if ( !from_marked ) cb_switch ( x , y ); | 388 | if ( !from_marked ) cb_switch ( x , y ); |
365 | x--; | 389 | x--; |
366 | if ( x < 0 ) { | 390 | if ( x < 0 ) { |
367 | x = 7; | 391 | x = 7; |
368 | y++; | 392 | y++; |
369 | if ( y == 8 ) y = 0; | 393 | if ( y == 8 ) y = 0; |
370 | } | 394 | } |
371 | if ( marked && ( marked_x == x ) && ( marked_y == y ) ) { | 395 | if ( marked && ( marked_x == x ) && ( marked_y == y ) ) { |
372 | from_marked = true ; | 396 | from_marked = true ; |
373 | } else { | 397 | } else { |
374 | from_marked = false ; | 398 | from_marked = false ; |
375 | cb_switch ( x , y ); | 399 | cb_switch ( x , y ); |
376 | } | 400 | } |
377 | break; | 401 | break; |
378 | case CB_RIGHT: | 402 | case CB_RIGHT: |
379 | if ( !from_marked ) cb_switch ( x , y ); | 403 | if ( !from_marked ) cb_switch ( x , y ); |
380 | x++; | 404 | x++; |
381 | if ( x == 8 ) { | 405 | if ( x == 8 ) { |
382 | x = 0; | 406 | x = 0; |
383 | y--; | 407 | y--; |
384 | if ( y < 0 ) y = 7; | 408 | if ( y < 0 ) y = 7; |
385 | } | 409 | } |
386 | if ( marked && ( marked_x == x ) && ( marked_y == y ) ) { | 410 | if ( marked && ( marked_x == x ) && ( marked_y == y ) ) { |
387 | from_marked = true ; | 411 | from_marked = true ; |
388 | } else { | 412 | } else { |
389 | from_marked = false ; | 413 | from_marked = false ; |
390 | cb_switch ( x , y ); | 414 | cb_switch ( x , y ); |
391 | } | 415 | } |
392 | break; | 416 | break; |
393 | case CB_SELECT: | 417 | case CB_SELECT: |
394 | #ifdef CB_SELECT_PRE | 418 | #ifdef CB_SELECT_PRE |
395 | if (lastbutton != CB_SELECT_PRE) | 419 | if (lastbutton != CB_SELECT_PRE) |
396 | break; | 420 | break; |
397 | #endif | 421 | #endif |
398 | if ( !marked ) { | 422 | if ( !marked ) { |
399 | xy2cr ( x , y , &c , &r ); | 423 | xy2cr ( x , y , &c , &r ); |
400 | l = locn[r][c]; | 424 | l = locn[r][c]; |
401 | if ( ( color[l]!=computer ) && ( board[l]!=no_piece ) ) { | 425 | if ( ( color[l]!=computer ) && ( board[l]!=no_piece ) ) { |
402 | marked = true; | 426 | marked = true; |
403 | from_marked = true ; | 427 | from_marked = true ; |
404 | marked_x = x; | 428 | marked_x = x; |
405 | marked_y = y; | 429 | marked_y = y; |
406 | } | 430 | } |
407 | } else { | 431 | } else { |
408 | if ( ( marked_x == x ) && ( marked_y == y ) ) { | 432 | if ( ( marked_x == x ) && ( marked_y == y ) ) { |
409 | marked = false; | 433 | marked = false; |
410 | from_marked = false; | 434 | from_marked = false; |
411 | } else { | 435 | } else { |
412 | xy2cr ( marked_x , marked_y , &c , &r ); | 436 | xy2cr ( marked_x , marked_y , &c , &r ); |
413 | result.mv_s[0] = 'a' + c; | 437 | result.mv_s[0] = 'a' + c; |
414 | result.mv_s[1] = '1' + r; | 438 | result.mv_s[1] = '1' + r; |
415 | xy2cr ( x , y , &c , &r ); | 439 | xy2cr ( x , y , &c , &r ); |
416 | result.mv_s[2] = 'a' + c; | 440 | result.mv_s[2] = 'a' + c; |
417 | result.mv_s[3] = '1' + r; | 441 | result.mv_s[3] = '1' + r; |
418 | result.mv_s[4] = '\00'; | 442 | result.mv_s[4] = '\00'; |
419 | result.type = COMMAND_MOVE; | 443 | result.type = COMMAND_MOVE; |
420 | return result; | 444 | return result; |
421 | } | 445 | } |
422 | } | 446 | } |
423 | break; | 447 | break; |
424 | } | 448 | } |
425 | if (button != BUTTON_NONE) | 449 | if (button != BUTTON_NONE) |
426 | lastbutton = button; | 450 | lastbutton = button; |
427 | } | 451 | } |
428 | 452 | ||
429 | } | 453 | } |
430 | 454 | ||
@@ -432,77 +456,87 @@ struct cb_command cb_getcommand (void) { | |||
432 | * plugin entry point. | 456 | * plugin entry point. |
433 | ******************************************************************************/ | 457 | ******************************************************************************/ |
434 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { | 458 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { |
435 | struct cb_command command; | 459 | struct cb_command command; |
436 | /* init status */ | 460 | /* init status */ |
437 | bool exit = false; | 461 | bool exit = false; |
438 | 462 | ||
439 | /* plugin init */ | 463 | /* plugin init */ |
440 | (void)parameter; | 464 | (void)parameter; |
441 | rb = api; | 465 | rb = api; |
442 | /* end of plugin init */ | 466 | /* end of plugin init */ |
443 | 467 | ||
444 | /* load opening book, soon */ | 468 | /* load opening book, soon */ |
445 | 469 | ||
446 | /* init board */ | 470 | /* init board */ |
447 | GNUChess_Initialize(); | 471 | GNUChess_Initialize(); |
448 | 472 | ||
449 | /* draw the board */ | 473 | /* draw the board */ |
450 | /* I don't like configscreens, start game inmediatly */ | 474 | /* I don't like configscreens, start game inmediatly */ |
451 | cb_drawboard(); | 475 | cb_drawboard(); |
452 | 476 | ||
453 | while (!exit) { | 477 | while (!exit) { |
454 | if ( mate ) { | 478 | if ( mate ) { |
455 | rb->splash ( 500 , true , "Checkmate!" ); | 479 | rb->splash ( 500 , true , "Checkmate!" ); |
456 | rb->button_get(true); | 480 | rb->button_get(true); |
457 | GNUChess_Initialize(); | 481 | GNUChess_Initialize(); |
458 | cb_drawboard(); | 482 | cb_drawboard(); |
459 | } | 483 | } |
460 | command = cb_getcommand (); | 484 | command = cb_getcommand (); |
461 | switch (command.type) { | 485 | switch (command.type) { |
462 | case COMMAND_MOVE: | 486 | case COMMAND_MOVE: |
463 | if ( ! VerifyMove ( command.mv_s , 0 , &command.mv ) ) { | 487 | if ( ! VerifyMove ( command.mv_s , 0 , &command.mv ) ) { |
464 | rb->splash ( 50 , true , "Illegal move!" ); | 488 | rb->splash ( 50 , true , "Illegal move!" ); |
465 | cb_drawboard(); | 489 | cb_drawboard(); |
466 | } else { | 490 | } else { |
467 | cb_drawboard(); | 491 | cb_drawboard(); |
468 | rb->splash ( 0 , true , "Thinking..." ); | 492 | rb->splash ( 0 , true , "Thinking..." ); |
469 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | 493 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ |
470 | rb->cpu_boost ( true ); | 494 | rb->cpu_boost ( true ); |
471 | #endif | 495 | #endif |
472 | SelectMove ( computer , 0 ); | 496 | SelectMove ( computer , 0 , cb_wt_callback ); |
473 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | 497 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ |
474 | rb->cpu_boost ( false ); | 498 | rb->cpu_boost ( false ); |
475 | #endif | 499 | #endif |
476 | cb_drawboard(); | 500 | if ( wt_command == COMMAND_QUIT ) { |
477 | } | 501 | exit = true; |
478 | break; | 502 | break; |
479 | /* case COMMAND_RESTART: | 503 | } |
480 | GNUChess_Initialize(); | 504 | cb_drawboard(); |
481 | cb_drawboard(); | 505 | } |
482 | break;*/ | 506 | break; |
483 | case COMMAND_PLAY: | 507 | #if 0 |
484 | opponent = !opponent; computer = !computer; | 508 | case COMMAND_RESTART: |
485 | rb->splash ( 0 , true , "Thinking..." ); | 509 | GNUChess_Initialize(); |
510 | cb_drawboard(); | ||
511 | break; | ||
512 | #endif | ||
513 | case COMMAND_PLAY: | ||
514 | opponent = !opponent; computer = !computer; | ||
515 | rb->splash ( 0 , true , "Thinking..." ); | ||
486 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | 516 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ |
487 | rb->cpu_boost ( true ); | 517 | rb->cpu_boost ( true ); |
488 | #endif | 518 | #endif |
489 | SelectMove ( computer , 0 ); | 519 | SelectMove ( computer , 0 , cb_wt_callback ); |
490 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | 520 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ |
491 | rb->cpu_boost ( false ); | 521 | rb->cpu_boost ( false ); |
492 | #endif | 522 | #endif |
493 | cb_drawboard(); | 523 | if ( wt_command == COMMAND_QUIT ) { |
494 | break; | 524 | exit = true; |
495 | case COMMAND_LEVEL: | 525 | break; |
496 | cb_levelup ( ); | 526 | } |
497 | cb_drawboard(); | 527 | cb_drawboard(); |
498 | break; | 528 | break; |
499 | case COMMAND_QUIT: | 529 | case COMMAND_LEVEL: |
500 | /*cb_saveposition();*/ | 530 | cb_levelup ( ); |
501 | exit = true; | 531 | cb_drawboard(); |
502 | break; | 532 | break; |
503 | } | 533 | case COMMAND_QUIT: |
504 | } | 534 | /*cb_saveposition();*/ |
505 | 535 | exit = true; | |
536 | break; | ||
537 | } | ||
538 | } | ||
539 | |||
506 | rb->lcd_setfont(FONT_UI); | 540 | rb->lcd_setfont(FONT_UI); |
507 | return PLUGIN_OK; | 541 | return PLUGIN_OK; |
508 | } | 542 | } |