forked from andor9/tyrant_optimize
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeck.h
More file actions
139 lines (125 loc) · 4.74 KB
/
deck.h
File metadata and controls
139 lines (125 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#ifndef DECK_H_INCLUDED
#define DECK_H_INCLUDED
#include <deque>
#include <list>
#include <map>
#include <random>
#include <vector>
#include "tyrant.h"
#include "card.h"
class Cards;
//---------------------- $30 Deck: a commander + a sequence of cards -----------
// Can be shuffled.
// Implementations: random player and raid decks, ordered player decks.
//------------------------------------------------------------------------------
namespace DeckStrategy
{
enum DeckStrategy
{
random,
ordered,
exact_ordered,
num_deckstrategies
};
}
typedef void (*DeckDecoder)(const char* hash, std::vector<unsigned>& ids);
typedef void (*DeckEncoder)(std::stringstream &ios, const Card* commander, std::vector<const Card*> cards);
void hash_to_ids_wmt_b64(const char* hash, std::vector<unsigned>& ids);
void encode_deck_wmt_b64(std::stringstream &ios, const Card* commander, std::vector<const Card*> cards);
void hash_to_ids_ext_b64(const char* hash, std::vector<unsigned>& ids);
void encode_deck_ext_b64(std::stringstream &ios, const Card* commander, std::vector<const Card*> cards);
void hash_to_ids_ddd_b64(const char* hash, std::vector<unsigned>& ids);
void encode_deck_ddd_b64(std::stringstream &ios, const Card* commander, std::vector<const Card*> cards);
extern DeckDecoder hash_to_ids;
extern DeckEncoder encode_deck;
//------------------------------------------------------------------------------
// No support for ordered raid decks
class Deck
{
public:
const Cards& all_cards;
DeckType::DeckType decktype;
unsigned id;
std::string name;
Effect effect; // for quests
unsigned upgrade_chance; // probability chance/max_change to upgrade; = level - 1 for level 1 to (max_level - 1) and 0 for max_level (directly use full upgraded cards)
unsigned upgrade_max_chance;
DeckStrategy::DeckStrategy strategy;
const Card* commander;
std::vector<const Card*> cards;
std::map<signed, char> card_marks; // <positions of card, prefix mark>: -1 indicating the commander. E.g, used as a mark to be kept in attacking deck when optimizing.
std::deque<const Card*> shuffled_cards;
// card id -> card order
std::map<unsigned, std::list<unsigned>> order;
std::vector<std::pair<unsigned, std::vector<const Card*>>> raid_cards;
std::vector<const Card*> reward_cards;
unsigned mission_req;
std::string deck_string;
std::vector<unsigned> given_hand;
std::vector<const Card*> fort_cards;
Deck(
const Cards& all_cards_,
DeckType::DeckType decktype_ = DeckType::deck,
unsigned id_ = 0,
std::string name_ = "",
Effect effect_ = Effect::none,
unsigned upgrade_chance_ = 0,
unsigned upgrade_max_chance_ = 1,
DeckStrategy::DeckStrategy strategy_ = DeckStrategy::random) :
all_cards(all_cards_),
decktype(decktype_),
id(id_),
name(name_),
effect(Effect::none),
upgrade_chance(upgrade_chance_),
upgrade_max_chance(upgrade_max_chance_),
strategy(strategy_),
commander(nullptr),
mission_req(0)
{
}
~Deck() {}
void set(
const Card* commander_,
const std::vector<const Card*>& cards_,
std::vector<std::pair<unsigned, std::vector<const Card*>>> raid_cards_ = {},
std::vector<const Card*> reward_cards_ = {},
unsigned mission_req_ = 0)
{
commander = commander_;
cards = std::vector<const Card*>(std::begin(cards_), std::end(cards_));
raid_cards = std::vector<std::pair<unsigned, std::vector<const Card*>>>(raid_cards_);
reward_cards = std::vector<const Card*>(reward_cards_);
mission_req = mission_req_;
}
void set(const std::vector<unsigned>& ids, const std::map<signed, char> &marks);
void set(const std::vector<unsigned>& ids)
{
std::map<signed, char> empty;
set(ids, empty);
}
void set(const std::string& deck_string_);
void resolve();
void set_given_hand(const std::string& deck_string_);
void set_forts(const std::string& deck_string_);
Deck* clone() const;
std::string hash() const;
std::string short_description() const;
std::string medium_description() const;
std::string long_description() const;
void show_upgrades(std::stringstream &ios, const Card* card, const char * leading_chars) const;
const Card* next();
const Card* upgrade_card(const Card* card, std::mt19937& re);
const Card* get_commander(std::mt19937& re);
void shuffle(std::mt19937& re);
void place_at_bottom(const Card* card);
};
typedef std::map<std::string, long double> DeckList;
class Decks
{
public:
std::list<Deck> decks;
std::map<std::pair<DeckType::DeckType, unsigned>, Deck*> by_type_id;
std::map<std::string, Deck*> by_name;
};
#endif