code cleanup
This commit is contained in:
parent
daa19e408f
commit
5ab7538506
1 changed files with 0 additions and 37 deletions
|
@ -337,7 +337,6 @@ namespace Hanabi {
|
||||||
|
|
||||||
template<std::size_t num_suits, player_t num_players, std::size_t hand_size>
|
template<std::size_t num_suits, player_t num_players, std::size_t hand_size>
|
||||||
double HanabiState<num_suits, num_players, hand_size>::backtrack(size_t depth) {
|
double HanabiState<num_suits, num_players, hand_size>::backtrack(size_t depth) {
|
||||||
// std::cout << *this << std::endl;
|
|
||||||
if (_score == 5 * num_suits) {
|
if (_score == 5 * num_suits) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -354,32 +353,20 @@ namespace Hanabi {
|
||||||
// First, check for playables
|
// First, check for playables
|
||||||
for(std::uint8_t index = 0; index < hand_size; index++) {
|
for(std::uint8_t index = 0; index < hand_size; index++) {
|
||||||
if(is_playable(hand[index])) {
|
if(is_playable(hand[index])) {
|
||||||
// std::cout << std::string("---------------------", depth) << "playing " << hand[index] << std::endl;
|
|
||||||
if (_draw_pile.empty()) {
|
if (_draw_pile.empty()) {
|
||||||
auto copy = *this;
|
auto copy = *this;
|
||||||
BacktrackAction action = play(index);
|
BacktrackAction action = play(index);
|
||||||
const double probability_for_this_play = backtrack(depth + 1);
|
const double probability_for_this_play = backtrack(depth + 1);
|
||||||
revert(action);
|
revert(action);
|
||||||
if (!same_up_to_discard_permutation(*this, copy)) {
|
|
||||||
std::cout << "detected faulty backtrack" << std::endl;
|
|
||||||
std::cout << *this << std::endl;
|
|
||||||
std::cout << copy << std::endl;
|
|
||||||
ASSERT(this->_hands == copy._hands);
|
|
||||||
ASSERT(this->_draw_pile == copy._draw_pile);
|
|
||||||
ASSERT(this->_endgame_turns_left == copy._endgame_turns_left);
|
|
||||||
ASSERT(false);
|
|
||||||
}
|
|
||||||
UPDATE_PROBABILITY(probability_for_this_play);
|
UPDATE_PROBABILITY(probability_for_this_play);
|
||||||
} else {
|
} else {
|
||||||
double sum_of_probabilities = 0;
|
double sum_of_probabilities = 0;
|
||||||
uint8_t sum_of_mults = 0;
|
uint8_t sum_of_mults = 0;
|
||||||
for (size_t i = 0; i < _draw_pile.size(); i++) {
|
for (size_t i = 0; i < _draw_pile.size(); i++) {
|
||||||
auto copy = *this;
|
|
||||||
BacktrackAction action = play(index);
|
BacktrackAction action = play(index);
|
||||||
sum_of_probabilities += backtrack(depth + 1) * action.multiplicity;
|
sum_of_probabilities += backtrack(depth + 1) * action.multiplicity;
|
||||||
sum_of_mults += action.multiplicity;
|
sum_of_mults += action.multiplicity;
|
||||||
revert(action);
|
revert(action);
|
||||||
ASSERT(same_up_to_discard_permutation(*this, copy));
|
|
||||||
ASSERT(sum_of_mults <= _weighted_draw_pile_size);
|
ASSERT(sum_of_mults <= _weighted_draw_pile_size);
|
||||||
}
|
}
|
||||||
ASSERT(sum_of_mults == _weighted_draw_pile_size);
|
ASSERT(sum_of_mults == _weighted_draw_pile_size);
|
||||||
|
@ -393,40 +380,19 @@ namespace Hanabi {
|
||||||
if(_pace > 0) {
|
if(_pace > 0) {
|
||||||
for(std::uint8_t index = 0; index < hand_size; index++) {
|
for(std::uint8_t index = 0; index < hand_size; index++) {
|
||||||
if (is_trash(hand[index])) {
|
if (is_trash(hand[index])) {
|
||||||
// std::cout << std::string("---------------------------", depth) << "discarding " << hand[index] << std::endl;
|
|
||||||
double sum_of_probabilities = 0;
|
double sum_of_probabilities = 0;
|
||||||
if (_draw_pile.empty()) {
|
if (_draw_pile.empty()) {
|
||||||
auto copy = *this;
|
|
||||||
BacktrackAction action = discard(index);
|
BacktrackAction action = discard(index);
|
||||||
const double probability_for_this_discard = backtrack(depth + 1);
|
const double probability_for_this_discard = backtrack(depth + 1);
|
||||||
revert(action);
|
revert(action);
|
||||||
if (!same_up_to_discard_permutation(*this, copy)) {
|
|
||||||
std::cout << "detected faulty backtrack" << std::endl;
|
|
||||||
std::cout << *this << std::endl;
|
|
||||||
std::cout << copy << std::endl;
|
|
||||||
ASSERT(this->_hands == copy._hands);
|
|
||||||
ASSERT(this->_draw_pile == copy._draw_pile);
|
|
||||||
ASSERT(this->_endgame_turns_left == copy._endgame_turns_left);
|
|
||||||
ASSERT(false);
|
|
||||||
}
|
|
||||||
UPDATE_PROBABILITY(probability_for_this_discard);
|
UPDATE_PROBABILITY(probability_for_this_discard);
|
||||||
} else {
|
} else {
|
||||||
uint8_t sum_of_mults = 0;
|
uint8_t sum_of_mults = 0;
|
||||||
for (size_t i = 0; i < _draw_pile.size(); i++) {
|
for (size_t i = 0; i < _draw_pile.size(); i++) {
|
||||||
auto copy = *this;
|
|
||||||
BacktrackAction action = discard(index);
|
BacktrackAction action = discard(index);
|
||||||
sum_of_probabilities += backtrack(depth + 1) * action.multiplicity;
|
sum_of_probabilities += backtrack(depth + 1) * action.multiplicity;
|
||||||
sum_of_mults += action.multiplicity;
|
sum_of_mults += action.multiplicity;
|
||||||
revert(action);
|
revert(action);
|
||||||
if (!same_up_to_discard_permutation(*this, copy)) {
|
|
||||||
std::cout << "detected faulty backtrack" << std::endl;
|
|
||||||
std::cout << *this << std::endl;
|
|
||||||
std::cout << copy << std::endl;
|
|
||||||
ASSERT(this->_hands == copy._hands);
|
|
||||||
ASSERT(this->_draw_pile == copy._draw_pile);
|
|
||||||
ASSERT(this->_endgame_turns_left == copy._endgame_turns_left);
|
|
||||||
ASSERT(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ASSERT(sum_of_mults == _weighted_draw_pile_size);
|
ASSERT(sum_of_mults == _weighted_draw_pile_size);
|
||||||
const double probability_discard = sum_of_probabilities / _weighted_draw_pile_size;
|
const double probability_discard = sum_of_probabilities / _weighted_draw_pile_size;
|
||||||
|
@ -441,12 +407,9 @@ namespace Hanabi {
|
||||||
|
|
||||||
// Last option is to stall
|
// Last option is to stall
|
||||||
if(_num_clues > 0) {
|
if(_num_clues > 0) {
|
||||||
// std::cout << std::string("--------------------", depth) << "stalling " << std::endl;
|
|
||||||
auto copy = *this;
|
|
||||||
BacktrackAction action = clue();
|
BacktrackAction action = clue();
|
||||||
const double probability_stall = backtrack(depth + 1);
|
const double probability_stall = backtrack(depth + 1);
|
||||||
revert(action);
|
revert(action);
|
||||||
ASSERT(same_up_to_discard_permutation(*this, copy));
|
|
||||||
UPDATE_PROBABILITY(probability_stall);
|
UPDATE_PROBABILITY(probability_stall);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue