deck.h 5.0 KB

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