1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (c) 2006 Alexander Levin
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
23 GUI part of reversi. Code is inspired by sudoku code by Dave Chapman
24 which is copyright (c) 2005 Dave Chapman and is released under the
25 GNU General Public License.
31 Use the arrow keys to move cursor, and press TOGGLE to place a stone.
33 At any time during the game, press MENU to bring up the game menu with
42 #include "reversi-game.h"
43 #include "reversi-strategy.h"
44 #include "reversi-gui.h"
46 #include "lib/playback_control.h"
50 /* This is initialized at the start of the plugin and used to determine the
51 * Appropriate game board size/legend spacing if the font is larger than a cell
54 static int font_width
;
55 static int font_height
;
57 /* Where the board begins */
61 #if LCD_HEIGHT > LCD_WIDTH
62 #define MARGIN_W (XOFS*2+1)
63 #define MARGIN_H (YOFS*2+1)
67 #define MARGIN_W (XOFS*2 + 16)
68 #define MARGIN_H (YOFS*2+1)
73 #if ( (LCD_WIDTH - MARGIN_W) / (BOARD_SIZE+MARGIN_C_W)) < \
74 ( (LCD_HEIGHT - MARGIN_H) / (BOARD_SIZE+MARGIN_C_H))
76 #define CELL_PRE ( ( (LCD_WIDTH * LCD_PIXEL_ASPECT_WIDTH / \
77 LCD_PIXEL_ASPECT_HEIGHT) - MARGIN_W) / \
78 (BOARD_SIZE+MARGIN_C_W) )
80 #define CELL_WIDTH (CELL_PRE*LCD_PIXEL_ASPECT_HEIGHT / LCD_PIXEL_ASPECT_WIDTH)
81 #define CELL_HEIGHT (CELL_PRE)
83 #define CELL_PRE ( ( (LCD_HEIGHT * LCD_PIXEL_ASPECT_HEIGHT / \
84 LCD_PIXEL_ASPECT_WIDTH) - MARGIN_H) / \
85 (BOARD_SIZE+MARGIN_C_H) )
87 #define CELL_WIDTH (CELL_PRE)
88 #define CELL_HEIGHT (CELL_PRE*LCD_PIXEL_ASPECT_WIDTH / LCD_PIXEL_ASPECT_HEIGHT)
91 /* Total width and height of the board without enclosing box */
92 #define BOARD_WIDTH (CELL_WIDTH*BOARD_SIZE)
93 #define BOARD_HEIGHT (CELL_HEIGHT*BOARD_SIZE)
95 /* Thickness of the white cells' lines */
96 #if (CELL_WIDTH >= 10) && (CELL_HEIGHT >= 10)
97 #define CELL_LINE_THICKNESS CELL_WIDTH/5
99 #define CELL_LINE_THICKNESS 1
102 /* Margins within a cell */
103 #define STONE_MARGIN 2
105 #define CURSOR_MARGIN 1
107 /* Upper left corner of a cell */
108 #define CELL_X(c) (XOFS + (c)*CELL_WIDTH)
109 #define CELL_Y(r) (YOFS + (r)*CELL_HEIGHT)
111 /* Used for touchscreen to convert an X/Y location to a cell location */
112 #define CELL_C(x) (((x)-XOFS)/CELL_WIDTH)
113 #define CELL_R(y) (((y)-YOFS)/CELL_HEIGHT)
115 #if LCD_HEIGHT > LCD_WIDTH
116 #define LEGEND_X(lc) (CELL_X(lc))
117 #define LEGEND_Y(lr) ((CELL_HEIGHT > font_height) ? \
118 CELL_Y(BOARD_SIZE+lr) + YOFS + 1 : \
119 BOARD_HEIGHT + 2*YOFS + font_height*(lr-BOARD_SIZE))
121 #define LEGEND_X(lc) (CELL_X(BOARD_SIZE+lc) + XOFS + 1)
122 #define LEGEND_Y(lr) (CELL_HEIGHT > font_height ? \
123 CELL_Y(lr) : font_height*(lr)+YOFS)
128 static reversi_board_t game
;
130 /* --- Setting values --- */
132 /* Playing strategies used by white and black players */
133 const game_strategy_t
*white_strategy
;
134 const game_strategy_t
*black_strategy
;
136 /* Cursor position */
137 static int cur_row
, cur_col
;
139 /* Color for the next move (BLACK/WHITE) */
140 static int cur_player
;
142 /* Active cursor wrapping mode */
143 static cursor_wrap_mode_t cursor_wrap_mode
;
145 static bool quit_plugin
;
146 static bool game_finished
;
148 #ifdef HAVE_TOUCHSCREEN
149 #include "lib/pluginlib_touchscreen.h"
150 /* This uses the touchscreen library functions/structures. */
152 /* This defines the number of buttons used; only used in this C file. */
153 #define TOUCHBUTTON_COUNT 3
155 /* Define the button locations, widths and heights */
157 #if LCD_HEIGHT < LCD_WIDTH
158 /* Define Menu button x, y, width, height */
159 #define B_MENU_X LEGEND_X(0)
160 #define B_MENU_Y (LCD_HEIGHT-LCD_HEIGHT/2)
161 #define B_MENU_W (LCD_WIDTH-LEGEND_X(0))
162 #define B_MENU_H (LCD_HEIGHT/4)
163 /* Define Quit Button x, y, width, height */
164 #define B_QUIT_X LEGEND_X(0)
165 #define B_QUIT_Y (LCD_HEIGHT-LCD_HEIGHT/4)
166 #define B_QUIT_W (LCD_WIDTH-LEGEND_X(0))
167 #define B_QUIT_H (LCD_HEIGHT/4)
169 /* Define Menu button x, y, width, height */
170 #define B_MENU_X (LCD_WIDTH/2)
171 #define B_MENU_Y (CELL_HEIGHT*BOARD_SIZE+YOFS*2)
172 #define B_MENU_W (LCD_WIDTH/4)
173 #define B_MENU_H (2*CELL_HEIGHT)
174 /* Define Quit Button x, y, width, height */
175 #define B_QUIT_X (LCD_WIDTH-LCD_WIDTH/4)
176 #define B_QUIT_Y (CELL_HEIGHT*BOARD_SIZE+YOFS*2)
177 #define B_QUIT_W (LCD_WIDTH/4)
178 #define B_QUIT_H (2*CELL_HEIGHT)
181 /* This is the button initialization/definition. The first element is the
182 * Viewport. This is defined in lcd.h, but the elements are:
183 * int x - X location of button/viewport
184 * int y - Y location of button/viewport
185 * int width - Width of button/viewport
186 * int height - Height of button/viewport
187 * int font - Font to be used on button/viewport
188 * int drawmode- Modes defined in lcd.h
189 * unsigned fg_pattern - foreground color
190 * unsigned bg_pattern - backbround color
191 * unsigned lss_pattern - Selector colors (currently unused)
192 * unsigned lse_pattern - |
193 * unsigned lst_pattern - \/
195 * The rest of the touch button elements are:
196 * bool repeat - requires the area be held for the action
197 * int action - action this button will return
198 * bool invisible - Is this an invisible button?
199 * char *title - Specify a title
200 * fb_data *pixmap- Currently unused, but will allow for a graphic
202 struct touchbutton reversi_buttons
[TOUCHBUTTON_COUNT
] =
204 { {B_MENU_X
, B_MENU_Y
, B_MENU_W
, B_MENU_H
, 0, FONT_UI
,
205 STYLE_DEFAULT
, 0, 0xFFFF, 0, 0, 0},
206 false, REVERSI_BUTTON_MENU
, false, "Menu", NULL
},
208 { {B_QUIT_X
, B_QUIT_Y
, B_QUIT_W
, B_QUIT_H
, 0, FONT_UI
,
209 STYLE_DEFAULT
, 0, 0xFFFF, 0, 0, 0},
210 false, REVERSI_BUTTON_QUIT
, false, "Quit", NULL
},
212 { {0, 0, XOFS
+BOARD_WIDTH
, YOFS
+BOARD_HEIGHT
, 0, 0,
213 STYLE_DEFAULT
, 0, 0xFFFF, 0, 0, 0},
214 false, REVERSI_BUTTON_MAKE_MOVE
, true, NULL
, NULL
}
218 /* Initialises the state of the game (starts a new game) */
219 static void reversi_gui_init(void) {
220 reversi_init_game(&game
);
221 game_finished
= false;
224 /* Place the cursor so that WHITE can make a move */
230 /* Draws the cursor in the specified cell. Cursor is drawn in the complement
231 * mode, i.e. drawing it twice will result in no changes on the screen.
233 static void reversi_gui_display_cursor(int row
, int col
) {
235 old_mode
= rb
->lcd_get_drawmode();
239 rb
->lcd_set_drawmode(DRMODE_COMPLEMENT
);
240 rb
->lcd_drawline(x
+CURSOR_MARGIN
, y
+CURSOR_MARGIN
,
241 x
+CELL_WIDTH
-CURSOR_MARGIN
, y
+CELL_HEIGHT
-CURSOR_MARGIN
);
242 rb
->lcd_drawline(x
+CURSOR_MARGIN
, y
+CELL_HEIGHT
-CURSOR_MARGIN
,
243 x
+CELL_WIDTH
-CURSOR_MARGIN
, y
+CURSOR_MARGIN
);
245 /* Draw the shadows */
246 rb
->lcd_hline(x
, x
+CELL_WIDTH
-1, YOFS
-3);
247 rb
->lcd_hline(x
, x
+CELL_WIDTH
-1, YOFS
+BOARD_HEIGHT
+3);
248 rb
->lcd_vline(XOFS
-3, y
, y
+CELL_HEIGHT
-1);
249 rb
->lcd_vline(XOFS
+BOARD_WIDTH
+3, y
, y
+CELL_HEIGHT
-1);
251 rb
->lcd_set_drawmode(old_mode
);
256 /* Draws the cell of the specified color (WHITE/BLACK) assuming that
257 * the upper left corner of the cell is at (x, y) */
258 static void reversi_gui_draw_cell(int x
, int y
, int color
) {
260 if (color
== WHITE
) {
261 for (i
= 0; i
< CELL_LINE_THICKNESS
; i
++) {
265 CELL_WIDTH
+1-2*(STONE_MARGIN
+i
),
266 CELL_HEIGHT
+1-2*(STONE_MARGIN
+i
)
269 } else if (color
== BLACK
) {
270 rb
->lcd_fillrect(x
+STONE_MARGIN
, y
+STONE_MARGIN
,
271 CELL_WIDTH
-STONE_MARGIN
-1, CELL_HEIGHT
-1-STONE_MARGIN
);
273 /* Cell is free -> nothing to do */
278 /* Draws the complete screen */
279 static void reversi_gui_display_board(void) {
280 int x
, y
, r
, c
, x_width
, x_height
;
281 /* This viewport is used to draw a scrolling score */
282 struct viewport tempvp
;
285 /* Clear the display buffer */
286 rb
->lcd_clear_display();
287 rb
->lcd_set_drawmode(DRMODE_FG
);
289 /* Thicker board box */
290 rb
->lcd_drawrect(XOFS
-1, YOFS
-1, BOARD_WIDTH
+3, BOARD_HEIGHT
+3);
292 /* Draw the gridlines */
293 for (r
=0, x
=XOFS
, y
=YOFS
; r
<=BOARD_SIZE
;
294 r
++, x
+=CELL_WIDTH
, y
+=CELL_HEIGHT
) {
295 rb
->lcd_hline(XOFS
, XOFS
+BOARD_WIDTH
, y
);
296 rb
->lcd_vline(x
, YOFS
, YOFS
+BOARD_HEIGHT
);
299 /* Draw the stones. This is not the most efficient way but more readable */
300 for (r
=0; r
<BOARD_SIZE
; r
++) {
302 for (c
=0; c
<BOARD_SIZE
; c
++) {
304 reversi_gui_draw_cell(x
, y
, game
.board
[r
][c
]);
308 /* Draw the cursor */
309 reversi_gui_display_cursor(cur_row
, cur_col
);
311 /* Draw the current score */
312 reversi_count_occupied_cells(&game
, &r
, &c
);
313 rb
->lcd_getstringsize("x", &x_width
, &x_height
);
317 reversi_gui_draw_cell(x
, y
+(LEGEND_Y(1)-LEGEND_Y(0))/2-CELL_WIDTH
/2, BLACK
);
318 rb
->snprintf(buf
, sizeof(buf
), "%01d", c
);
320 tempvp
.x
=x
+CELL_WIDTH
+2;
322 tempvp
.width
=LCD_WIDTH
-tempvp
.x
;
323 tempvp
.height
=LEGEND_Y(1);
326 tempvp
.drawmode
=STYLE_DEFAULT
;
329 tempvp
.bg_pattern
=0xFFFF;
330 #ifdef HAVE_LCD_COLOR
331 tempvp
.lss_pattern
=0;
332 tempvp
.lse_pattern
=0;
333 tempvp
.lst_pattern
=0;
337 rb
->screens
[SCREEN_MAIN
]->set_viewport(&tempvp
);
338 rb
->lcd_puts_scroll(0, 0, buf
);
339 rb
->screens
[SCREEN_MAIN
]->set_viewport(NULL
);
343 reversi_gui_draw_cell(x
, y
+(LEGEND_Y(1)-LEGEND_Y(0))/2-CELL_WIDTH
/2, WHITE
);
344 rb
->snprintf(buf
, sizeof(buf
), "%01d", r
);
347 rb
->screens
[SCREEN_MAIN
]->set_viewport(&tempvp
);
348 rb
->lcd_puts_scroll(0, 0, buf
);
349 rb
->screens
[SCREEN_MAIN
]->set_viewport(NULL
);
351 /* Draw the box around the current player */
352 r
= (cur_player
== BLACK
? 0 : 1);
353 y
= LEGEND_Y(r
)+(LEGEND_Y(1)-LEGEND_Y(0))/2-CELL_WIDTH
/2;
354 rb
->lcd_drawrect(x
, y
, CELL_WIDTH
+1, CELL_HEIGHT
+1);
356 #if defined(HAVE_TOUCHSCREEN)
357 touchbutton_draw(reversi_buttons
, TOUCHBUTTON_COUNT
);
360 /* Update the screen */
369 /* Menu entries and the corresponding values for cursor wrap mode */
370 #define MENU_TEXT_WRAP_MODE "Cursor wrap mode"
371 static const struct opt_items cursor_wrap_mode_settings
[] = {
372 { "Flat board", -1 },
376 static const cursor_wrap_mode_t cursor_wrap_mode_values
[3] = {
377 WRAP_FLAT
, WRAP_SPHERE
, WRAP_TORUS
};
380 /* Menu entries and the corresponding values for available strategies */
381 #define MENU_TEXT_STRAT_WHITE "Strategy for white"
382 #define MENU_TEXT_STRAT_BLACK "Strategy for black"
384 static struct opt_items strategy_settings
[] = {
386 { "Naive robot", -1 },
387 { "Simple robot", -1 },
388 //{ "AB robot", -1 },
390 static const game_strategy_t
* const strategy_values
[] = {
391 &strategy_human
, &strategy_naive
, &strategy_simple
, /*&strategy_ab*/ };
394 /* Sets the strategy for the specified player. 'player' is the
395 pointer to the player to set the strategy for (actually,
396 either white_strategy or black_strategy). propmpt is the
397 text to show as the prompt in the menu */
398 static bool reversi_gui_choose_strategy(
399 const game_strategy_t
**player
, const char *prompt
) {
401 int num_items
= sizeof(strategy_settings
)/sizeof(strategy_settings
[0]);
404 for (i
= 0; i
< num_items
; i
++) {
405 if ((*player
) == strategy_values
[i
]) {
412 rb
->set_option(prompt
, &index
, INT
, strategy_settings
, num_items
, NULL
);
414 (*player
) = strategy_values
[index
];
416 if((*player
)->init_func
)
417 (*player
)->init_func(&game
);
423 /* Returns true iff USB ws connected while in the menu */
424 static bool reversi_gui_menu(void) {
425 int index
, num_items
, i
;
428 MENUITEM_STRINGLIST(menu
, "Reversi Menu", NULL
,
429 "Start new game", "Pass the move",
430 MENU_TEXT_STRAT_BLACK
, MENU_TEXT_STRAT_WHITE
,
431 MENU_TEXT_WRAP_MODE
, "Playback Control", "Quit");
433 #ifdef HAVE_TOUCHSCREEN
434 /* Entering Menu, set the touchscreen to the global setting */
435 rb
->touchscreen_set_mode(rb
->global_settings
->touch_mode
);
438 result
= rb
->do_menu(&menu
, NULL
, NULL
, false);
441 case 0: /* Start a new game */
445 case 1: /* Pass the move to the partner */
446 cur_player
= reversi_flipped_color(cur_player
);
449 case 2: /* Strategy for black */
450 reversi_gui_choose_strategy(&black_strategy
, MENU_TEXT_STRAT_BLACK
);
453 case 3: /* Strategy for white */
454 reversi_gui_choose_strategy(&white_strategy
, MENU_TEXT_STRAT_WHITE
);
457 case 4: /* Cursor wrap mode */
458 num_items
= sizeof(cursor_wrap_mode_values
) /
459 sizeof(cursor_wrap_mode_values
[0]);
461 for (i
= 0; i
< num_items
; i
++) {
462 if (cursor_wrap_mode
== cursor_wrap_mode_values
[i
]) {
467 rb
->set_option(MENU_TEXT_WRAP_MODE
, &index
, INT
,
468 cursor_wrap_mode_settings
, 3, NULL
);
469 cursor_wrap_mode
= cursor_wrap_mode_values
[index
];
473 playback_control(NULL
);
481 #ifdef HAVE_TOUCHSCREEN
482 /* Leaving the menu, set back to pointer mode */
483 rb
->touchscreen_set_mode(TOUCHSCREEN_POINT
);
486 return (result
== MENU_ATTACHED_USB
);
490 /* Calculates the new cursor position if the user wants to move it
491 * vertically as specified by delta. Current wrap mode is respected.
492 * The cursor is not actually moved.
494 * Returns true iff the cursor would be really moved. In any case, the
495 * new cursor position is stored in (new_row, new_col).
498 reversi_gui_cursor_pos_vmove(int row_delta
, int *new_row
, int *new_col
) {
499 *new_row
= cur_row
+ row_delta
;
503 switch (cursor_wrap_mode
) {
508 *new_row
= BOARD_SIZE
- 1;
511 *new_row
= BOARD_SIZE
- 1;
514 *new_col
= BOARD_SIZE
- 1;
518 } else if (*new_row
>= BOARD_SIZE
) {
519 switch (cursor_wrap_mode
) {
529 if (*new_col
>= BOARD_SIZE
) {
536 return (cur_row
!= (*new_row
)) || (cur_col
!= (*new_col
));
540 /* Calculates the new cursor position if the user wants to move it
541 * horisontally as specified by delta. Current wrap mode is respected.
542 * The cursor is not actually moved.
544 * Returns true iff the cursor would be really moved. In any case, the
545 * new cursor position is stored in (new_row, new_col).
548 reversi_gui_cursor_pos_hmove(int col_delta
, int *new_row
, int *new_col
) {
550 *new_col
= cur_col
+ col_delta
;
553 switch (cursor_wrap_mode
) {
558 *new_col
= BOARD_SIZE
- 1;
561 *new_col
= BOARD_SIZE
- 1;
564 *new_row
= BOARD_SIZE
- 1;
568 } else if (*new_col
>= BOARD_SIZE
) {
569 switch (cursor_wrap_mode
) {
579 if (*new_row
>= BOARD_SIZE
) {
586 return (cur_row
!= (*new_row
)) || (cur_col
!= (*new_col
));
590 /* Actually moves the cursor to the new position and updates the screen */
591 static void reversi_gui_move_cursor(int new_row
, int new_col
) {
592 int old_row
, old_col
;
600 /* Only update the changed cells since there are no global changes */
601 reversi_gui_display_cursor(old_row
, old_col
);
602 reversi_gui_display_cursor(new_row
, new_col
);
606 /* plugin entry point */
607 enum plugin_status
plugin_start(const void *parameter
) {
608 bool exit
, draw_screen
;
610 #ifdef HAVE_TOUCHSCREEN
611 int button_x
, button_y
;
613 int lastbutton
= BUTTON_NONE
;
617 /* Initialize Font Width and height */
618 rb
->lcd_getstringsize("0", &font_width
, &font_height
);
620 #ifdef HAVE_TOUCHSCREEN
621 rb
->touchscreen_set_mode(TOUCHSCREEN_POINT
);
625 rb
->lcd_set_backdrop(NULL
);
626 rb
->lcd_set_foreground(LCD_BLACK
);
627 rb
->lcd_set_background(LCD_WHITE
);
630 /* Avoid compiler warnings */
633 rb
->srand(*rb
->current_tick
); /* Some AIs use rand() */
634 white_strategy
= &strategy_human
;
635 black_strategy
= &strategy_human
;
638 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || \
639 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
640 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
641 cursor_wrap_mode
= WRAP_TORUS
;
643 cursor_wrap_mode
= WRAP_FLAT
;
645 /* The main game loop */
649 while (!exit
&& !quit_plugin
) {
650 const game_strategy_t
*cur_strategy
= NULL
;
652 reversi_gui_display_board();
657 cur_strategy
= black_strategy
;
660 cur_strategy
= white_strategy
;
664 if(cur_strategy
->is_robot
&& !game_finished
) {
665 move_t m
= cur_strategy
->move_func(&game
, cur_player
);
666 reversi_make_move(&game
, MOVE_ROW(m
), MOVE_COL(m
), cur_player
);
667 cur_player
= reversi_flipped_color(cur_player
);
669 /* TODO: Add some delay to prevent it from being too fast ? */
670 /* TODO: Don't duplicate end of game check */
671 if (reversi_game_is_finished(&game
, cur_player
)) {
672 reversi_count_occupied_cells(&game
, &w_cnt
, &b_cnt
);
673 rb
->splashf(HZ
*2, "Game over. %s won.",
674 (w_cnt
>b_cnt
?"WHITE":"BLACK"));
675 draw_screen
= true; /* Must update screen after splash */
676 game_finished
= true;
681 /***********************************************************************
682 * Button handling code happens below here
683 **********************************************************************/
684 button
= rb
->button_get(true);
686 /* The touchscreen buttons can act as true buttons so OR them in */
687 #ifdef HAVE_TOUCHSCREEN
688 button
|= touchbutton_get(reversi_buttons
, button
, TOUCHBUTTON_COUNT
);
691 /* All of these button presses wait for the release event */
692 if(button
&BUTTON_REL
) {
693 #ifdef REVERSI_BUTTON_QUIT
694 if(button
&REVERSI_BUTTON_QUIT
) {
699 #ifdef HAVE_TOUCHSCREEN
700 if(button
&BUTTON_TOUCHSCREEN
) {
701 button_x
= rb
->button_get_data();
702 button_y
= button_x
& 0xffff;
705 /* Check if the click was in the gameboard, if so move cursor.
706 * This has to happen before MAKE_MOVE is processed.
708 if( (CELL_R(button_y
)<BOARD_SIZE
) &&
709 (CELL_C(button_x
)<BOARD_SIZE
) )
711 reversi_gui_move_cursor(CELL_R(button_y
), CELL_C(button_x
));
716 if( (button
&REVERSI_BUTTON_MENU
)
717 #if defined(REVERSI_BUTTON_MENU_LONGPRESS)
718 && (lastbutton
&BUTTON_REPEAT
)
721 if (reversi_gui_menu()) {
722 return PLUGIN_USB_CONNECTED
;
727 if(button
&REVERSI_BUTTON_MAKE_MOVE
728 #if defined(REVERSI_BUTTON_MAKE_MOVE_SHORTPRESS)
729 && !(lastbutton
&BUTTON_REPEAT
)
732 /* If you touch the game board instead of hitting menu after it
733 * has completed the game will exit out.
737 if (reversi_make_move(&game
, cur_row
, cur_col
, cur_player
) > 0) {
738 /* Move was made. Global changes on the board are possible */
739 draw_screen
= true; /* Redraw the screen next time */
740 cur_player
= reversi_flipped_color(cur_player
);
741 if (reversi_game_is_finished(&game
, cur_player
)) {
742 reversi_count_occupied_cells(&game
, &w_cnt
, &b_cnt
);
743 rb
->splashf(HZ
*2, "Game over. %s won.",
744 (w_cnt
>b_cnt
?"WHITE":"BLACK"));
745 draw_screen
= true; /* Must update screen after splash */
746 game_finished
= true;
749 /* An attempt to make an invalid move */
750 rb
->splash(HZ
/2, "Illegal move!");
752 /* Ignore any button presses during the splash */
753 rb
->button_clear_queue();
758 /* These button presses will run on a release or a repeat event */
759 if(button
&BUTTON_REL
|| button
&BUTTON_REPEAT
) {
760 /* Move cursor left */
761 if(button
&REVERSI_BUTTON_LEFT
) {
762 if (reversi_gui_cursor_pos_hmove(-1, &row
, &col
)) {
763 reversi_gui_move_cursor(row
, col
);
766 /* Move cursor right */
767 if(button
&REVERSI_BUTTON_RIGHT
) {
768 if (reversi_gui_cursor_pos_hmove(1, &row
, &col
)) {
769 reversi_gui_move_cursor(row
, col
);
773 if(button
&REVERSI_BUTTON_UP
) {
774 if (reversi_gui_cursor_pos_vmove(-1, &row
, &col
)) {
775 reversi_gui_move_cursor(row
, col
);
778 /* Move cursor down */
779 if(button
&REVERSI_BUTTON_DOWN
) {
780 if (reversi_gui_cursor_pos_vmove(1, &row
, &col
)) {
781 reversi_gui_move_cursor(row
, col
);
786 if (rb
->default_event_handler(button
) == SYS_USB_CONNECTED
) {
787 /* Quit if USB has been connected */
788 return PLUGIN_USB_CONNECTED
;
791 if (button
!= BUTTON_NONE
) {