Advertisement
Guest User

Serialized Classes

a guest
Jun 6th, 2020
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.40 KB | None | 0 0
  1. class InfosetHistory {
  2. public:
  3.     InfosetHistory();
  4.  
  5.     Card initialDiscardPile;
  6.     std::vector<Card> initialHand;
  7.     std::vector<DrawAction> playerDrawActions;
  8.     std::vector<Card> playerDiscardActions;
  9.     std::vector<DrawAction> opponentDrawActions;
  10.     std::vector<Card> opponentDiscardActions;
  11.  
  12.     InfosetHistory(Card initialDiscardPile, std::vector<Card> hand);
  13.  
  14.     InfosetHistory(Card initialDiscardPile, std::vector<Card> hand,
  15.                    std::vector<DrawAction> playerDrawActions, std::vector<Card> playerDiscardActions,
  16.                    std::vector<DrawAction> opponentDrawActions, std::vector<Card> opponentDiscardActions);
  17.     ...
  18.  
  19.     template<class Archive>
  20.     void serialize(Archive& ar, const unsigned int version) {
  21.         ar & initialDiscardPile;
  22.         ar & initialHand;
  23.         ar & playerDrawActions;
  24.         ar & playerDiscardActions;
  25.         ar & opponentDrawActions;
  26.         ar & opponentDiscardActions;
  27.     }
  28. };
  29.  
  30. struct DrawAction {
  31.     bool fromDeck;
  32.     Card card;
  33.  
  34.     DrawAction(){
  35.         fromDeck = false;
  36.         card = Card();
  37.     }
  38.  
  39.     explicit DrawAction(bool fromDeck) {
  40.         this->fromDeck = fromDeck;
  41.     }
  42.  
  43.     DrawAction(bool fromDeck, Card& card) {
  44.         this->fromDeck = fromDeck;
  45.         this->card = card;
  46.     }
  47.    
  48.     ...
  49.  
  50.     template<class Archive>
  51.     void serialize(Archive& ar, const unsigned int version) {
  52.         ar & fromDeck;
  53.         ar & card;
  54.     }
  55. };
  56.  
  57. class Node {
  58. public:
  59.     std::vector<Card> allowedActions;
  60.     unsigned int NUM_ACTIONS{};
  61.     std::vector<double> regretSum;
  62.     std::vector<double> strategySum;
  63.     unsigned char phase{};
  64.  
  65.     Node();
  66.  
  67.     explicit Node(bool drawOnlyDiscardPile);
  68.  
  69.     explicit Node(const std::vector<Card>& allowedActions);
  70.  
  71.     Node(const Node& obj);
  72.  
  73.     ...    
  74.  
  75.     template<class Archive>
  76.     void serialize(Archive& ar, const unsigned int version) {
  77.         ar & allowedActions;
  78.         ar & NUM_ACTIONS;
  79.         ar & regretSum;
  80.         ar & strategySum;
  81.         ar & phase;
  82.     }
  83. };
  84.  
  85. struct Card {
  86.     int rank;
  87.     int suit;
  88.  
  89.     Card(){
  90.         this->rank = 0;
  91.         this->suit = 0;
  92.     }
  93.  
  94.     Card(int rank, int suit) {
  95.         this->rank = rank;
  96.         this->suit = suit;
  97.     }
  98.  
  99.     ...
  100.    
  101.     template<class Archive>
  102.     void serialize(Archive& ar, const unsigned int version) {
  103.         ar & rank;
  104.         ar & suit;
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement