deck.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. Spacing 1 or 3. 1 is what was used before, 3 looks better, takes up more
  10. screenspace. And I have plenty, even on 80x23.
  11. TODO: Have functions that gives me:
  12. int deck(int c); // which deck #
  13. int suit(int c); // suit
  14. int rank(int c); // rank
  15. */
  16. typedef std::vector<int> cards;
  17. class Deck {
  18. private:
  19. door::ANSIColor cardback;
  20. vector<door::Panel *> cards;
  21. vector<door::Panel *> backs;
  22. door::Panel *card_of(int c);
  23. std::string back_char(int level);
  24. door::Panel *back_of(int level);
  25. int is_rank(int c);
  26. int is_suit(int c);
  27. int is_deck(int c);
  28. void init(void);
  29. char rank_symbol(int c);
  30. std::string suit_symbol(int c);
  31. int card_height;
  32. public:
  33. enum SUIT { HEART, DIAMOND, CLUBS, SPADE };
  34. Deck(int size = 3);
  35. Deck(door::ANSIColor backcolor, int size = 3);
  36. ~Deck();
  37. door::Panel *card(int c);
  38. door::Panel *back(int level);
  39. void part(int x, int y, door::Door &d, int level, bool left);
  40. int unblocks(int c);
  41. const static std::array<std::pair<int, int>, 18> blocks;
  42. };
  43. /**
  44. * @brief Given a position, space=3, height=3, return x,y and level.
  45. *
  46. * @param pos
  47. * @param space
  48. * @param h
  49. * @param x
  50. * @param y
  51. * @param level
  52. */
  53. void cardgo(int pos, int space, int h, int &x, int &y, int &level);
  54. /**
  55. * @brief shuffle deck of cards
  56. *
  57. * example of seeding the deck for a given date 2/27/2021 game 1
  58. * std::seed_seq s1{2021, 2, 27, 1};
  59. * vector<int> deck1 = card_shuffle(s1, 1);
  60. * @param seed
  61. * @param decks
  62. * @return vector<int>
  63. */
  64. cards card_shuffle(std::seed_seq &seed, int decks = 1);
  65. cards card_states(int decks = 1);