Skip to content

Commit

Permalink
Add checks in simulation test that ensure rewards and returns vectors…
Browse files Browse the repository at this point in the history
… have size equal to the number of players.

PiperOrigin-RevId: 272283762
Change-Id: I8aff35e4f8093fbd15619392ce35c38c296b1fa0
  • Loading branch information
DeepMind Technologies Ltd authored and open_spiel@google.com committed Oct 3, 2019
1 parent 91ff14b commit e0f6cb5
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions open_spiel/tests/basic_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ void RandomSimulation(std::mt19937* rng, const Game& game, bool undo) {
}
} else if (state->CurrentPlayer() == open_spiel::kSimultaneousPlayerId) {
std::vector<double> rewards = state->Rewards();
SPIEL_CHECK_EQ(rewards.size(), game.NumPlayers());
std::cout << "Rewards: " << absl::StrJoin(rewards, " ") << std::endl;
for (auto p = Player{0}; p < game.NumPlayers(); ++p) {
episode_returns[p] += rewards[p];
Expand Down Expand Up @@ -370,6 +371,7 @@ void RandomSimulation(std::mt19937* rng, const Game& game, bool undo) {
game_length++;
} else {
std::vector<double> rewards = state->Rewards();
SPIEL_CHECK_EQ(rewards.size(), game.NumPlayers());
std::cout << "Rewards: " << absl::StrJoin(rewards, " ") << std::endl;
for (auto p = Player{0}; p < game.NumPlayers(); ++p) {
episode_returns[p] += rewards[p];
Expand Down Expand Up @@ -432,6 +434,7 @@ void RandomSimulation(std::mt19937* rng, const Game& game, bool undo) {
}

auto returns = state->Returns();
SPIEL_CHECK_EQ(returns.size(), game.NumPlayers());
for (Player player = 0; player < game.NumPlayers(); player++) {
double final_return = returns[player];
SPIEL_CHECK_FLOAT_EQ(final_return, state->PlayerReturn(player));
Expand Down

0 comments on commit e0f6cb5

Please sign in to comment.