--- apps/plugins/superdom.c 2009-03-04 15:15:02.000000000 +0900 +++ apps/plugins/superdom.v2.c 2009-03-04 20:09:48.000000000 +0900 @@ -1813,16 +1813,18 @@ int numthreats = 0; int total_str_diff = 0; int men_needed; + int numterritory = 0; struct threat targets[2]; int numtargets; struct cursor adj; bool full = false; - for(i=1;i<12;i++) { - for(j=1;j<12;j++) { - if((board[i][j].colour == COLOUR_DARK) && - (calc_strength(COLOUR_DARK,i,j) < - calc_strength(COLOUR_LIGHT,i,j))) { - if(board[i][j].ind || board[i][j].farm) { + for(i=1;i<11;i++) { + for(j=1;j<11;j++) { + if(board[i][j].colour == COLOUR_DARK) { + numterritory++; + if((calc_strength(COLOUR_DARK,i,j) < + calc_strength(COLOUR_LIGHT,i,j)) && + (board[i][j].ind || board[i][j].farm)) { if(numthreats < 3) { offensive = false; threats[numthreats].x = i; @@ -1851,30 +1853,28 @@ * owned by the computer. If none are found just place troops in * random places around the map until we run out of money */ k = 0; - while(kyield(); } + rb->yield(); } } if(k == 0) { /* No targets found! Randomly pick squares and if they're owned * by the computer then stick a tank on it. */ rb->srand(*rb->current_tick); - while(compres.cash >= 300) { - i = rb->rand()%11 + 1; - j = rb->rand()%11 + 1; + while(compres.cash >= 300 && compres.tanks < numterritory) { + i = rb->rand()%10 + 1; + j = rb->rand()%10 + 1; if(board[i][j].colour == COLOUR_DARK) { if(compres.cash >= 300) { if(!board[i][j].tank) { @@ -1886,6 +1886,7 @@ } } } + rb->yield(); } compres.bank += compres.cash; compres.cash = 0; @@ -1926,6 +1927,7 @@ } draw_board(); rb->sleep(HZ); + break; } } } @@ -1985,6 +1987,7 @@ draw_board(); rb->sleep(HZ); } + break; } } else { if(compres.cash >= 600) { @@ -2019,6 +2022,7 @@ draw_board(); rb->sleep(HZ); } + break; } } else { if(compres.cash >= 300) { @@ -2071,47 +2075,63 @@ void computer_war(void) { /* Work out where to attack - prioritise the defence of buildings */ int i, j; + bool found_target = true; struct cursor adj; - while(compres.moves) { - for(i=1;i<12;i++) { - for(j=1;j<12;j++) { + while(found_target) { + found_target = false; + for(i=1;i<11;i++) { + for(j=1;j<11;j++) { if((board[i][j].colour == COLOUR_DARK) && (board[i][j].farm || board[i][j].ind)) { - if(find_adj_target(i, j, &adj) && compres.moves) { + if(find_adj_target(i, j, &adj)) { + found_target = true; if(attack_territory(COLOUR_DARK, adj.x, adj.y) >= 0) { compres.moves--; + if(!compres.moves) + return; } } } rb->yield(); } } - if(compres.moves) { - /* Defence stage done, move on to OFFENCE */ - for(i=1;i<12;i++) { - for(j=1;j<12;j++) { - if(board[i][j].colour == COLOUR_LIGHT && compres.moves && - (board[i][j].ind || board[i][j].farm) && - (calc_strength(COLOUR_DARK, i, j) >= - calc_strength(COLOUR_LIGHT, i, j))) { - if(attack_territory(COLOUR_DARK, i, j) >= 0) { - compres.moves--; - } + } + /* Defence stage done, move on to OFFENCE */ + found_target = true; + while(found_target) { + found_target = false; + for(i=1;i<11;i++) { + for(j=1;j<11;j++) { + if(board[i][j].colour == COLOUR_LIGHT && + (board[i][j].ind || board[i][j].farm) && + (calc_strength(COLOUR_DARK, i, j) >= + calc_strength(COLOUR_LIGHT, i, j))) { + found_target = true; + if(attack_territory(COLOUR_DARK, i, j) >= 0) { + compres.moves--; + if(!compres.moves) + return; } - rb->yield(); } + rb->yield(); } - while(compres.moves > 0) { - /* Spend leftover moves wherever attacking randomly */ - rb->srand(*rb->current_tick); - i = (rb->rand()%10)+1; - j = (rb->rand()%10)+1; + } + } + /* Spend leftover moves wherever attacking randomly */ + found_target = true; + while(found_target) { + found_target = false; + for(i=1;i<11;i++) { + for(j=1;j<11;j++) { if(board[i][j].colour == COLOUR_LIGHT && (calc_strength(COLOUR_DARK, i, j) >= calc_strength(COLOUR_LIGHT, i, j))) { + found_target = true; if(attack_territory(COLOUR_DARK, i, j) >= 0) { compres.moves--; + if(!compres.moves) + return; } } rb->yield();