diff options
author | Franklin Wei <frankhwei536@gmail.com> | 2014-08-30 20:59:20 -0400 |
---|---|---|
committer | Michael Giacomelli <giac2000@hotmail.com> | 2014-09-14 04:17:16 +0200 |
commit | a65f6ceaedae44eb0434f9511ce68472dc1b2bbe (patch) | |
tree | 390d2ea3240594162d38b1c08ffe82cebe2c5ffa /apps/plugins/superdom.c | |
parent | 333a82c8eb6888d0c6c2bca4e7a7db9603bbd0ca (diff) | |
download | rockbox-a65f6ceaedae44eb0434f9511ce68472dc1b2bbe.tar.gz rockbox-a65f6ceaedae44eb0434f9511ce68472dc1b2bbe.zip |
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>
Diffstat (limited to 'apps/plugins/superdom.c')
-rw-r--r-- | apps/plugins/superdom.c | 86 |
1 files changed, 69 insertions, 17 deletions
diff --git a/apps/plugins/superdom.c b/apps/plugins/superdom.c index edb432d68f..dfd8ccee1f 100644 --- a/apps/plugins/superdom.c +++ b/apps/plugins/superdom.c | |||
@@ -19,7 +19,9 @@ | |||
19 | * | 19 | * |
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | /* TODO list: | 21 | /* TODO list: |
22 | - improve AI (move, use nukes, etc.) | 22 | - improve AI |
23 | - buy/use nukes - DONE | ||
24 | - build farms/factories | ||
23 | */ | 25 | */ |
24 | 26 | ||
25 | 27 | ||
@@ -72,6 +74,11 @@ char buf[255]; | |||
72 | #define COMPUTER_SURRENDER_THRESHOLD 15 | 74 | #define COMPUTER_SURRENDER_THRESHOLD 15 |
73 | #define COMPUTER_HARD_SURRENDER_THRESHOLD 25 | 75 | #define COMPUTER_HARD_SURRENDER_THRESHOLD 25 |
74 | 76 | ||
77 | /* AI settings */ | ||
78 | #define AI_INVESTING_LEVEL 2 | ||
79 | #define AI_BUILD_NUKES_LEVEL 3 | ||
80 | #define AI_BUILD_INDS_FARMS_LEVEL 2 | ||
81 | |||
75 | /* board size */ | 82 | /* board size */ |
76 | #define BOARD_SIZE 10 | 83 | #define BOARD_SIZE 10 |
77 | #define NUM_SPACES (BOARD_SIZE*BOARD_SIZE) | 84 | #define NUM_SPACES (BOARD_SIZE*BOARD_SIZE) |
@@ -166,13 +173,14 @@ static struct settings { | |||
166 | easy: | 173 | easy: |
167 | - no movement | 174 | - no movement |
168 | - no investing | 175 | - no investing |
176 | - will build factories if it has none | ||
169 | medium: | 177 | medium: |
170 | - movement | 178 | - movement |
171 | - investing | 179 | - investing |
172 | - can build factories/farms | 180 | - can build factories/farms if it has money |
173 | hard: | 181 | hard: |
174 | - nuclear war | 182 | - can buy/use nukes |
175 | - harder to surrender | 183 | - will hold out longer (surrender threshold 25) |
176 | */ | 184 | */ |
177 | int compdiff; | 185 | int compdiff; |
178 | bool spoil_enabled; | 186 | bool spoil_enabled; |
@@ -569,13 +577,14 @@ static int settings_menu(void) | |||
569 | case 6: | 577 | case 6: |
570 | { | 578 | { |
571 | static const struct opt_items difficulty_options[3]={ | 579 | static const struct opt_items difficulty_options[3]={ |
572 | {"Easy", 1}, | 580 | {"Easy", -1}, |
573 | {"Intermediate", 2}, | 581 | {"Intermediate", -1}, |
574 | {"Hard", 3} | 582 | {"Hard", -1} |
575 | }; | 583 | }; |
576 | rb->set_option("Computer difficulty", &superdom_settings.compdiff, | 584 | static int sel=1; |
585 | rb->set_option("Computer difficulty", &sel, | ||
577 | INT, difficulty_options, 3, NULL); | 586 | INT, difficulty_options, 3, NULL); |
578 | superdom_settings.compdiff++; | 587 | superdom_settings.compdiff=sel+1; |
579 | break; | 588 | break; |
580 | } | 589 | } |
581 | case 7: | 590 | case 7: |
@@ -1906,8 +1915,53 @@ static void computer_allocate(void) | |||
1906 | rb->yield(); | 1915 | rb->yield(); |
1907 | } | 1916 | } |
1908 | } | 1917 | } |
1909 | /* AI player will buy nukes if possible first */ | 1918 | /* if the computer has no factories, build some ASAP */ |
1910 | if(compres.cash > PRICE_NUKE + PRICE_TANK && superdom_settings.compdiff>=3) | 1919 | if(!compres.inds) |
1920 | { | ||
1921 | while(compres.cash >= PRICE_FACTORY && compres.inds < numterritory) | ||
1922 | { | ||
1923 | i = rb->rand()%BOARD_SIZE + 1; | ||
1924 | j = rb->rand()%BOARD_SIZE + 1; | ||
1925 | if(board[i][j].colour == COLOUR_DARK) | ||
1926 | { | ||
1927 | buy_resources(COLOUR_DARK, 4, i, j, 0); | ||
1928 | } | ||
1929 | } | ||
1930 | } | ||
1931 | if(superdom_settings.compdiff>=AI_BUILD_INDS_FARMS_LEVEL && compres.cash>=PRICE_FACTORY) | ||
1932 | { | ||
1933 | while(compres.cash>=PRICE_FACTORY) | ||
1934 | { | ||
1935 | if(compres.farms<compres.inds) | ||
1936 | { | ||
1937 | while(compres.farms<compres.inds && compres.cash>=PRICE_FARM) | ||
1938 | { | ||
1939 | i = rb->rand()%BOARD_SIZE + 1; | ||
1940 | j = rb->rand()%BOARD_SIZE + 1; | ||
1941 | if(board[i][j].colour == COLOUR_DARK && !board[i][j].farm) | ||
1942 | { | ||
1943 | buy_resources(COLOUR_DARK, 3, i, j, 0); | ||
1944 | break; | ||
1945 | } | ||
1946 | } | ||
1947 | } | ||
1948 | else | ||
1949 | { | ||
1950 | while(compres.inds<compres.farms && compres.cash>=PRICE_FACTORY) | ||
1951 | { | ||
1952 | i = rb->rand()%BOARD_SIZE + 1; | ||
1953 | j = rb->rand()%BOARD_SIZE + 1; | ||
1954 | if(board[i][j].colour == COLOUR_DARK && !board[i][j].ind) | ||
1955 | { | ||
1956 | buy_resources(COLOUR_DARK, 4, i, j, 0); | ||
1957 | break; | ||
1958 | } | ||
1959 | } | ||
1960 | } | ||
1961 | } | ||
1962 | } | ||
1963 | /* AI will buy nukes first if possible */ | ||
1964 | if(compres.cash > PRICE_NUKE + PRICE_TANK && superdom_settings.compdiff>=AI_BUILD_NUKES_LEVEL) | ||
1911 | { | 1965 | { |
1912 | while(compres.cash >= PRICE_NUKE && compres.nukes < numterritory) | 1966 | while(compres.cash >= PRICE_NUKE && compres.nukes < numterritory) |
1913 | { | 1967 | { |
@@ -1960,9 +2014,8 @@ static void computer_allocate(void) | |||
1960 | } | 2014 | } |
1961 | if(k == 0) | 2015 | if(k == 0) |
1962 | { | 2016 | { |
1963 | /* No targets found! Randomly pick squares and if they're owned | 2017 | /* randomly place tanks */ |
1964 | * by the computer then stick a tank on it. */ | 2018 | while(compres.cash >= PRICE_TANK && compres.tanks < numterritory) |
1965 | while(compres.cash >= 300 && compres.tanks < numterritory) | ||
1966 | { | 2019 | { |
1967 | i = rb->rand()%BOARD_SIZE + 1; | 2020 | i = rb->rand()%BOARD_SIZE + 1; |
1968 | j = rb->rand()%BOARD_SIZE + 1; | 2021 | j = rb->rand()%BOARD_SIZE + 1; |
@@ -2064,7 +2117,7 @@ static void computer_allocate(void) | |||
2064 | } | 2117 | } |
2065 | } | 2118 | } |
2066 | /* no investing in easy mode */ | 2119 | /* no investing in easy mode */ |
2067 | if(superdom_settings.compdiff>=2) | 2120 | if(superdom_settings.compdiff>=AI_INVESTING_LEVEL) |
2068 | { | 2121 | { |
2069 | compres.bank += compres.cash; | 2122 | compres.bank += compres.cash; |
2070 | compres.cash = 0; | 2123 | compres.cash = 0; |
@@ -2113,7 +2166,6 @@ static void computer_movement(void) | |||
2113 | { | 2166 | { |
2114 | struct cursor nukes[10]; /* 10 for now, change as needed */ | 2167 | struct cursor nukes[10]; /* 10 for now, change as needed */ |
2115 | int nukes_back=0; | 2168 | int nukes_back=0; |
2116 | rb->splashf(HZ, "computer has %d nukes", compres.nukes); | ||
2117 | if(compres.nukes>0) | 2169 | if(compres.nukes>0) |
2118 | { | 2170 | { |
2119 | for(int i=1;i<=BOARD_SIZE && nukes_back<compres.nukes && nukes_back<10;i++) | 2171 | for(int i=1;i<=BOARD_SIZE && nukes_back<compres.nukes && nukes_back<10;i++) |
@@ -2414,7 +2466,7 @@ startyear: | |||
2414 | } | 2466 | } |
2415 | if(-avg_str_diff > HUMAN_SURRENDER_THRESHOLD) | 2467 | if(-avg_str_diff > HUMAN_SURRENDER_THRESHOLD) |
2416 | { | 2468 | { |
2417 | rb->splash(HZ*4, "Your army have suffered terrible morale from" | 2469 | rb->splash(HZ*4, "Your army has suffered terrible morale from" |
2418 | " the bleak prospects of winning. You lose."); | 2470 | " the bleak prospects of winning. You lose."); |
2419 | return PLUGIN_OK; | 2471 | return PLUGIN_OK; |
2420 | } | 2472 | } |