Browse Source

Refactor time.

db calls now all log SQLite execptions.
deck has better names.
Steve Thielemann 4 years ago
parent
commit
cab4462b20
6 changed files with 225 additions and 155 deletions
  1. 122 39
      db.cpp
  2. 13 11
      db.h
  3. 44 60
      deck.cpp
  4. 25 24
      deck.h
  5. 5 5
      main.cpp
  6. 16 16
      play.cpp

+ 122 - 39
db.cpp

@@ -20,55 +20,108 @@ The database access is slow.
 So, make sure you set it up so that you do your writes right
 before you collect user input.  That way, the user won't see
 the lags.
+
+This might be an issue on rPI systems!
+Change the strategy so we only update when the game ends.
 */
 
 DBData::DBData(void)
     : db("space-data.db", SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE) {
 
-  init();
+  create_tables();
   stmt_getSet = std::make_unique<SQLite::Statement>(
       db, "SELECT value FROM settings WHERE username=? AND setting=?");
   stmt_setSet = std::make_unique<SQLite::Statement>(
       db, "REPLACE INTO settings(username, setting, value) VALUES(?,?,?);");
 }
 
-// DBData::DBData(void) : sql(std::string(DB_CONNECT_STRING)) {}
-
 DBData::~DBData() {}
 
