diff options
author | Franklin Wei <frankhwei536@gmail.com> | 2014-08-30 10:21:25 -0400 |
---|---|---|
committer | Michael Giacomelli <giac2000@hotmail.com> | 2014-09-14 04:16:48 +0200 |
commit | ad79a90e39b202f1fe9bdc9105a21ebf7bebb7b5 (patch) | |
tree | c08854fcbf9a073542a58ce52528b705bb4fcb81 /apps/plugins | |
parent | bc00d38987a99eda1e38f2db62ebafb94cb9d6a5 (diff) |
[WIP] Superdom: AI can now use nukes
Change-Id: Iff5093b0edb4c065096d41c36d33bb2126063cf6
Reviewed-on: http://gerrit.rockbox.org/942
Reviewed-by: Michael Giacomelli <giac2000@hotmail.com>
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/superdom.c | 79 |
1 files changed, 76 insertions, 3 deletions
diff --git a/apps/plugins/superdom.c b/apps/plugins/superdom.c index 3cbc5f285d..312c48cdeb 100644 --- a/apps/plugins/superdom.c +++ b/apps/plugins/superdom.c @@ -19,9 +19,7 @@ * ****************************************************************************/ /* TODO list: - - don't hardcode board size - improve AI (move, use nukes, etc.) - - allow for configurable AI */ @@ -1294,7 +1292,11 @@ static int launch_nuke(int colour, int nukex, int nukey, int targetx, int target board[targetx][targety].nuke = false; board[targetx][targety].farm = false; /* TODO: Fallout carried by wind */ - + draw_board(); + if(human) + rb->sleep(HZ*2); + else + rb->sleep(HZ); return RET_VAL_OK; } @@ -2098,7 +2100,78 @@ static int find_adj_target(int x, int y, struct cursor* adj) static void computer_movement(void) { + /* use nukes */ + if(superdom_settings.compdiff>=3) + { + struct cursor nukes[10]; /* 10 for now, change as needed */ + int nukes_back=0; + rb->splashf(HZ, "computer has %d nukes", compres.nukes); + if(compres.nukes>0) + { + for(int i=1;i<=BOARD_SIZE && nukes_back<compres.nukes && nukes_back<10;i++) + { + for(int j=1;j<BOARD_SIZE && nukes_back<compres.nukes && nukes_back<10 ;j++) + { + if(board[i][j].nuke) + { + nukes[nukes_back].x=i; + nukes[nukes_back].y=j; + nukes_back++; + } + rb->yield(); + } + } + bool found_target=true; + struct cursor adj; + int next_nuke=0; + /* first, use nukes for defence */ + while(found_target && next_nuke<nukes_back) + { + found_target = false; + for(int i=1;i<=BOARD_SIZE && nukes_back<compres.nukes && nukes_back<10;i++) + { + for(int j=1;j<=BOARD_SIZE && nukes_back<compres.nukes && nukes_back<10;j++) + { + if((board[i][j].colour == COLOUR_DARK) && + (board[i][j].farm || board[i][j].ind || board[i][j].nuke) && + find_adj_target(i, j, &adj)) + { + found_target = true; + rb->splashf(2*HZ, "Launching nuke for defence, from (%d, %d) to (%d, %d)", nukes[next_nuke].x, nukes[next_nuke].y, adj.x, adj.y); + launch_nuke(COLOUR_DARK, nukes[next_nuke].x, nukes[next_nuke].y, adj.x, adj.y); + next_nuke++; + } + rb->yield(); + } + } + } + /* if we still have any left over, use those for offence */ + found_target = true; + while(found_target && next_nuke<nukes_back) + { + found_target = false; + for(int i=1;i<=BOARD_SIZE;i++) + { + for(int j=1;j<=BOARD_SIZE;j++) + { + if(board[i][j].colour == COLOUR_LIGHT && + (board[i][j].ind || board[i][j].farm || board[i][j].nuke) && + (calc_strength(COLOUR_DARK, i, j) >= calc_strength(COLOUR_LIGHT, i, j))) + { + found_target = true; + rb->splashf(2*HZ, "Launching nuke for offence, nuke index %d", next_nuke); + launch_nuke(COLOUR_DARK, nukes[next_nuke].x, nukes[next_nuke].y, i, j); + next_nuke++; + } + rb->yield(); + } + } + } + + } + } + /* TODO: move other units */ } static void computer_war(void) |