Superdom: some AI improvements and other minor changes

Change-Id: Ia2756a7263ec09b78714273af0f604fc9cdb50eb
Reviewed-on: http://gerrit.rockbox.org/944
Reviewed-by: Michael Giacomelli <giac2000@hotmail.com>
This commit is contained in:
Franklin Wei 2014-08-30 20:59:20 -04:00 committed by Michael Giacomelli
parent 333a82c8eb
commit a65f6ceaed

View file

@ -19,7 +19,9 @@
* *
****************************************************************************/ ****************************************************************************/
/* TODO list: /* TODO list:
- improve AI (move, use nukes, etc.) - improve AI
- buy/use nukes - DONE
- build farms/factories
*/ */
@ -72,6 +74,11 @@ char buf[255];
#define COMPUTER_SURRENDER_THRESHOLD 15 #define COMPUTER_SURRENDER_THRESHOLD 15
#define COMPUTER_HARD_SURRENDER_THRESHOLD 25 #define COMPUTER_HARD_SURRENDER_THRESHOLD 25
/* AI settings */
#define AI_INVESTING_LEVEL 2
#define AI_BUILD_NUKES_LEVEL 3
#define AI_BUILD_INDS_FARMS_LEVEL 2
/* board size */ /* board size */
#define BOARD_SIZE 10 #define BOARD_SIZE 10
#define NUM_SPACES (BOARD_SIZE*BOARD_SIZE) #define NUM_SPACES (BOARD_SIZE*BOARD_SIZE)
@ -166,13 +173,14 @@ static struct settings {
easy: easy:
- no movement - no movement
- no investing - no investing
- will build factories if it has none
medium: medium:
- movement - movement
- investing - investing
- can build factories/farms - can build factories/farms if it has money
hard: hard:
- nuclear war - can buy/use nukes
- harder to surrender - will hold out longer (surrender threshold 25)
*/ */
int compdiff; int compdiff;
bool spoil_enabled; bool spoil_enabled;
@ -569,13 +577,14 @@ static int settings_menu(void)
case 6: case 6:
{ {
static const struct opt_items difficulty_options[3]={ static const struct opt_items difficulty_options[3]={
{"Easy", 1}, {"Easy", -1},
{"Intermediate", 2}, {"Intermediate", -1},
{"Hard", 3} {"Hard", -1}
}; };
rb->set_option("Computer difficulty", &superdom_settings.compdiff, static int sel=1;
rb->set_option("Computer difficulty", &sel,
INT, difficulty_options, 3, NULL); INT, difficulty_options, 3, NULL);
superdom_settings.compdiff++; superdom_settings.compdiff=sel+1;
break; break;
} }
case 7: case 7:
@ -1906,8 +1915,53 @@ static void computer_allocate(void)
rb->yield(); rb->yield();
} }
} }
/* AI player will buy nukes if possible first */ /* if the computer has no factories, build some ASAP */
if(compres.cash > PRICE_NUKE + PRICE_TANK && superdom_settings.compdiff>=3) if(!compres.inds)
{
while(compres.cash >= PRICE_FACTORY && compres.inds < numterritory)
{
i = rb->rand()%BOARD_SIZE + 1;
j = rb->rand()%BOARD_SIZE + 1;
if(board[i][j].colour == COLOUR_DARK)
{
buy_resources(COLOUR_DARK, 4, i, j, 0);
}
}
}
if(superdom_settings.compdiff>=AI_BUILD_INDS_FARMS_LEVEL && compres.cash>=PRICE_FACTORY)
{
while(compres.cash>=PRICE_FACTORY)
{
if(compres.farms<compres.inds)
{
while(compres.farms<compres.inds && compres.cash>=PRICE_FARM)
{
i = rb->rand()%BOARD_SIZE + 1;
j = rb->rand()%BOARD_SIZE + 1;
if(board[i][j].colour == COLOUR_DARK && !board[i][j].farm)
{
buy_resources(COLOUR_DARK, 3, i, j, 0);
break;
}
}
}
else
{
while(compres.inds<compres.farms && compres.cash>=PRICE_FACTORY)
{
i = rb->rand()%BOARD_SIZE + 1;
j = rb->rand()%BOARD_SIZE + 1;
if(board[i][j].colour == COLOUR_DARK && !board[i][j].ind)
{
buy_resources(COLOUR_DARK, 4, i, j, 0);
break;
}
}
}
}
}
/* AI will buy nukes first if possible */
if(compres.cash > PRICE_NUKE + PRICE_TANK && superdom_settings.compdiff>=AI_BUILD_NUKES_LEVEL)
{ {
while(compres.cash >= PRICE_NUKE && compres.nukes < numterritory) while(compres.cash >= PRICE_NUKE && compres.nukes < numterritory)
{ {
@ -1960,9 +2014,8 @@ static void computer_allocate(void)
} }
if(k == 0) if(k == 0)
{ {
/* No targets found! Randomly pick squares and if they're owned /* randomly place tanks */
* by the computer then stick a tank on it. */ while(compres.cash >= PRICE_TANK && compres.tanks < numterritory)
while(compres.cash >= 300 && compres.tanks < numterritory)
{ {
i = rb->rand()%BOARD_SIZE + 1; i = rb->rand()%BOARD_SIZE + 1;
j = rb->rand()%BOARD_SIZE + 1; j = rb->rand()%BOARD_SIZE + 1;
@ -2064,7 +2117,7 @@ static void computer_allocate(void)
} }
} }
/* no investing in easy mode */ /* no investing in easy mode */
if(superdom_settings.compdiff>=2) if(superdom_settings.compdiff>=AI_INVESTING_LEVEL)
{ {
compres.bank += compres.cash; compres.bank += compres.cash;
compres.cash = 0; compres.cash = 0;
@ -2113,7 +2166,6 @@ static void computer_movement(void)
{ {
struct cursor nukes[10]; /* 10 for now, change as needed */ struct cursor nukes[10]; /* 10 for now, change as needed */
int nukes_back=0; int nukes_back=0;
rb->splashf(HZ, "computer has %d nukes", compres.nukes);
if(compres.nukes>0) if(compres.nukes>0)
{ {
for(int i=1;i<=BOARD_SIZE && nukes_back<compres.nukes && nukes_back<10;i++) for(int i=1;i<=BOARD_SIZE && nukes_back<compres.nukes && nukes_back<10;i++)
@ -2414,7 +2466,7 @@ startyear:
} }
if(-avg_str_diff > HUMAN_SURRENDER_THRESHOLD) if(-avg_str_diff > HUMAN_SURRENDER_THRESHOLD)
{ {
rb->splash(HZ*4, "Your army have suffered terrible morale from" rb->splash(HZ*4, "Your army has suffered terrible morale from"
" the bleak prospects of winning. You lose."); " the bleak prospects of winning. You lose.");
return PLUGIN_OK; return PLUGIN_OK;
} }