deck.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. ░░░░░ ░░░░░ ░░░░░
  15. ░░░░░ ░░░░░ ░░░░░
  16. ▒▒▒▒▒░░░▒▒▒▒▒ #####░░░##### #####░░░#####
  17. ▒▒▒▒▒ ▒▒▒▒▒ ##### ##### ##### #####
  18. ▓▓▓▓▓▒▒▒▓▓▓▓▓▒▒▒▓▓▓▓▓ #####===#####===##### #####===#####===#####
  19. ▓▓▓▓▓ ▓▓▓▓▓ ▓▓▓▓▓ ##### ##### ##### ##### ##### #####
  20. █████▓▓▓█████▓▓▓█████▓▓▓#####===#####===#####===#####===#####===#####===#####
  21. █████ █████ █████ ##### ##### ##### ##### ##### ##### #####
  22. █████ █████ █████ ##### ##### ##### ##### ##### ##### #####
  23. #####
  24. Player Information ##### Time in: xx Time out: xx
  25. Name: ##### Playing Day: November 3rd
  26. Hand Score : Current Streak: N
  27. Todays Score : XX Cards Remaining Longest Streak: NN
  28. Monthly Score: Playing Hand X of X Most Won: xxx Lost: xxx
  29. [4] Lf [6] Rt [Space] Play Card [Enter] Draw [D]one [H]elp [R]edraw
  30. layout, rev1:
  31. ░░░░░ ░░░░░ ░░░░░
  32. ░░░░░ ░░░░░ ░░░░░
  33. ▒▒▒▒▒░▒▒▒▒▒ #####░##### #####░#####
  34. ▒▒▒▒▒ ▒▒▒▒▒ ##### ##### ##### #####
  35. ▓▓▓▓▓▒▓▓▓▓▓▒▓▓▓▓▓ #####=#####=##### #####=#####=#####
  36. ▓▓▓▓▓ ▓▓▓▓▓ ▓▓▓▓▓ ##### ##### ##### ##### ##### #####
  37. █████▓█████▓█████▓#####=#####=#####=#####=#####=#####=#####
  38. █████ █████ █████ ##### ##### ##### ##### ##### ##### #####
  39. █████ █████ █████ ##### ##### ##### ##### ##### ##### #####
  40. #####
  41. Player Information ##### Time in: xx Time out: xx
  42. Name: ##### Playing Day: November 3rd
  43. Hand Score : Current Streak: N
  44. Todays Score : XX Cards Remaining Longest Streak: NN
  45. Monthly Score: Playing Hand X of X Most Won: xxx Lost: xxx
  46. [4] Lf [6] Rt [Space] Play Card [Enter] Draw [D]one [H]elp [R]edraw
  47. Spacing 1 or 3. 1 is what was used before, 3 looks better, takes up more
  48. screenspace. And I have plenty, even on 80x23.
  49. TODO: Have functions that gives me:
  50. int deck(int c); // which deck #
  51. int suit(int c); // suit
  52. int rank(int c); // rank
  53. */
  54. typedef std::vector<int> cards;
  55. class Deck {
  56. private:
  57. door::ANSIColor cardback;
  58. vector<door::Panel *> cards;
  59. vector<door::Panel *> backs;
  60. door::Panel *card_of(int c);
  61. std::string back_char(int level);
  62. door::Panel *back_of(int level);
  63. int is_rank(int c);
  64. int is_suit(int c);
  65. int is_deck(int c);
  66. void init(void);
  67. char rank_symbol(int c);
  68. std::string suit_symbol(int c);
  69. int card_height;
  70. public:
  71. enum SUIT { HEART, DIAMOND, CLUBS, SPADE };
  72. Deck(int size = 3);
  73. Deck(door::ANSIColor backcolor, int size = 3);
  74. ~Deck();
  75. door::Panel *card(int c);
  76. door::Panel *back(int level);
  77. void part(int x, int y, door::Door &d, int level, bool left);
  78. int unblocks(int c);
  79. const static std::array<std::pair<int, int>, 18> blocks;
  80. };
  81. /**
  82. * @brief Given a position, space=3, height=3, return x,y and level.
  83. *
  84. * @param pos
  85. * @param space
  86. * @param h
  87. * @param x
  88. * @param y
  89. * @param level
  90. */
  91. void cardgo(int pos, int space, int h, int &x, int &y, int &level);
  92. /**
  93. * @brief shuffle deck of cards
  94. *
  95. * example of seeding the deck for a given date 2/27/2021 game 1
  96. * std::seed_seq s1{2021, 2, 27, 1};
  97. * vector<int> deck1 = card_shuffle(s1, 1);
  98. * @param seed
  99. * @param decks
  100. * @return vector<int>
  101. */
  102. cards card_shuffle(std::seed_seq &seed, int decks = 1);
  103. cards card_states(int decks = 1);