fix initialization bugs

This commit is contained in:
Maximilian Keßler 2023-08-11 16:54:11 +02:00
parent 57ebc3d478
commit c77215ed14
Signed by: max
GPG key ID: BCC5A619923C0BA5
2 changed files with 28 additions and 6 deletions

View file

@ -143,11 +143,13 @@ enum class ActionType {
vote_terminate = 10,
};
class Action {
struct Action {
ActionType type {};
Card card {};
};
std::ostream& operator<<(std::ostream& os, const Action& action);
/** Would like to have 2 versions:
* All:
* - support playing cards, querying basic information
@ -175,6 +177,8 @@ public:
virtual void init_backtracking_information() = 0;
virtual probability_t evaluate_state() = 0;
virtual std::vector<std::pair<Action, std::optional<probability_t>>> get_reasonable_actions() = 0;
virtual ~HanabiStateIF() = default;
protected:
@ -209,7 +213,7 @@ public:
std::optional<probability_t> lookup() const;
std::vector<std::pair<Action, std::optional<probability_t>>> get_reasonable_actions();
std::vector<std::pair<Action, std::optional<probability_t>>> get_reasonable_actions() final;
auto operator<=>(const HanabiState &) const = default;

View file

@ -12,6 +12,23 @@ namespace Hanabi {
return os;
}
std::ostream &operator<<(std::ostream &os, Action const& action) {
switch(action.type) {
case ActionType::play:
os << "play " << action.card;
break;
case ActionType::discard:
os << "discard";
break;
case ActionType::clue:
os << "clue";
break;
default:
break;
}
return os;
}
Card &Card::operator++() {
rank++;
return *this;
@ -351,7 +368,8 @@ namespace Hanabi {
if (nums_in_draw_pile[card] > 0) {
_draw_pile.push_back({card, nums_in_draw_pile[card]});
if (!is_trash(card)) {
_relative_representation.card_positions_draw.push_back({nums_in_draw_pile[card], draw_pile});
_relative_representation.card_positions_draw.push_back({});
_relative_representation.card_positions_draw.back().resize(nums_in_draw_pile[card], draw_pile);
_relative_representation.good_cards_draw.push_back(card);
}
}
@ -521,16 +539,16 @@ namespace Hanabi {
const std::optional<probability_t> prob = lookup();
const Action action = {ActionType::clue, unknown_card};
reasonable_actions.emplace_back(action, prob);
const probability_t probability_stall = evaluate_state();
revert_clue();
}
return reasonable_actions;
}
template<suit_t num_suits, player_t num_players, hand_index_t hand_size>
std::optional<probability_t> HanabiState<num_suits, num_players, hand_size>::lookup() const {
const auto id = unique_id();
if(_position_tablebase.contains(id)) {
return _position_tablebase[id];
return _position_tablebase.at(id);
} else {
return std::nullopt;
}
@ -643,7 +661,7 @@ namespace Hanabi {
f(1);
revert_action();
} else {
unsigned sum_of_multiplicities;
unsigned sum_of_multiplicities = 0;
for(size_t i = 0; i < _draw_pile.size(); i++) {
const unsigned long multiplicity = do_action();
sum_of_multiplicities += multiplicity;