Skip to content

Commit

Permalink
Add a check for the function which is wrapped in Python.
Browse files Browse the repository at this point in the history
Many games include that check, but not all, and I got a Segfault in Python which took me some time to understand. The only "issue", is that now, in many times, we will have the check twice, but this should not have measurable impacts.

PiperOrigin-RevId: 277051089
Change-Id: I5e1fa39916593c3120628054d2bd2a8a112c29ed
  • Loading branch information
DeepMind Technologies Ltd authored and open_spiel@google.com committed Oct 28, 2019
1 parent f703610 commit c6bb943
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions open_spiel/spiel.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,13 @@ class State {

virtual std::vector<double> ObservationAsNormalizedVector(
Player player) const {
// We add this player check, to prevent errors if the game implementation
// lacks that check (in particular as this function is the one used in
// Python). This can lead to doing this check twice.
// TODO(author2): Do we want to prevent executing this twice for games
// that implement it?
SPIEL_CHECK_GE(player, 0);
SPIEL_CHECK_LT(player, num_players_);
std::vector<double> normalized_observation;
ObservationAsNormalizedVector(player, &normalized_observation);
return normalized_observation;
Expand Down

0 comments on commit c6bb943

Please sign in to comment.