deck.h 7.1 KB

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