fix initialization bugs
This commit is contained in:
parent
57ebc3d478
commit
c77215ed14
2 changed files with 28 additions and 6 deletions
|
@ -143,11 +143,13 @@ enum class ActionType {
|
||||||
vote_terminate = 10,
|
vote_terminate = 10,
|
||||||
};
|
};
|
||||||
|
|
||||||
class Action {
|
struct Action {
|
||||||
ActionType type {};
|
ActionType type {};
|
||||||
Card card {};
|
Card card {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, const Action& action);
|
||||||
|
|
||||||
/** Would like to have 2 versions:
|
/** Would like to have 2 versions:
|
||||||
* All:
|
* All:
|
||||||
* - support playing cards, querying basic information
|
* - support playing cards, querying basic information
|
||||||
|
@ -175,6 +177,8 @@ public:
|
||||||
virtual void init_backtracking_information() = 0;
|
virtual void init_backtracking_information() = 0;
|
||||||
virtual probability_t evaluate_state() = 0;
|
virtual probability_t evaluate_state() = 0;
|
||||||
|
|
||||||
|
virtual std::vector<std::pair<Action, std::optional<probability_t>>> get_reasonable_actions() = 0;
|
||||||
|
|
||||||
virtual ~HanabiStateIF() = default;
|
virtual ~HanabiStateIF() = default;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -209,7 +213,7 @@ public:
|
||||||
|
|
||||||
std::optional<probability_t> lookup() const;
|
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;
|
auto operator<=>(const HanabiState &) const = default;
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,23 @@ namespace Hanabi {
|
||||||
return os;
|
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++() {
|
Card &Card::operator++() {
|
||||||
rank++;
|
rank++;
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -351,7 +368,8 @@ namespace Hanabi {
|
||||||
if (nums_in_draw_pile[card] > 0) {
|
if (nums_in_draw_pile[card] > 0) {
|
||||||
_draw_pile.push_back({card, nums_in_draw_pile[card]});
|
_draw_pile.push_back({card, nums_in_draw_pile[card]});
|
||||||
if (!is_trash(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);
|
_relative_representation.good_cards_draw.push_back(card);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -521,16 +539,16 @@ namespace Hanabi {
|
||||||
const std::optional<probability_t> prob = lookup();
|
const std::optional<probability_t> prob = lookup();
|
||||||
const Action action = {ActionType::clue, unknown_card};
|
const Action action = {ActionType::clue, unknown_card};
|
||||||
reasonable_actions.emplace_back(action, prob);
|
reasonable_actions.emplace_back(action, prob);
|
||||||
const probability_t probability_stall = evaluate_state();
|
|
||||||
revert_clue();
|
revert_clue();
|
||||||
}
|
}
|
||||||
|
return reasonable_actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<suit_t num_suits, player_t num_players, hand_index_t hand_size>
|
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 {
|
std::optional<probability_t> HanabiState<num_suits, num_players, hand_size>::lookup() const {
|
||||||
const auto id = unique_id();
|
const auto id = unique_id();
|
||||||
if(_position_tablebase.contains(id)) {
|
if(_position_tablebase.contains(id)) {
|
||||||
return _position_tablebase[id];
|
return _position_tablebase.at(id);
|
||||||
} else {
|
} else {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
@ -643,7 +661,7 @@ namespace Hanabi {
|
||||||
f(1);
|
f(1);
|
||||||
revert_action();
|
revert_action();
|
||||||
} else {
|
} else {
|
||||||
unsigned sum_of_multiplicities;
|
unsigned sum_of_multiplicities = 0;
|
||||||
for(size_t i = 0; i < _draw_pile.size(); i++) {
|
for(size_t i = 0; i < _draw_pile.size(); i++) {
|
||||||
const unsigned long multiplicity = do_action();
|
const unsigned long multiplicity = do_action();
|
||||||
sum_of_multiplicities += multiplicity;
|
sum_of_multiplicities += multiplicity;
|
||||||
|
|
Loading…
Reference in a new issue