Browse Source

Move docs to cpp. Initial cleanup.

Steve Thielemann 4 years ago
parent
commit
75c9bd250f
2 changed files with 71 additions and 121 deletions
  1. 65 11
      deck.cpp
  2. 6 110
      deck.h

+ 65 - 11
deck.cpp

@@ -273,6 +273,22 @@ void Deck::part(int x, int y, door::Door &d, int level, bool left) {
 
 door::Panel *Deck::card(int c) { return cards[c]; }
 
+/**
+ * @brief Return panel for back of card.
+ *
+ * 0 = Blank
+ * 1 = level 1 (furthest/darkest)
+ * 2 = level 2
+ * 3 = level 3
+ * 4 = level 4 (closest/lightest)
+ *
+ * 5 = left (fills with left corner in place)
+ * 6 = right (fills right corner)
+ * 7 = both (fills both corners)
+ *
+ * @param level
+ * @return door::Panel*
+ */
 door::Panel *Deck::back(int level) { return backs[level]; }
 
 const std::array<std::pair<int, int>, 18> Deck::blocks = {
@@ -288,36 +304,53 @@ const std::array<std::pair<int, int>, 18> Deck::blocks = {
 /**
  * @brief Which card (if any) is unblocked by this card
  *
- * @param c
+ * @param card
  * @return * int
  */
-std::vector<int> Deck::unblocks(int c) {
+std::vector<int> Deck::unblocks(int card) {
   std::vector<int> result;
   for (size_t i = 0; i < blocks.size(); ++i) {
-    if ((blocks.at(i).first == c) || (blocks.at(i).second == c)) {
+    if ((blocks.at(i).first == card) || (blocks.at(i).second == card)) {
       result.push_back(i);
     }
   }
   return result;
 }
 
-bool Deck::can_play(int c1, int c2) {
-  int s1, s2;
-  s1 = is_rank(c1);
-  s2 = is_rank(c2);
+/**
+ * @brief Can this card play on this other card?
+ *
+ * @param card1
+ * @param card2
+ * @return true
+ * @return false
+ */
+bool Deck::can_play(int card1, int card2) {
+  int rank1, rank2;
+  rank1 = is_rank(card1);
+  rank2 = is_rank(card2);
 
   // this works %13 handles wrap-around for us.
-  if ((s1 + 1) % 13 == s2)
+  if ((rank1 + 1) % 13 == rank2)
     return true;
 
-  if (s1 == 0) {
-    s1 += 13;
+  if (rank1 == 0) {
+    rank1 += 13;
   }
-  if (s1 - 1 == s2)
+  if (rank1 - 1 == rank2)
     return true;
   return false;
 }
 
+/**
+ * @brief Returns marker
+ *
+ * 0 = blank
+ * 1 = [] symbol thing \xfe ■
+ *
+ * @param c
+ * @return door::Panel*
+ */
 door::Panel *Deck::marker(int c) { return mark[c]; }
 
 /**
@@ -552,6 +585,16 @@ void cardgo(int pos, int &x, int &y, int &level) {
   }
 }
 
+/**
+ * @brief shuffle deck of cards
+ *
+ * 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);
+ * @param seed
+ * @param decks
+ * @return vector<int>
+ */
 cards card_shuffle(std::seed_seq &seed, int decks) {
   std::mt19937 gen;
 
@@ -659,6 +702,17 @@ int find_next(bool left, const cards &states, int current) {
   return pos;
 }
 
+/**
+ * @brief Find the next closest card to move to.
+ *
+ * Given the card states, this finds the next closest card.
+ * Uses current.
+ *
+ * return -1 there's no options to go to.  (END OF GAME)
+ * @param states
+ * @param current
+ * @return int
+ */
 int find_next_closest(const cards &states, int current) {
   int cx, cy, level;
   int current_x;

+ 6 - 110
deck.h

@@ -81,11 +81,13 @@ int suit(int c);  // suit
 int rank(int c);  // rank
  */
 
-typedef std::vector<int> cards;
+typedef std::vector<int> cards; // or a "deck"
 
 class Deck {
 private:
+  // We assume for this game that there's only one deck back color.
   door::ANSIColor cardback;
+  // shared_ptr<door::Panel> for the win?
   vector<door::Panel *> cards;
   vector<door::Panel *> backs;
   vector<door::Panel *> mark;
@@ -111,130 +113,24 @@ public:
   int is_rank(int c);
   int is_suit(int c);
   int is_deck(int c);
-  /**
-   * @brief Can this rank play on this other rank?
-   *
-   * @param c1
-   * @param c2
-   * @return true
-   * @return false
-   */
-  bool can_play(int c1, int c2);
 
+  bool can_play(int card1, int card2);
   door::Panel *card(int c);
-  /**
-   * @brief Return panel for back of card.
-   *
-   * 0 = Blank
-   * 1 = level 1 (furthest/darkest)
-   * 2 = level 2
-   * 3 = level 3
-   * 4 = level 4 (closest/lightest)
-   *
-   * 5 = left (fills with left corner in place)
-   * 6 = right (fills right corner)
-   * 7 = both (fills both corners)
-   *
-   * @param level
-   * @return door::Panel*
-   */
-
   door::Panel *back(int level);
-  /**
-   * @brief Returns marker
-   *
-   * 0 = blank
-   * 1 = [] symbol thing \xfe ■
-   *
-   * @param c
-   * @return door::Panel*
-   */
   door::Panel *marker(int c);
+
   void part(int x, int y, door::Door &d, int level, bool left);
-  std::vector<int> unblocks(int c);
+  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);
 };
 
-/**
- * @brief Given a position, space=3, height=3, return x,y and level.
- *
- * This is the older version that allows for space and h "height"
- * to be variable.  I'd rather have one that has them as constants.
- *
- * @param pos
- * @param space
- * @param h
- * @param x
- * @param y
- * @param level
- */
-[[deprecated("Use cardgo(int pos, int &x, int &y, int &level")]] void
-cardgo(int pos, int space, int h, int &x, int &y, int &level);
-
-/**
- * @brief Where does this card go?
- *
- * This finds x, y, and the level (for the card background)
- *
- * @param pos
- * @param x
- * @param y
- * @param level
- */
 void cardgo(int pos, int &x, int &y, int &level);
-
-/**
- * @brief shuffle deck of cards
- *
- * 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);
- * @param seed
- * @param decks
- * @return vector<int>
- */
 cards card_shuffle(std::seed_seq &seed, int decks = 1);
-
-/**
- * @brief return vector of card states
- *
- * These are pre-initialized to 0.
- * Default to 1 deck (0-51), but this handles any number of decks.
- *
- * @param decks
- * @return cards
- */
-
 cards card_states(int decks = 1);
-
-/**
- * @brief Find the next card to move to.
- *
- * if (left) .. to the left, otherwise right
- * current is the current position we're on.
- *
- * return -1 failed to find anything.
- * @param left
- * @param states
- * @param current
- * @return int
- */
 int find_next(bool left, const cards &states, int current);
-
-/**
- * @brief Find the next closest card to move to.
- *
- * Given the card states, this finds the next closest card.
- * Uses current.
- *
- * return -1 there's no options to go to.  (END OF GAME)
- * @param states
- * @param current
- * @return int
- */
 int find_next_closest(const cards &states, int current);
 
 extern vector<std::string> deck_colors;