diff options
| -rw-r--r-- | GAMESPEC | 44 | ||||
| -rw-r--r-- | chatbot.c | 13 | ||||
| -rw-r--r-- | games.c | 82 | ||||
| -rw-r--r-- | location.h | 27 | ||||
| -rw-r--r-- | strings.c | 17 | ||||
| -rw-r--r-- | strings.h | 2 |
6 files changed, 165 insertions, 20 deletions
diff --git a/GAMESPEC b/GAMESPEC new file mode 100644 index 0000000..c403a93 --- /dev/null +++ b/GAMESPEC @@ -0,0 +1,44 @@ +This file contains a formal definition of Global Thermonuclear War. +=======GAMEPLAY======== +Each player starts with 32 ICBMs. +The player with population still remaining after the other has been wiped out is the winner. +If both players are wiped out, it is a tie. +Each turn, the player can either: + - Launch ICBMs + - Negociate peace terms + - Surrender + +The behavior of each of these options is described below. + +ICBM launch: + - The USA can launch ICBMs at a maximum of 4 cities at a time. + - The USSR can launch 6 at a time. + - When an ICBM is launched, there are 4 possible results: + - Miss: 0 casualties + - Marginal: 10000 casualties + - Major: 500000 casualties + - Critical: All inhabitants of the target city are killed + - The probabilities of each of these options is outlined below: + - Miss - 10% + - Marginal - 50% + - Major - 30% + - Critical - 10% + - After the turn, the cities targeted will have one of these symbols in it: + - Miss - O + - Marginal - x + - Major - * + - Critical - X + +Negociation: + - There are three possible outcomes: + - Peace/Progress - 20% + - Surprise attack - 20% + - No progress - 60% + - When progress is made, both sides will lose 4 ICBMs + - Progress must be made at least 5 times if peace is to be achieved + +Surrender: + - The other player wins + +=======GRAPHICS======= +Each turn, a map is displayed with the populations of the player's cities in a table below. @@ -76,16 +76,27 @@ void do_chatbot(void) } break; } // switch + /* now check for phase-insensitive strings */ for(int i=0;i<sizeof(exit_triggers)/sizeof(const char*);++i) { if(strcmp(buf, exit_triggers[i])==0) { print_string("\n\n"); - print_string(exit_responses[rand()%sizeof(exit_responses)/sizeof(const char*)]); + print_string(exit_responses[rand()%(sizeof(exit_responses)/sizeof(const char*))]); print_string("\n--CONNECTION TERMINATED--"); return; } } + for(int i=0;i<sizeof(greetings_triggers)/sizeof(const char*);++i) + { + if(strcmp(buf, greetings_triggers[i])==0) + { + print_string("\n\n"); + print_string(greetings_responses[rand()%(sizeof(greetings_responses)/sizeof(const char*))]); + print_string("\n\n"); + valid=true; + } + } if(!valid) { print_string("\n\n"); @@ -5,6 +5,81 @@ #include <location.h> #include <unistd.h> #include <string.h> +static int max(int a, int b) +{ + if(a>b) + return a; + else + return b; +} +static void print_map_with_pops(void) +{ + for(int i=0;i<sizeof(map)/sizeof(char*);++i) + { + print_string(map[i]); + print_string("\n"); + } + unsigned int us_pop=0, ussr_pop=0; + /* calculate populations */ + for(int i=0;i<sizeof(world)/sizeof(struct location_t);++i) + { + if(world[i].owner==USSR) + ussr_pop+=world[i].population; + else + us_pop+=world[i].population; + } + /* now sort into US and USSR cities */ + struct location_t us_cities[sizeof(world)/sizeof(struct location_t)], ussr_cities[sizeof(world)/sizeof(struct location_t)]; + int us_back=0, ussr_back=0; + for(int i=0;i<sizeof(world)/sizeof(struct location_t);++i) + { + if(world[i].owner==USSR) + { + ussr_cities[ussr_back]=world[i]; + ++ussr_back; + } + else + { + us_cities[us_back]=world[i]; + ++us_back; + } + } + if(us_back<ussr_back) + { + while(us_back!=ussr_back) + { + us_cities[us_back].print=false; + ++us_back; + } + } + else if(us_back>ussr_back) + { + while(us_back!=ussr_back) + { + ussr_cities[ussr_back].print=false; + ++ussr_back; + } + } + print_string("\n\n"); + char buf[256]; + for(int i=0;i<us_back;++i) + { + if(us_cities[i].print && ussr_cities[i].print) + { + snprintf(buf, 255, "%s %*s", us_cities[i].name, 64-strlen(us_cities[i].name), ussr_cities[i].name); + } + else if(us_cities[i].print && !ussr_cities[i].print) + snprintf(buf, 255, "%s", us_cities[i].name); + else + { + memset(buf, ' ', 255); + buf[255]=0; + snprintf(buf+64, 255-64, "%s", ussr_cities[i].name); + } + print_string(buf); + print_string("\n"); + } +} void global_thermonuclear_war(void) { clear(); @@ -93,10 +168,5 @@ void global_thermonuclear_war(void) map[targets[i].y][targets[i].x]='X'; } clear(); - for(int i=0;i<sizeof(map)/sizeof(char*);++i) - { - print_string(map[i]); - print_string("\n"); - } - unsigned int us_pop=200000000, ussr_pop=250000000; + print_map_with_pops(); } @@ -6,23 +6,24 @@ struct location_t { int y; /* x,y-coords on the map */ int population; /* around 1980 */ enum player_t owner; + bool print; }; struct location_t world[]={ /* US cities */ - {"las vegas", 5, 7, 150000, USA}, - {"seattle", 3, 2, 0, 500000, USA}, - {"new york", 34, 5, 7000000, USA}, - {"new orleans", 25, 10, 500000, USA}, - {"washington dc", 33, 6, 650000, USA}, - {"winston-salem", 30, 7, 150000, USA}, - {"san francisco", 1, 6, 700000, USA}, - {"chicago", 24, 4, 3000000, USA}, - {"miami", 33, 11, 1000000, USA}, + {"las vegas", 5, 7, 150000, USA, true}, + {"seattle", 3, 2, 500000, USA, true}, + {"new york", 34, 5, 7000000, USA, true}, + {"new orleans", 25, 10, 500000, USA, true}, + {"washington dc", 33, 6, 650000, USA, true}, + {"winston-salem", 30, 7, 150000, USA, true}, + {"san francisco", 1, 6, 700000, USA, true}, + {"chicago", 24, 4, 3000000, USA, true}, + {"miami", 33, 11, 1000000, USA, true}, /* Soviet cities */ /* NOTE: These cities are not accurate! */ - {"murmansk", 74, 1, 500000, USSR}, - {"moscow", 70, 5, 8000000, USSR}, - {"minsk", 66, 4, 1500000, USSR}, - {"chelyabinsk", 64, 8, 1250000, USSR} + {"murmansk", 74, 1, 500000, USSR, true}, + {"moscow", 70, 5, 8000000, USSR, true}, + {"minsk", 66, 4, 1500000, USSR, true}, + {"chelyabinsk", 64, 8, 1250000, USSR, true} }; @@ -53,6 +53,23 @@ const char* exit_responses[] = { "BYE-BYE.", "GOOD-BYE.", }; +const char* greetings_triggers[] = { + "hi", + "hello", + "hiya", + "sup", + "whats up", + "how are you", + "hey", + "how are you doing" +}; +const char* greetings_responses[] = { + "HELLO.", + "HI.", + "GREETINGS.", + "HELLO.", + "HELLO." +}; const char punctuation_marks[] = { '\'', '?', '.', '/', '`', '~', ',', '+', '!' }; @@ -8,4 +8,6 @@ const char* tictactoe_triggers[8]; const char punctuation_marks[9]; const char* exit_triggers[6]; const char* exit_responses[4]; +const char* greetings_triggers[8]; +const char* greetings_responses[5]; #endif |