summaryrefslogtreecommitdiff
path: root/apps/plugins/reversi/reversi-gui.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/reversi/reversi-gui.c')
-rw-r--r--apps/plugins/reversi/reversi-gui.c38
1 files changed, 35 insertions, 3 deletions
diff --git a/apps/plugins/reversi/reversi-gui.c b/apps/plugins/reversi/reversi-gui.c
index e543563729..5c759a02f1 100644
--- a/apps/plugins/reversi/reversi-gui.c
+++ b/apps/plugins/reversi/reversi-gui.c
@@ -328,11 +328,11 @@ static const cursor_wrap_mode_t cursor_wrap_mode_values[3] = {
328 328
329static struct opt_items strategy_settings[] = { 329static struct opt_items strategy_settings[] = {
330 { "Human", NULL }, 330 { "Human", NULL },
331 { "Silly robot", NULL }, 331 { "Naive robot", NULL },
332 { "Smart robot", NULL }, 332 { "Simple robot", NULL },
333}; 333};
334static const game_strategy_t * const strategy_values[] = { 334static const game_strategy_t * const strategy_values[] = {
335 &strategy_human, &strategy_novice, &strategy_expert }; 335 &strategy_human, &strategy_naive, &strategy_simple };
336 336
337 337
338/* Sets the strategy for the specified player. 'player' is the 338/* Sets the strategy for the specified player. 'player' is the
@@ -555,6 +555,9 @@ enum plugin_status plugin_start(struct plugin_api *api, void *parameter) {
555 /* Avoid compiler warnings */ 555 /* Avoid compiler warnings */
556 (void)parameter; 556 (void)parameter;
557 557
558 game.rb = rb;
559 rb->srand(*rb->current_tick); /* Some AIs use rand() */
560
558 reversi_gui_init(); 561 reversi_gui_init();
559 cursor_wrap_mode = WRAP_FLAT; 562 cursor_wrap_mode = WRAP_FLAT;
560 563
@@ -563,10 +566,39 @@ enum plugin_status plugin_start(struct plugin_api *api, void *parameter) {
563 quit_plugin = false; 566 quit_plugin = false;
564 draw_screen = true; 567 draw_screen = true;
565 while (!exit && !quit_plugin) { 568 while (!exit && !quit_plugin) {
569 const game_strategy_t *cur_strategy = NULL;
566 if (draw_screen) { 570 if (draw_screen) {
567 reversi_gui_display_board(); 571 reversi_gui_display_board();
568 draw_screen = false; 572 draw_screen = false;
569 } 573 }
574 switch(cur_player) {
575 case BLACK:
576 cur_strategy = black_strategy;
577 break;
578 case WHITE:
579 cur_strategy = white_strategy;
580 break;
581 }
582
583 if(cur_strategy->is_robot) {
584 /* TODO: Check move validity */
585 move_t m = cur_strategy->move_func(&game, cur_player);
586 reversi_make_move(&game, MOVE_ROW(m), MOVE_COL(m), cur_player);
587 cur_player = reversi_flipped_color(cur_player);
588 draw_screen = true;
589 /* TODO: Add some delay to prevent it from being too fast ? */
590 /* TODO: Don't duplicate end of game check */
591 if (reversi_game_is_finished(&game)) {
592 reversi_count_occupied_cells(&game, &w_cnt, &b_cnt);
593 rb->snprintf(msg_buf, sizeof(msg_buf),
594 "Game over. %s have won.",
595 (w_cnt>b_cnt?"WHITE":"BLACK"));
596 rb->splash(HZ*2, msg_buf);
597 draw_screen = true; /* Must update screen after splash */
598 }
599 continue;
600 }
601
570 button = rb->button_get(true); 602 button = rb->button_get(true);
571 603
572 switch (button) { 604 switch (button) {