Skip to content

Commit

Permalink
Merge pull request #1 from kbuffardi/design
Browse files Browse the repository at this point in the history
Design updates with CI
  • Loading branch information
kbuffardi authored Mar 7, 2022
2 parents 2a15ce5 + 647b6f0 commit c69b25c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 5 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/cpp-ci.yml
Original file line number Diff line number Diff line change
@@ -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
35 changes: 32 additions & 3 deletions dictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <std::string> temp;

if( !read.is_open() ){
words.push_back("words");
return;
}
else{
std::string word;
Expand All @@ -18,13 +26,34 @@ dictionary::dictionary(){
for(int i=0; i<word.length(); i++){
word[i] = toupper(word[i]);
}
words.push_back(word);
temp.push_back(word);
}
}

if( temp.size() > 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();
}
8 changes: 7 additions & 1 deletion dictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@

class dictionary{
private:
const std::string DEFAULT_DICTIONARY = ".wordler.data";
std::vector<std::string> 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
3 changes: 2 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit c69b25c

Please sign in to comment.