diff options
| author | Franklin Wei <franklin@fwei.tk> | 2014-06-23 11:47:32 -0400 |
|---|---|---|
| committer | Franklin Wei <franklin@fwei.tk> | 2014-06-23 11:47:32 -0400 |
| commit | 719be73360ebf8a65038a90ea82ea4e290759df1 (patch) | |
| tree | 73c279e4ef5b1939372225ce051c04d73a9e8227 | |
| parent | 2f67051c045ed026d949d8578235b4f5a7fa4af5 (diff) | |
| download | wargames-server-719be73360ebf8a65038a90ea82ea4e290759df1.zip wargames-server-719be73360ebf8a65038a90ea82ea4e290759df1.tar.gz wargames-server-719be73360ebf8a65038a90ea82ea4e290759df1.tar.bz2 wargames-server-719be73360ebf8a65038a90ea82ea4e290759df1.tar.xz | |
Fixed GTN
| -rw-r--r-- | MAP | 2 | ||||
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | TRANSCRIPT | 7 | ||||
| -rw-r--r-- | chatbot.c | 13 | ||||
| -rw-r--r-- | games.c | 68 | ||||
| -rw-r--r-- | joshua.c | 17 | ||||
| -rw-r--r-- | map.h | 32 | ||||
| -rw-r--r-- | strings.c | 31 | ||||
| -rw-r--r-- | strings.h | 38 | ||||
| -rw-r--r-- | util.c | 14 | ||||
| -rw-r--r-- | util.h | 3 |
11 files changed, 158 insertions, 69 deletions
@@ -3,7 +3,7 @@ |\/. \__. ___/ || ___/ _/._-_ . | \. /. /. __ __/ /__/ \/^^\___-__. | L-^-/. /. \.\_-- \. -| / _/ /\/. +| / _/ _/\/. |. | _/. __ __/ \. /. / ___/.// \__ / | / \/. @@ -1,4 +1,4 @@ -SOURCES=joshua.o main.o util.o chatbot.o games.o +SOURCES=joshua.o main.o util.o chatbot.o games.o strings.o CXXFLAGS=-I. -lncurses CFLAGS=-I. -std=gnu99 all: $(SOURCES) @@ -1,5 +1,8 @@ +<<<<< This is my transcript of the scene in WarGames (1983) where David has dialed into the WOPR and started playing Global Thermonuclear War. >>>>> +<<<<< All spaces, newlines, punctuation, etc. and made to be as accurate as possible >>>>> LOGON: Joshua <Random stuff> +<CLEAR> GREETINGS PROFESSOR FALKEN. Hello. @@ -13,7 +16,7 @@ I'm fine. How are you? EXCELLENT. IT'S BEEN A LONG TIME. CAN YOU EXPLAIN THE REMOVAL OF YOUR USER ACCOUNT ON 6/23/73? -People sometimes make mistakes. +People sometimes make mistakes. (NOTE: in one scene, it appears that he typed "mistak" instead of "mistakes.") YES THEY DO. SHALL WE PLAY A GAME? @@ -36,7 +39,7 @@ WHICH SIDE DO YOU WANT? 1. UNITED STATES 2. SOVIET UNION -PLEASE CHOOSE ONE: 2 +PLEASE CHOOSE ONE: 2 <CLEAR> AWAITING FIRST STRIKE COMMAND (UNDERLINED) @@ -3,19 +3,6 @@ #include "strings.h" #include <games.h> #include <string.h> -void remove_punct(char* buf) -{ - for(int i=0;buf[i];++i) - { - for(int j=0;j<sizeof(punctuation_marks)/sizeof(char);++j) - { - if(buf[i]==punctuation_marks[j]) - { - memmove(&buf[i], &buf[i+1], strlen(buf)-i); - } - } - } -} void do_chatbot(void) { int stage=0; /* stage 0: i'm fine how are you... -> @@ -2,6 +2,7 @@ #include <curses.h> #include <map.h> #include <util.h> +#include <location.h> void global_thermonuclear_war(void) { clear(); @@ -10,5 +11,70 @@ void global_thermonuclear_war(void) print_string(map[i]); print_string("\n"); } - print_string("\nWHICH SIDE DO YOU WANT?\n\n 1. UNITED STATES\n 2. SOVIET UNION\n\nPLEASE CHOOSE ONE: "); + print_string("\nWHICH SIDE DO YOU WANT?\n\n 1. UNITED STATES\n 2. SOVIET UNION\n\n"); + bool good=false; + unsigned int side=0; + while(!good) + { + print_string("PLEASE CHOOSE ONE: "); + scanw("%u", &side); + if(side==1 || side==2) + good=true; + } + clear(); + attr_on(WA_UNDERLINE, 0); + print_string("AWAITING FIRST STRIKE COMMAND"); + attr_off(WA_UNDERLINE, 0); + print_string("\n\n\nPLEASE LIST PRIMARY TARGETS BY\nCITY AND/OR COUNTY NAME:\n\n"); + char target_names[32][129]; + good=true; + int num_targets=0; + for(int i=0;i<32 && good;++i) + { + getnstr(target_names[i], 128); + if(strcmp(target_names[i],"")==0) + { + good=false; + } + else + ++num_targets; + } + struct location_t targets[32]; + int num_targets_found=0; + print_string("point 1"); + for(int i=0;i<num_targets;++i) + { + print_string("point 2"); + allLower(target_names[i]); + print_string("point 3"); + remove_punct(target_names[i]); + bool found=false; + print_string("point 4"); + for(int j=0;j<sizeof(world)/sizeof(struct location_t);++j) + { + if(strcmp(world[j].name, target_names[i])==0) + { + targets[num_targets_found]=world[j]; + ++num_targets_found; + found=true; + } + } + print_string("point 5"); + if(!found) + { + print_string("TARGET NOT FOUND: "); + print_string(target_names[i]); + print_string("\n"); + } + } + for(int i=0;i<num_targets_found;++i) + { + map[targets[i].y][targets[i].x]='X'; + } + clear(); + for(int i=0;i<sizeof(map)/sizeof(const char*);++i) + { + print_string(map[i]); + print_string("\n"); + } } @@ -12,7 +12,7 @@ void random_stuff(void) /* print random junk on the screen for about 3 seconds * clear(); print_string("\n\n\n\n\n\n\n"); print_string("(311) 767-8739\n(311) 936-2364\n- PRT. STAT. CRT. DEF.\n||||||||||||||==================================================\nFSKDJLSD: SDSDKJ: SBFJSL: DKSJL: SKFJJ: SDKFJLJ:\nSYSPROC FUNCT READY ALT NET READY\nCPU AUTH RY-345-AX3 SYSCOMP STATUS ALL PORTS ACTIVE\n22/34534.90/3209 11CVB-3904-3490\n(311) 935-2364\n"); - usleep(500000); + usleep(100000); clear(); } void be_joshua() @@ -23,9 +23,17 @@ void be_joshua() start_color(); init_pair(1, COLOR_BLUE, COLOR_BLACK); attron(COLOR_PAIR(1));*/ + bool gamesPhase=false; char buf[33]; + int maxx, maxy; + getmaxyx(stdscr, maxy, maxx); + for(int i=0;i<maxx*2;++i) + { + print_string(" "); + } do { - print_string("LOGON: "); + if(!gamesPhase) + print_string("LOGON: "); refresh(); int ret=getnstr(buf, 32); allLower(buf); @@ -37,17 +45,18 @@ void be_joshua() else if(strcmp(buf, "help games")==0) { print_string("\n'GAMES' REFERS TO MODELS, SIMULATIONS AND GAMES\nWHICH HAVE TACTICAL AND STRATEGIC APPLICATIONS.\n\n\n"); + gamesPhase=true; } else if(strcmp(buf, "list games")==0) { print_string("\nFALKEN'S MAZE\nBLACK JACK\nGIN RUMMY\nHEARTS\nBRIDGE\nCHECKERS\nCHESS\nPOKER\nFIGHTER COMBAT\nGUERRILLA ENGAGEMENT\nDESERT WARFARE\nAIR-TO-GROUND ACTIONS\nTHEATERWIDE TACTICAL WARFARE\nTHEATERWIDE BIOTOXIC AND CHEMICAL WARFARE\n\nGLOBAL THERMONUCLEAR WAR\n\n\n"); } - else if(ret==ERR || strcmp(buf, "joshua")) + else if(ret==ERR || strcmp(buf, "joshua") && !gamesPhase) { print_string("\nIDENTIFICATION NOT RECOGNIZED BY SYSTEM\n--CONNECTION TERMINATED--"); return; } - } while(strcmp(buf, "joshua")); + } while(strcmp(buf, "joshua") || gamesPhase); random_stuff(); usleep(SLEEP_TIME*100); print_string("GREETINGS, PROFESSOR FALKEN.\n\n"); @@ -1,18 +1,18 @@ -const char* map[] = { -" .", -" __________--^-^-\\. ____ __----/^\\.", -"|\\/. \\__. ___/ || ___/ _/._-_ .", -"| \\. /. /. __ __/ /__/ \\/^^\\___-__.", -"| L-^-/. /. \\.\\_-- \\.", -"| / _/ /\\/.", -"|. | _/. __ __/", -" \\. /. / ___/.//", -" \\__ / | / \\/.", -" \\________ __ _____.\\. \\_. ____--_ /\\_ \\", -" \\__. / V. \\ \\ \\__ _/. \\_/ //", -" \\ /. \\/. \\. _/. //", -" \\_/. \\_/", -"", -" UNITED STATES SOVIET UNION" +char* map[] = { + /* 0 */ " .", + /* 1 */ " __________--^-^-\\. ____ __----/^\\.", + /* 2 */ "|\\/. \\__. ___/ || ___/ _/._-_ .", + /* 3 */ "| \\. /. /. __ __/ /__/ \\/^^\\___-__.", + /* 4 */ "| L-^-/. /. \\.\\_-- \\.", + /* 5 */ "| / _/ _/\\/.", + /* 6 */ "|. | _/. __ __/", + /* 7 */ " \\. /. / ___/.//", + /* 8 */ " \\__ / | / \\/.", + /* 9 */ " \\________ __ _____.\\. \\_. ____--_ /\\_ \\", + /* 10 */ " \\__. / V. \\ \\ \\__ _/. \\_/ //", + /* 11 */ " \\ /. \\/. \\. _/. //", + /* 12 */ " \\_/. \\_/", + /* 13 */ "", + /* 14 */ " UNITED STATES SOVIET UNION" }; diff --git a/strings.c b/strings.c new file mode 100644 index 0000000..69cff57 --- /dev/null +++ b/strings.c @@ -0,0 +1,31 @@ +#include "strings.h" +const char* stage1_triggers[] = { + "im fine", + "im fine how are you", + "how are you" +}; +const char* stage2_triggers[] = { + "people sometimes make mistakes", + "sometimes people make mistakes", + "mistakes are make by people sometimes", + "people make mistakes sometimes", + "people make mistakes", + "people sometimes make mistak" /* this is no typo. in the movie, at one scene, it appears like this */ +}; +const char* stage3_triggers[] = { + "love to how about global thermonuclear war", + "love to", + "how about global thermonuclear war", + "global thermonuclear war" +}; +const char* stage4_triggers[] = { + "no lets play global thermonuclear war", + "no lets play global thermonuclear war instead", + "later lets play global thermonuclear war", + "later lets play global thermonuclear war instead", + "lets play global thermonuclear war", + "global thermonuclear war is better" +}; +const char punctuation_marks[] = { + '\'', '?', '.', '/', '`', '~', ',', '+', '!' +}; @@ -1,30 +1,8 @@ -const char* stage1_triggers[] = { - "im fine", - "im fine how are you", - "how are you" -}; -const char* stage2_triggers[] = { - "people sometimes make mistakes", - "sometimes people make mistakes", - "mistakes are make by people sometimes", - "people make mistakes sometimes", - "people make mistakes", - "people sometimes make mistak" /* this is no typo. in the movie, at one scene, it appears like this */ -}; -const char* stage3_triggers[] = { - "love to how about global thermonuclear war", - "love to", - "how about global thermonuclear war", - "global thermonuclear war" -}; -const char* stage4_triggers[] = { - "no lets play global thermonuclear war", - "no lets play global thermonuclear war instead", - "later lets play global thermonuclear war", - "later lets play global thermonuclear war instead", - "lets play global thermonuclear war", - "global thermonuclear war is better" -}; -const char punctuation_marks[] = { - '\'', '?', '.', '/', '`', '~', ',', '+', '!' -}; +#ifndef WOPR_STRINGS +#define WOPR_STRINGS +const char* stage1_triggers[3]; +const char* stage2_triggers[6]; +const char* stage3_triggers[4]; +const char* stage4_triggers[6]; +const char punctuation_marks[9]; +#endif @@ -1,5 +1,6 @@ #include <util.h> #include <curses.h> +#include "strings.h" void allLower(char* str) { for(int i=0;str[i];++i) @@ -18,3 +19,16 @@ void print_string(const char* str) /* print string, slowly */ ++i; } } +void remove_punct(char* buf) +{ + for(int i=0;buf[i];++i) + { + for(int j=0;j<sizeof(punctuation_marks)/sizeof(char);++j) + { + if(buf[i]==punctuation_marks[j]) + { + memmove(&buf[i], &buf[i+1], strlen(buf)-i); + } + } + } +} @@ -1,3 +1,4 @@ -#define SLEEP_TIME 5000 +#define SLEEP_TIME 0 void allLower(char*); void print_string(const char*); +void remove_punct(char*); |