diff options
author | Antoine Cellerier <dionoea@videolan.org> | 2007-07-01 17:51:38 +0000 |
---|---|---|
committer | Antoine Cellerier <dionoea@videolan.org> | 2007-07-01 17:51:38 +0000 |
commit | 9af42897706548a400a8444066b6ee4900c284f4 (patch) | |
tree | 4d8c63a2c267779cb3311e16e3a75843c4a8809a /apps/plugins/reversi/reversi-gui.c | |
parent | e76e138097ce8789821ce5be9ad9271ed46d8561 (diff) |
Implement 2 simple AIs for reversi:
* naive: plays random moves
* simple: plays highest score move (Even though it's named simple i can't beat it :/)
More AIs are yet to come (I'll be using those in hinversi).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13755 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/reversi/reversi-gui.c')
-rw-r--r-- | apps/plugins/reversi/reversi-gui.c | 38 |
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] = { static struct opt_items strategy_settings[] = { { "Human", NULL }, - { "Silly robot", NULL }, - { "Smart robot", NULL }, + { "Naive robot", NULL }, + { "Simple robot", NULL }, }; static const game_strategy_t * const strategy_values[] = { - &strategy_human, &strategy_novice, &strategy_expert }; + &strategy_human, &strategy_naive, &strategy_simple }; /* 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) { /* Avoid compiler warnings */ (void)parameter; + game.rb = rb; + rb->srand(*rb->current_tick); /* Some AIs use rand() */ + reversi_gui_init(); cursor_wrap_mode = WRAP_FLAT; @@ -563,10 +566,39 @@ enum plugin_status plugin_start(struct plugin_api *api, void *parameter) { quit_plugin = false; draw_screen = true; while (!exit && !quit_plugin) { + const game_strategy_t *cur_strategy = NULL; if (draw_screen) { reversi_gui_display_board(); draw_screen = false; } + switch(cur_player) { + case BLACK: + cur_strategy = black_strategy; + break; + case WHITE: + cur_strategy = white_strategy; + break; + } + + if(cur_strategy->is_robot) { + /* TODO: Check move validity */ + move_t m = cur_strategy->move_func(&game, cur_player); + reversi_make_move(&game, MOVE_ROW(m), MOVE_COL(m), cur_player); + cur_player = reversi_flipped_color(cur_player); + draw_screen = true; + /* TODO: Add some delay to prevent it from being too fast ? */ + /* TODO: Don't duplicate end of game check */ + if (reversi_game_is_finished(&game)) { + reversi_count_occupied_cells(&game, &w_cnt, &b_cnt); + rb->snprintf(msg_buf, sizeof(msg_buf), + "Game over. %s have won.", + (w_cnt>b_cnt?"WHITE":"BLACK")); + rb->splash(HZ*2, msg_buf); + draw_screen = true; /* Must update screen after splash */ + } + continue; + } + button = rb->button_get(true); switch (button) { |