diff --git a/.github/workflows/cpp-ci.yml b/.github/workflows/cpp-ci.yml new file mode 100644 index 0000000..07d49aa --- /dev/null +++ b/.github/workflows/cpp-ci.yml @@ -0,0 +1,23 @@ +name: C++ CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Compile C++ 2017 + run: make + analyze: + needs: build + runs-on: ubuntu-latest + steps: + - name: Install linting dependencies + run: apt-get -qq update && apt-get -qq --force-yes install cppcheck + - name: Analyze design + run: cppcheck . --std=c++17 \ No newline at end of file diff --git a/dictionary.cpp b/dictionary.cpp index 440f250..065f024 100644 --- a/dictionary.cpp +++ b/dictionary.cpp @@ -6,10 +6,18 @@ // initiate word dictionary from file .wordler.data and store them as a // list of upper case letters dictionary::dictionary(){ - std::ifstream read(".wordler.data"); + dictionary_file = DEFAULT_DICTIONARY; // default file + load_dictionary(dictionary_file); +} + +// loads words from file name passed in as long as it includes +// at least one word +void dictionary::load_dictionary(std::string file){ + std::ifstream read(file); + std::vector temp; if( !read.is_open() ){ - words.push_back("words"); + return; } else{ std::string word; @@ -18,13 +26,34 @@ dictionary::dictionary(){ for(int i=0; i 0 ){ + words = temp; + dictionary_file = file; + } read.close(); } +// returns the name of the file that was most recently used to +// load the current dictionary +std::string dictionary::file_name(){ + return dictionary_file; +} + // select a random word from our dictionary and return it std::string dictionary::select_word(){ return words.at(rand() % words.size()); +} + +// return a word from our dictionary given a seed as an index +std::string dictionary::select_word(int seed){ + return words.at(seed % words.size()); +} + +// retrieves the number of words currently in the dictionary +int dictionary::size(){ + return words.size(); } \ No newline at end of file diff --git a/dictionary.h b/dictionary.h index 913f671..1a6005c 100644 --- a/dictionary.h +++ b/dictionary.h @@ -6,11 +6,17 @@ class dictionary{ private: + const std::string DEFAULT_DICTIONARY = ".wordler.data"; std::vector words; - void load_words(); + std::string dictionary_file; + public: dictionary(); + void load_dictionary(std::string); + std::string file_name(); std::string select_word(); + std::string select_word(int seed); + int size(); }; #endif \ No newline at end of file diff --git a/main.cpp b/main.cpp index ec3befc..5f8a9de 100644 --- a/main.cpp +++ b/main.cpp @@ -31,7 +31,8 @@ int main(){ // capitalize guess for easy comparisons capitalize(guess); guesses++; - hint = capitalize(get_hint(guess,secret)); + hint = get_hint(guess,secret); + capitalize(hint); if( hint == secret ){ std::cout << "Congrats, you got it in " << guesses << " guesses!\n";