deck.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. #ifndef DECK_H
  2. #define DECK_H
  3. #include "door.h"
  4. #include <random>
  5. #include <string>
  6. #include <utility> // pair
  7. #include <vector>
  8. /*
  9. I tried card_height = 5, but the cards looked a little too stretched out/tall.
  10. 3 looks good.
  11. layout, rev2:
  12. 12345678901234567890123456789012345678901234567890123456789012345678901234567890
  13. +---------------------------------+
  14. Space Ace - Tri-Peaks Solitaire
  15. +---------------------------------+
  16. Cards start at 0, not 1!
  17. ░░1░░ ░░2░░ ░░3░░
  18. ░░░░░ ░░░░░ ░░░░░
  19. ▒▒4▒▒░░░▒▒5▒▒ ##6##░░░##7## ##8##░░░##9##
  20. ▒▒▒▒▒ ▒▒▒▒▒ ##### ##### ##### #####
  21. ▓▓10▓▒▒▒▓▓11▓▒▒▒▓▓12▓ ##13#===##14#===##15# ##16#===##17#===##18#
  22. ▓▓▓▓▓ ▓▓▓▓▓ ▓▓▓▓▓ ##### ##### ##### ##### ##### #####
  23. ██19█▓▓▓██20█▓▓▓██21█▓▓▓##22#===##23#===##24#===##25#===##26#===##27#===##28#
  24. █████ █████ █████ ##### ##### ##### ##### ##### ##### #####
  25. █████ █████ █████ ##### ##### ##### ##### ##### ##### #####
  26. Name: ##30# --29- Playing: December 31
  27. Score: ##### ----- Current Streak: nn
  28. Time used: xxx / XXX left ##### ----- Longest Streak: nn
  29. Playing Hand X of X Cards left XX
  30. 1234567890123456789012345 123456789012345 12345678901234567890
  31. [4/<] Left [6/>] Right [Space] Play Card [Enter] Draw [Q]uit [R]edraw [H]elp
  32. ^ -- above is 20 lines from +-- to [4/<] < Left
  33. score_panel left_panel streak_panel
  34. command_panel
  35. #####
  36. Player Information ##### Time in: xx Time out: xx
  37. Name: ##### Playing Day: November 3rd
  38. Hand Score : Current Streak: N
  39. Todays Score : XX Cards Remaining Longest Streak: NN
  40. Monthly Score: Playing Hand X of X Most Won: xxx Lost: xxx
  41. [4] Lf [6] Rt [Space] Play Card [Enter] Draw [D]one [H]elp [R]edraw
  42. layout, rev1:
  43. ░░░░░ ░░░░░ ░░░░░
  44. ░░░░░ ░░░░░ ░░░░░
  45. ▒▒▒▒▒░▒▒▒▒▒ #####░##### #####░#####
  46. ▒▒▒▒▒ ▒▒▒▒▒ ##### ##### ##### #####
  47. ▓▓▓▓▓▒▓▓▓▓▓▒▓▓▓▓▓ #####=#####=##### #####=#####=#####
  48. ▓▓▓▓▓ ▓▓▓▓▓ ▓▓▓▓▓ ##### ##### ##### ##### ##### #####
  49. █████▓█████▓█████▓#####=#####=#####=#####=#####=#####=#####
  50. █████ █████ █████ ##### ##### ##### ##### ##### ##### #####
  51. █████ █████ █████ ##### ##### ##### ##### ##### ##### #####
  52. #####
  53. Player Information ##### Time in: xx Time out: xx
  54. Name: ##### Playing Day: November 3rd
  55. Hand Score : Current Streak: N
  56. Todays Score : XX Cards Remaining Longest Streak: NN
  57. Monthly Score: Playing Hand X of X Most Won: xxx Lost: xxx
  58. [4] Lf [6] Rt [Space] Play Card [Enter] Draw [D]one [H]elp [R]edraw
  59. Spacing 1 or 3. 1 is what was used before, 3 looks better, takes up more
  60. screenspace. And I have plenty, even on 80x23.
  61. TODO: Have functions that gives me:
  62. int deck(int c); // which deck #
  63. int suit(int c); // suit
  64. int rank(int c); // rank
  65. */
  66. typedef std::vector<int> cards;
  67. class Deck {
  68. private:
  69. door::ANSIColor cardback;
  70. vector<door::Panel *> cards;
  71. vector<door::Panel *> backs;
  72. vector<door::Panel *> mark;
  73. door::Panel *card_of(int c);
  74. std::string back_char(int level);
  75. door::Panel *back_of(int level);
  76. door::Panel *mark_of(int c);
  77. void init(void);
  78. char rank_symbol(int c);
  79. std::string suit_symbol(int c);
  80. int card_height;
  81. public:
  82. enum SUIT { HEART, DIAMOND, CLUBS, SPADE };
  83. Deck(int size = 3);
  84. // Deck(const Deck &) = default;
  85. Deck(Deck &&);
  86. Deck &operator=(Deck &&);
  87. Deck(door::ANSIColor backcolor, int size = 3);
  88. ~Deck();
  89. int is_rank(int c);
  90. int is_suit(int c);
  91. int is_deck(int c);
  92. /**
  93. * @brief Can this rank play on this other rank?
  94. *
  95. * @param c1
  96. * @param c2
  97. * @return true
  98. * @return false
  99. */
  100. bool can_play(int c1, int c2);
  101. door::Panel *card(int c);
  102. /**
  103. * @brief Return panel for back of card.
  104. *
  105. * 0 = Blank
  106. * 1 = level 1 (furthest/darkest)
  107. * 2 = level 2
  108. * 3 = level 3
  109. * 4 = level 4 (closest/lightest)
  110. *
  111. * 5 = left (fills with left corner in place)
  112. * 6 = right (fills right corner)
  113. * 7 = both (fills both corners)
  114. *
  115. * @param level
  116. * @return door::Panel*
  117. */
  118. door::Panel *back(int level);
  119. /**
  120. * @brief Returns marker
  121. *
  122. * 0 = blank
  123. * 1 = [] symbol thing \xfe ■
  124. *
  125. * @param c
  126. * @return door::Panel*
  127. */
  128. door::Panel *marker(int c);
  129. void part(int x, int y, door::Door &d, int level, bool left);
  130. std::vector<int> unblocks(int c);
  131. const static std::array<std::pair<int, int>, 18> blocks;
  132. void remove_card(door::Door &door, int c, int off_x, int off_y, bool left,
  133. bool right);
  134. };
  135. /**
  136. * @brief Given a position, space=3, height=3, return x,y and level.
  137. *
  138. * This is the older version that allows for space and h "height"
  139. * to be variable. I'd rather have one that has them as constants.
  140. *
  141. * @param pos
  142. * @param space
  143. * @param h
  144. * @param x
  145. * @param y
  146. * @param level
  147. */
  148. [[deprecated("Use cardgo(int pos, int &x, int &y, int &level")]] void
  149. cardgo(int pos, int space, int h, int &x, int &y, int &level);
  150. /**
  151. * @brief Where does this card go?
  152. *
  153. * This finds x, y, and the level (for the card background)
  154. *
  155. * @param pos
  156. * @param x
  157. * @param y
  158. * @param level
  159. */
  160. void cardgo(int pos, int &x, int &y, int &level);
  161. /**
  162. * @brief shuffle deck of cards
  163. *
  164. * example of seeding the deck for a given date 2/27/2021 game 1
  165. * std::seed_seq s1{2021, 2, 27, 1};
  166. * vector<int> deck1 = card_shuffle(s1, 1);
  167. * @param seed
  168. * @param decks
  169. * @return vector<int>
  170. */
  171. cards card_shuffle(std::seed_seq &seed, int decks = 1);
  172. /**
  173. * @brief return vector of card states
  174. *
  175. * These are pre-initialized to 0.
  176. * Default to 1 deck (0-51), but this handles any number of decks.
  177. *
  178. * @param decks
  179. * @return cards
  180. */
  181. cards card_states(int decks = 1);
  182. /**
  183. * @brief Find the next card to move to.
  184. *
  185. * if (left) .. to the left, otherwise right
  186. * current is the current position we're on.
  187. *
  188. * return -1 failed to find anything.
  189. * @param left
  190. * @param states
  191. * @param current
  192. * @return int
  193. */
  194. int find_next(bool left, const cards &states, int current);
  195. /**
  196. * @brief Find the next closest card to move to.
  197. *
  198. * Given the card states, this finds the next closest card.
  199. * Uses current.
  200. *
  201. * return -1 there's no options to go to. (END OF GAME)
  202. * @param states
  203. * @param current
  204. * @return int
  205. */
  206. int find_next_closest(const cards &states, int current);
  207. extern vector<std::string> deck_colors;
  208. door::renderFunction makeColorRender(door::ANSIColor c1, door::ANSIColor c2,
  209. door::ANSIColor c3);
  210. door::ANSIColor from_string(std::string colorCode);
  211. std::string from_color_option(int opt);
  212. void string_toupper(std::string &str);
  213. #endif