-void DBData::init(void) {
-  db.exec("CREATE TABLE IF NOT EXISTS \
+/**
+ * @brief create tables if they don't exist.
+ */
+void DBData::create_tables(void) {
+  try {
+    db.exec("CREATE TABLE IF NOT EXISTS \
 settings(username TEXT, setting TEXT, value TEXT, \
 PRIMARY KEY(username, setting));");
-  db.exec("CREATE TABLE IF NOT EXISTS \
+    db.exec("CREATE TABLE IF NOT EXISTS \
 scores ( \"username\" TEXT, \"when\" INTEGER, \
 \"date\" INTEGER, \"hand\" INTEGER, \"score\" INTEGER, \
 PRIMARY KEY(\"username\", \"date\", \"hand\"));");
+  } catch (std::exception &e) {
+    if (get_logger) {
+      get_logger() << "create_tables():" << std::endl;
+      get_logger() << "SQLite exception: " << e.what() << std::endl;
+    }
+  }
 }
 
-void DBData::setUser(std::string currentUser) { user = currentUser; }
-
+/**
+ * @brief get setting from the settings table
+ *
+ * We use user and setting.
+ * Return isMissing if not found.
+ *
+ * @param setting
+ * @param ifMissing
+ * @return std::string
+ */
 std::string DBData::getSetting(const std::string &setting,
                                std::string ifMissing) {
-  stmt_getSet->reset();
-  stmt_getSet->bind(1, user);
-  stmt_getSet->bind(2, setting);
-  if (stmt_getSet->executeStep()) {
-    std::string value = stmt_getSet->getColumn(0);
-    return value;
-  };
+  try {
+    stmt_getSet->reset();
+    stmt_getSet->bind(1, user);
+    stmt_getSet->bind(2, setting);
+    if (stmt_getSet->executeStep()) {
+      std::string value = stmt_getSet->getColumn(0);
+      return value;
+    };
+    return ifMissing;
+  } catch (std::exception &e) {
+    if (get_logger) {
+      get_logger() << "getSettings( " << setting << "," << ifMissing
+                   << " ): " << user << std::endl;
+      get_logger() << "SQLite exception: " << e.what() << std::endl;
+    }
+  }
   return ifMissing;
 }
 
+/**
+ * @brief save setting in the settings table
+ *
+ * We save user setting in the settings table.
+ * We use SQLite's REPLACE INTO so it does an update if it exists, or an insert
+ * if it is missing.
+ * @param setting
+ * @param value
+ */
 void DBData::setSetting(const std::string &setting, const std::string &value) {
-  stmt_setSet->reset();
-  stmt_setSet->bind(1, user);
-  stmt_setSet->bind(2, setting);
-  stmt_setSet->bind(3, value);
-  stmt_setSet->exec();
+  try {
+    stmt_setSet->reset();
+    stmt_setSet->bind(1, user);
+    stmt_setSet->bind(2, setting);
+    stmt_setSet->bind(3, value);
+    stmt_setSet->exec();
+  } catch (std::exception &e) {
+    if (get_logger) {
+      get_logger() << "setSettings( " << setting << "," << value
+                   << " ): " << user << std::endl;
+      get_logger() << "SQLite exception: " << e.what() << std::endl;
+    }
+  }
 }
 
-void DBData::save_score(time_t when, time_t date, int hand, int score) {
+/**
+ * @brief save the user's score
+ *
+ * @param when now()
+ * @param date what day they played
+ * @param hand which hand they played
+ * @param score
+ */
+void DBData::saveScore(time_t when, time_t date, int hand, int score) {
   try {
     SQLite::Statement stmt(db,
                            "INSERT INTO scores( \"username\", \"when\", "
@@ -81,42 +134,72 @@ void DBData::save_score(time_t when, time_t date, int hand, int score) {
     stmt.exec();
   } catch (std::exception &e) {
     if (get_logger) {
+      get_logger() << "saveScore( " << when << "," << date << "," << hand << ","
+                   << score << " ): " << user << std::endl;
       get_logger() << "SQLite exception: " << e.what() << std::endl;
     }
   }
 }
 
-int DBData::has_played_day(time_t day) {
-  // get date from this
-
-  // std::stringstream ss;
-  // ss << std::put_time(std::localtime(&day), "%Y/%0m/%0d");
-
-  SQLite::Statement stmt(
-      db, "SELECT COUNT(*) FROM scores WHERE \"username\"=? AND \"DATE\"=?;");
-  stmt.bind(1, user);
-  stmt.bind(2, day);
-  int count = -1;
-  if (stmt.executeStep()) {
-    count = stmt.getColumn(0);
-  };
-  return count;
+/**
+ * @brief Returns number of hands played on given day
+ *
+ * returns number of hands they played, or 0
+ * @param day
+ * @return int
+ */
+int DBData::handsPlayedOnDay(time_t day) {
+  try {
+    SQLite::Statement stmt(
+        db, "SELECT COUNT(*) FROM scores WHERE \"username\"=? AND \"DATE\"=?;");
+    stmt.bind(1, user);
+    stmt.bind(2, day);
+    int count = 0;
+    if (stmt.executeStep()) {
+      count = stmt.getColumn(0);
+    };
+    return count;
+  } catch (std::exception &e) {
+    if (get_logger) {
+      get_logger() << "handsPlayedOnDay( " << day << " ): " << user
+                   << std::endl;
+      get_logger() << "SQLite exception: " << e.what() << std::endl;
+    }
+  }
+  return 0;
 }
 
-std::string make_date(time_t tt) {
+/**
+ * @brief Format date to string.
+ *
+ * We use default "%0m/%0d/%Y", but can be configured by SysOp via
+ * config["date_score"] setting.  "%Y/%0m/%0d" for non-US?
+ *
+ * @param tt
+ * @return std::string
+ */
+std::string convertDateToDateScoreFormat(time_t tt) {
   std::stringstream ss;
   if (config["date_score"]) {
     std::string custom_format = config["date_score"].as<std::string>();
     ss << std::put_time(std::localtime(&tt), custom_format.c_str());
   } else {
-    ss << std::put_time(std::localtime(&tt), "%Y/%0m/%0d");
+    ss << std::put_time(std::localtime(&tt), "%0m/%0d/%Y");
   }
 
   std::string date = ss.str();
   return date;
 }
 
-void standard_date(time_t &tt, int hour) {
+/**
+ * @brief change datetime to have consistent time
+ *
+ * This converts the time part to hour:00
+ *
+ * @param tt
+ * @param hour
+ */
+void normalizeDate(time_t &tt, int hour) {
   std::tm *local_tm = localtime(&tt);
   // adjust date to 2:00:00 AM
 

+ 13 - 11
db.h

@@ -5,28 +5,30 @@
 
 class DBData {
   SQLite::Database db;
-  void init(void);
+  void create_tables(void);
   std::string user;
+  /*
+  I thought some of my performance problems were from the prepared statement
+  calls.  It was not the case, there's a weird delay when I save/hit the
+  database.  This didn't fix it, but they are still present.
+  Prepared statements, prepared ahead of time, are a good thing.
+   */
   std::unique_ptr<SQLite::Statement> stmt_getSet;
   std::unique_ptr<SQLite::Statement> stmt_setSet;
 
 public:
   DBData();
   virtual ~DBData();
-  void setUser(std::string user);
+
+  void setUser(std::string currentUser) { user = currentUser; };
   void clearUser(void) { user.clear(); };
-  /*
-    std::string getSetting(const std::string &user, const std::string &setting,
-                           std::string ifMissing);
-    void setSetting(const std::string &user, const std::string &setting,
-                    const std::string &value);*/
   std::string getSetting(const std::string &setting, std::string ifMissing);
   void setSetting(const std::string &setting, const std::string &value);
-  void save_score(time_t when, time_t date, int hand, int score);
-  int has_played_day(time_t day);
+  void saveScore(time_t when, time_t date, int hand, int score);
+  int handsPlayedOnDay(time_t day);
 };
 
-void standard_date(time_t &tt, int hour = 2);
-std::string make_date(time_t tt);
+void normalizeDate(time_t &tt, int hour = 2);
+std::string convertDateToDateScoreFormat(time_t tt);
 
 #endif

+ 44 - 60
deck.cpp

@@ -4,32 +4,16 @@
 #include <map>
 #include <sstream>
 
-Deck::Deck(int size) {
-  cardback = door::ANSIColor(door::COLOR::RED);
-  card_height = size;
-  init();
-}
-
-Deck::Deck(door::ANSIColor backcolor, int size) : cardback{backcolor} {
-  card_height = size;
-  init();
-}
-
-void Deck::init(void) {
-  if (card_height != 3) {
-    if (card_height != 5) {
-      card_height = 3;
-    }
-  }
+Deck::Deck(door::ANSIColor backcolor) : card_back_color{backcolor} {
   for (int i = 0; i < 52; ++i) {
-    cards.push_back(card_of(i));
+    cards.push_back(cardOf(i));
   }
   // 0 = BLANK, 1-4 levels
   for (int i = 0; i < 5; ++i) {
-    backs.push_back(back_of(i));
+    backs.push_back(backOf(i));
   }
-  mark.push_back(mark_of(0));
-  mark.push_back(mark_of(1));
+  mark.push_back(markOf(0));
+  mark.push_back(markOf(1));
 }
 
 Deck::~Deck() {
@@ -48,7 +32,7 @@ Deck::~Deck() {
 }
 
 Deck::Deck(Deck &&ref) {
-  cardback = ref.cardback;
+  card_back_color = ref.card_back_color;
   for (auto c : cards)
     delete c;
   cards.clear();
@@ -64,11 +48,11 @@ Deck::Deck(Deck &&ref) {
   mark.clear();
   mark = ref.mark;
   ref.mark.clear();
-  card_height = ref.card_height;
+  // card_height = ref.card_height;
 };
 
 Deck &Deck::operator=(Deck &&ref) {
-  cardback = ref.cardback;
+  card_back_color = ref.card_back_color;
   for (auto c : cards)
     delete c;
   cards.clear();
@@ -84,20 +68,20 @@ Deck &Deck::operator=(Deck &&ref) {
   mark.clear();
   mark = ref.mark;
   ref.mark.clear();
-  card_height = ref.card_height;
+  // card_height = ref.card_height;
   return *this;
 }
 
-int Deck::is_deck(int c) { return c / 52; }
-int Deck::is_suit(int c) { return (c % 52) / 13; }
-int Deck::is_rank(int c) { return (c % 52) % 13; }
+int Deck::getDeck(int c) { return c / 52; }
+int Deck::getSuit(int c) { return (c % 52) / 13; }
+int Deck::getRank(int c) { return (c % 52) % 13; }
 
-char Deck::rank_symbol(int c) {
+char Deck::rankSymbol(int c) {
   const char symbols[] = "A23456789TJQK";
   return symbols[c];
 }
 
-std::string Deck::suit_symbol(int c) {
+std::string Deck::suitSymbol(int c) {
   // unicode
   if (door::unicode) {
     switch (c) {
@@ -139,9 +123,9 @@ std::string Deck::suit_symbol(int c) {
   return std::string("!", 1);
 }
 
-door::Panel *Deck::card_of(int c) {
-  int suit = is_suit(c);
-  int rank = is_rank(c);
+door::Panel *Deck::cardOf(int c) {
+  int suit = getSuit(c);
+  int rank = getRank(c);
   bool is_red = (suit < 2);
   door::ANSIColor color;
 
@@ -153,8 +137,8 @@ door::Panel *Deck::card_of(int c) {
   door::Panel *p = new door::Panel(0, 0, 5);
   // setColor sets border_color.  NOT WHAT I WANT.
   // p->setColor(color);
-  char r = rank_symbol(rank);
-  std::string s = suit_symbol(suit);
+  char r = rankSymbol(rank);
+  std::string s = suitSymbol(suit);
 
   // build lines
   std::ostringstream oss;
@@ -185,7 +169,7 @@ door::Panel *Deck::card_of(int c) {
   return p;
 }
 
-std::string Deck::back_char(int level) {
+std::string Deck::backSymbol(int level) {
   std::string c;
   if (level == 0) {
     c = ' ';
@@ -225,23 +209,23 @@ std::string Deck::back_char(int level) {
   return c;
 }
 
-door::Panel *Deck::back_of(int level) {
+door::Panel *Deck::backOf(int level) {
   // using: \xb0, 0xb1, 0xb2, 0xdb
   // OR:    \u2591, \u2592, \u2593, \u2588
 
   // door::ANSIColor color(door::COLOR::RED, door::COLOR::BLACK);
   door::Panel *p = new door::Panel(0, 0, 5);
-  std::string c = back_char(level);
+  std::string c = backSymbol(level);
   std::string l = c + c + c + c + c;
   for (int x = 0; x < card_height; ++x) {
-    p->addLine(std::make_unique<door::Line>(l, 5, cardback));
+    p->addLine(std::make_unique<door::Line>(l, 5, card_back_color));
   };
-  // p->addLine(std::make_unique<door::Line>(l, 5, cardback));
-  // p->addLine(std::make_unique<door::Line>(l, 5, cardback));
+  // p->addLine(std::make_unique<door::Line>(l, 5, card_back_color));
+  // p->addLine(std::make_unique<door::Line>(l, 5, card_back_color));
   return p;
 }
 
-door::Panel *Deck::mark_of(int c) {
+door::Panel *Deck::markOf(int c) {
   door::Panel *p = new door::Panel(1);
   door::ANSIColor color = door::ANSIColor(
       door::COLOR::BLUE, door::COLOR::WHITE); // , door::ATTR::BOLD);
@@ -265,10 +249,10 @@ void Deck::part(int x, int y, door::Door &d, int level, bool left) {
   if (!left) {
     x += 2;
   }
-  std::string c = back_char(level);
+  std::string c = backSymbol(level);
   std::string l = c + c + c;
   door::Goto g(x, y);
-  d << g << cardback << l;
+  d << g << card_back_color << l;
 }
 
 door::Panel *Deck::card(int c) { return cards[c]; }
@@ -325,10 +309,10 @@ std::vector<int> Deck::unblocks(int card) {
  * @return true
  * @return false
  */
-bool Deck::can_play(int card1, int card2) {
+bool Deck::canPlay(int card1, int card2) {
   int rank1, rank2;
-  rank1 = is_rank(card1);
-  rank2 = is_rank(card2);
+  rank1 = getRank(card1);
+  rank2 = getRank(card2);
 
   // this works %13 handles wrap-around for us.
   if ((rank1 + 1) % 13 == rank2)
@@ -354,7 +338,7 @@ bool Deck::can_play(int card1, int card2) {
 door::Panel *Deck::marker(int c) { return mark[c]; }
 
 /**
- * @brief remove_card
+ * @brief removeCard
  *
  * This removes a card at a given position (c).
  * It needs to know if there are cards underneath
@@ -367,15 +351,15 @@ door::Panel *Deck::marker(int c) { return mark[c]; }
  * @param left
  * @param right
  */
-void Deck::remove_card(door::Door &door, int c, int off_x, int off_y, bool left,
-                       bool right) {
+void Deck::removeCard(door::Door &door, int c, int off_x, int off_y, bool left,
+                      bool right) {
   int cx, cy, level;
   cardgo(c, cx, cy, level);
   if (level > 1)
     --level;
-  std::string cstr = back_char(level);
+  std::string cstr = backSymbol(level);
   door::Goto g(cx + off_x, cy + off_y);
-  door << g << cardback;
+  door << g << card_back_color;
   if (left)
     door << cstr;
   else
@@ -590,12 +574,12 @@ void cardgo(int pos, int &x, int &y, int &level) {
  *
  * example of seeding the deck for a given date 2/27/2021 game 1
  * std::seed_seq s1{2021, 2, 27, 1};
- * vector<int> deck1 = card_shuffle(s1, 1);
+ * vector<int> deck1 = shuffleCards(s1, 1);
  * @param seed
  * @param decks
  * @return vector<int>
  */
-cards card_shuffle(std::seed_seq &seed, int decks) {
+cards shuffleCards(std::seed_seq &seed, int decks) {
   std::mt19937 gen;
 
   // build deck of cards
@@ -620,7 +604,7 @@ cards card_shuffle(std::seed_seq &seed, int decks) {
  * @param decks
  * @return cards
  */
-cards card_states(int decks) {
+cards makeCardStates(int decks) {
   // auto states = std::unique_ptr<std::vector<int>>(); // (decks * 52, 0)>;
   std::vector<int> states;
   states.assign(decks * 52, 0);
@@ -642,7 +626,7 @@ cards card_states(int decks) {
  * @param current
  * @return int
  */
-int find_next(bool left, const cards &states, int current) {
+int findNextActiveCard(bool left, const cards &states, int current) {
   int cx, cy, level;
   int current_x;
   cardgo(current, cx, cy, level);
@@ -713,7 +697,7 @@ int find_next(bool left, const cards &states, int current) {
  * @param current
  * @return int
  */
-int find_next_closest(const cards &states, int current) {
+int findClosestActiveCard(const cards &states, int current) {
   int cx, cy, level;
   int current_x;
   cardgo(current, cx, cy, level);
@@ -781,7 +765,7 @@ door::renderFunction makeColorRender(door::ANSIColor c1, door::ANSIColor c2,
           // handle this some other way.
           textColor.setFg(door::COLOR::WHITE);
         } else {
-          door::ANSIColor c = from_string(found);
+          door::ANSIColor c = stringToANSIColor(found);
           textColor.setFg(c.getFg());
         }
       }
@@ -835,7 +819,7 @@ door::renderFunction makeColorRender(door::ANSIColor c1, door::ANSIColor c2,
 // convert a string to an option
 // an option to the string to store
 // This needs to be updated to use deck_colors.
-door::ANSIColor from_string(std::string colorCode) {
+door::ANSIColor stringToANSIColor(std::string colorCode) {
   std::map<std::string, door::ANSIColor> codeMap = {
       {std::string("BLUE"), door::ANSIColor(door::COLOR::BLUE)},
       {std::string("RED"), door::ANSIColor(door::COLOR::RED)},
@@ -864,7 +848,7 @@ door::ANSIColor from_string(std::string colorCode) {
   // }
 }
 
-std::string from_color_option(int opt) { return deck_colors[opt]; }
+std::string stringFromColorOptions(int opt) { return deck_colors[opt]; }
 void string_toupper(std::string &str) {
   std::transform(str.begin(), str.end(), str.begin(), ::toupper);
 }

+ 25 - 24
deck.h

@@ -3,6 +3,7 @@
 
 #include "door.h"
 
+#include <memory>
 #include <random>
 #include <string>
 #include <utility> // pair
@@ -82,39 +83,38 @@ int rank(int c);  // rank
  */
 
 typedef std::vector<int> cards; // or a "deck"
+typedef std::shared_ptr<door::Panel> shared_panel;
 
 class Deck {
 private:
   // We assume for this game that there's only one deck back color.
-  door::ANSIColor cardback;
+  door::ANSIColor card_back_color;
   // shared_ptr<door::Panel> for the win?
   vector<door::Panel *> cards;
   vector<door::Panel *> backs;
   vector<door::Panel *> mark;
-  door::Panel *card_of(int c);
-  std::string back_char(int level);
-  door::Panel *back_of(int level);
-  door::Panel *mark_of(int c);
-  void init(void);
-  char rank_symbol(int c);
-  std::string suit_symbol(int c);
-  int card_height;
+  door::Panel *cardOf(int c);
+  std::string backSymbol(int level);
+  door::Panel *backOf(int level);
+  door::Panel *markOf(int c);
+  char rankSymbol(int c);
+  std::string suitSymbol(int c);
+  const int card_height = 3;
 
 public:
   enum SUIT { HEART, DIAMOND, CLUBS, SPADE };
 
-  Deck(int size = 3);
-  // Deck(const Deck &) = default;
+  Deck(door::ANSIColor backcolor = door::ANSIColor(door::COLOR::RED));
   Deck(Deck &&);
   Deck &operator=(Deck &&);
-  Deck(door::ANSIColor backcolor, int size = 3);
+
   ~Deck();
 
-  int is_rank(int c);
-  int is_suit(int c);
-  int is_deck(int c);
+  int getRank(int c);
+  int getSuit(int c);
+  int getDeck(int c);
 
-  bool can_play(int card1, int card2);
+  bool canPlay(int card1, int card2);
   door::Panel *card(int c);
   door::Panel *back(int level);
   door::Panel *marker(int c);
@@ -123,21 +123,22 @@ public:
   std::vector<int> unblocks(int card);
   const static std::array<std::pair<int, int>, 18> blocks;
 
-  void remove_card(door::Door &door, int c, int off_x, int off_y, bool left,
-                   bool right);
+  void removeCard(door::Door &door, int c, int off_x, int off_y, bool left,
+                  bool right);
 };
 
 void cardgo(int pos, int &x, int &y, int &level);
-cards card_shuffle(std::seed_seq &seed, int decks = 1);
-cards card_states(int decks = 1);
-int find_next(bool left, const cards &states, int current);
-int find_next_closest(const cards &states, int current);
+cards shuffleCards(std::seed_seq &seed, int decks = 1);
+cards makeCardStates(int decks = 1);
+int findNextActiveCard(bool left, const cards &states, int current);
+int findClosestActiveCard(const cards &states, int current);
 
 extern vector<std::string> deck_colors;
 door::renderFunction makeColorRender(door::ANSIColor c1, door::ANSIColor c2,
                                      door::ANSIColor c3);
-door::ANSIColor from_string(std::string colorCode);
-std::string from_color_option(int opt);
+door::ANSIColor stringToANSIColor(std::string colorCode);
+std::string stringFromColorOptions(int opt);
+
 void string_toupper(std::string &str);
 
 #endif

+ 5 - 5
main.cpp

@@ -43,7 +43,7 @@ bool file_exists(const char *name) {
   return f.good();
 }
 
-door::ANSIColor from_string(std::string colorCode);
+door::ANSIColor stringToANSIColor(std::string colorCode);
 
 std::function<std::ofstream &(void)> get_logger;
 
@@ -464,7 +464,7 @@ int configure(door::Door &door, DBData &db) {
 
         if (newOpt >= 0) {
           newOpt--;
-          newColor = from_color_option(newOpt);
+          newColor = stringFromColorOptions(newOpt);
           if (newOpt != currentOpt) {
             door.log() << deckcolor << " was " << currentDefault << ", "
                        << currentOpt << ". Now " << newColor << ", " << newOpt
@@ -863,7 +863,7 @@ int main(int argc, char *argv[]) {
   }
 
   if (r < 0) {
-  TIMEOUT:
+    // TIMEOUT:
     if (r == -1) {
       door.log() << "TIMEOUT" << std::endl;
 
@@ -969,8 +969,8 @@ int main(int argc, char *argv[]) {
   // games the same/fair for everyone.
 
   std::seed_seq s1{2021, 2, 27, 1};
-  cards deck1 = card_shuffle(s1, 1);
-  cards state = card_states();
+  cards deck1 = shuffleCards(s1, 1);
+  cards state = makeCardStates();
 
   // I tried setting the cursor before the delay and before displaying the
   // card. It is very hard to see / just about useless.  Not worth the

+ 16 - 16
play.cpp

@@ -40,7 +40,7 @@ PlayCards::PlayCards(door::Door &d, DBData &dbd) : door{d}, db{dbd} {
                  << std::put_time(std::localtime(&time_play_day), "%F %R")
                  << std::endl;
   };
-  standard_date(time_play_day);
+  normalizeDate(time_play_day);
   play_day = std::chrono::system_clock::from_time_t(time_play_day);
   if (get_logger) {
     get_logger() << "after: "
@@ -85,7 +85,7 @@ int PlayCards::play_cards(void) {
   init_values();
   std::string currentDefault = db.getSetting("DeckColor", "ALL");
   get_logger() << "DeckColor shows as " << currentDefault << std::endl;
-  deck_color = from_string(currentDefault);
+  deck_color = stringToANSIColor(currentDefault);
 
   dp = Deck(deck_color);
 
@@ -124,8 +124,8 @@ next_hand:
 
     std::seed_seq seq{local_tm.tm_year + 1900, local_tm.tm_mon + 1,
                       local_tm.tm_mday, hand};
-    deck = card_shuffle(seq, 1);
-    state = card_states();
+    deck = shuffleCards(seq, 1);
+    state = makeCardStates();
   }
 
   /*
@@ -217,18 +217,18 @@ next_hand:
       case '5':
         // can we play this card?
         /*
-        get_logger() << "can_play( " << select_card << ":"
+        get_logger() << "canPlay( " << select_card << ":"
                      << deck1.at(select_card) << "/"
-                     << d.is_rank(deck1.at(select_card)) << " , "
+                     << d.getRank(deck1.at(select_card)) << " , "
                      << play_card << "/" <<
-        d.is_rank(deck1.at(play_card))
+        d.getRank(deck1.at(play_card))
                      << ") = "
-                     << d.can_play(deck1.at(select_card),
+                     << d.canPlay(deck1.at(select_card),
                                    deck1.at(play_card))
                      << std::endl;
                      */
 
-        if (dp.can_play(deck.at(select_card), deck.at(play_card)) or
+        if (dp.canPlay(deck.at(select_card), deck.at(play_card)) or
             config[CHEATER]) {
           // if (true) {
           // yes we can.
@@ -270,7 +270,7 @@ next_hand:
                 left = true;
             }
 
-            dp.remove_card(door, select_card, off_x, off_y, left, right);
+            dp.removeCard(door, select_card, off_x, off_y, left, right);
 
             /*   // old way of doing this that leaves holes.
             cardgo(select_card, cx, cy, level);
@@ -336,7 +336,7 @@ next_hand:
               select_card = new_card_shown;
             } else {
               // select_card++;
-              int new_select = find_next_closest(state, select_card);
+              int new_select = findClosestActiveCard(state, select_card);
 
               if (new_select != -1) {
                 select_card = new_select;
@@ -354,9 +354,9 @@ next_hand:
                 // if (!config[CHEATER]) {
                 time_t right_now = std::chrono::system_clock::to_time_t(
                     std::chrono::system_clock::now());
-                db.save_score(right_now,
-                              std::chrono::system_clock::to_time_t(play_day),
-                              hand, score);
+                db.saveScore(right_now,
+                             std::chrono::system_clock::to_time_t(play_day),
+                             hand, score);
                 //}
                 press_a_key(door);
 
@@ -380,7 +380,7 @@ next_hand:
         break;
       case XKEY_LEFT_ARROW:
       case '4': {
-        int new_select = find_next(true, state, select_card);
+        int new_select = findNextActiveCard(true, state, select_card);
         /*
         int new_active = active_card - 1;
         while (new_active >= 0) {
@@ -404,7 +404,7 @@ next_hand:
       } break;
       case XKEY_RIGHT_ARROW:
       case '6': {
-        int new_select = find_next(false, state, select_card);
+        int new_select = findNextActiveCard(false, state, select_card);
         /*
         int new_active = active_card + 1;
         while (new_active < 28) {