Skip to content

Commit

Permalink
Addressing Raphael's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoCabannes committed Jun 8, 2021
1 parent c362c93 commit 5a291c2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
21 changes: 21 additions & 0 deletions open_spiel/games/mfg/crowd_modelling_2d.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,27 @@

namespace open_spiel {
namespace crowd_modelling_2d {

std::vector<absl::string_view> ProcessStringParam(
const std::string& string_param_str, int max_size) {
// ProcessStringParam takes a parameter string and split it is a sequence of
// substring. Example:
// "" -> {}
// "[0|0;0|1]" -> {"0|0", "0|1"}
// "[0.5;0.5]" -> {"0.5", "0.5"}
absl::string_view string_param = absl::StripAsciiWhitespace(string_param_str);
SPIEL_CHECK_TRUE(absl::ConsumePrefix(&string_param, "["));
SPIEL_CHECK_TRUE(absl::ConsumeSuffix(&string_param, "]"));

std::vector<absl::string_view> split_string_list;
if (!string_param.empty()) {
split_string_list = absl::StrSplit(string_param, ';');
}
SPIEL_CHECK_GE(split_string_list.size(), 0);
SPIEL_CHECK_LE(split_string_list.size(), max_size * max_size);
return split_string_list;
}

namespace {

// Facts about the game.
Expand Down
19 changes: 1 addition & 18 deletions open_spiel/games/mfg/crowd_modelling_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,7 @@ inline constexpr const char* kInitialDistributionValue = "[]"; // "[0.5;0.5]"
inline constexpr int kNeutralAction = 2;

std::vector<absl::string_view> ProcessStringParam(
const std::string& string_param_str, int max_size) {
// ProcessStringParam takes a parameter string and split it is a sequence of
// substring. Example:
// "" -> {}
// "[0|0;0|1]" -> {"0|0", "0|1"}
// "[0.5;0.5]" -> {"0.5", "0.5"}
absl::string_view string_param = absl::StripAsciiWhitespace(string_param_str);
SPIEL_CHECK_TRUE(absl::ConsumePrefix(&string_param, "["));
SPIEL_CHECK_TRUE(absl::ConsumeSuffix(&string_param, "]"));

std::vector<absl::string_view> split_string_list;
if (!string_param.empty()) {
split_string_list = absl::StrSplit(string_param, ';');
}
SPIEL_CHECK_GE(split_string_list.size(), 0);
SPIEL_CHECK_LE(split_string_list.size(), max_size * max_size);
return split_string_list;
}
const std::string& string_param_str, int max_size);

// Game state.
// The high-level state transitions are as follows:
Expand Down
12 changes: 6 additions & 6 deletions open_spiel/games/mfg/crowd_modelling_2d_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ void TestProcess() {
} // namespace open_spiel

int main(int argc, char** argv) {
open_spiel::crowd_modelling::TestLoad();
open_spiel::crowd_modelling::TestLoadWithParams();
open_spiel::crowd_modelling::TestLoadWithParams2();
open_spiel::crowd_modelling::TestRandomPlay();
open_spiel::crowd_modelling::TestReward();
open_spiel::crowd_modelling::TestProcess();
open_spiel::crowd_modelling_2d::TestLoad();
open_spiel::crowd_modelling_2d::TestLoadWithParams();
open_spiel::crowd_modelling_2d::TestLoadWithParams2();
open_spiel::crowd_modelling_2d::TestRandomPlay();
open_spiel::crowd_modelling_2d::TestReward();
open_spiel::crowd_modelling_2d::TestProcess();
}

0 comments on commit 5a291c2

Please sign in to comment.