Skip to content

Commit

Permalink
Add single_tensor support in 4 card games
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 516143728
Change-Id: Iaade156979dd8856588862593149608e978536cb
  • Loading branch information
DeepMind Technologies Ltd authored and lanctot committed Mar 13, 2023
1 parent ca2b942 commit bec9201
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions open_spiel/games/euchre.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ std::shared_ptr<const Game> Factory(const GameParameters& params) {

REGISTER_SPIEL_GAME(kGameType, Factory);

open_spiel::RegisterSingleTensorObserver single_tensor(kGameType.short_name);

std::map<Suit, Suit> same_color_suit {
{Suit::kClubs, Suit::kSpades}, {Suit::kSpades, Suit::kClubs},
{Suit::kDiamonds, Suit::kHearts}, {Suit::kHearts, Suit::kDiamonds}};
Expand Down
6 changes: 6 additions & 0 deletions open_spiel/games/euchre_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "open_spiel/observer.h"
#include "open_spiel/spiel.h"
#include "open_spiel/tests/basic_tests.h"

Expand All @@ -23,6 +24,11 @@ void BasicGameTests() {
testing::LoadGameTest("euchre");
testing::ChanceOutcomesTest(*LoadGame("euchre"));
testing::RandomSimTest(*LoadGame("euchre"), 10);

auto observer = LoadGame("euchre")
->MakeObserver(kInfoStateObsType,
GameParametersFromString("single_tensor"));
testing::RandomSimTestCustomObserver(*LoadGame("euchre"), observer);
}


Expand Down
3 changes: 3 additions & 0 deletions open_spiel/games/hanabi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ std::shared_ptr<const Game> Factory(const GameParameters& params) {

REGISTER_SPIEL_GAME(kGameType, Factory);

open_spiel::RegisterSingleTensorObserver single_tensor(kGameType.short_name);


} // namespace

std::unordered_map<std::string, std::string> OpenSpielHanabiGame::MapParams()
Expand Down
6 changes: 6 additions & 0 deletions open_spiel/games/hanabi_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "open_spiel/games/hanabi.h"

#include "open_spiel/game_parameters.h"
#include "open_spiel/observer.h"
#include "open_spiel/spiel_utils.h"
#include "open_spiel/tests/basic_tests.h"

Expand All @@ -32,6 +33,11 @@ void BasicHanabiTests() {
testing::RandomSimTest(
*LoadGame("hanabi", {{"players", GameParameter(players)}}), 100);
}

auto observer = LoadGame("hanabi")
->MakeObserver(kDefaultObsType,
GameParametersFromString("single_tensor"));
testing::RandomSimTestCustomObserver(*LoadGame("hanabi"), observer);
}

} // namespace
Expand Down
2 changes: 2 additions & 0 deletions open_spiel/games/hearts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ std::shared_ptr<const Game> Factory(const GameParameters& params) {

REGISTER_SPIEL_GAME(kGameType, Factory);

open_spiel::RegisterSingleTensorObserver single_tensor(kGameType.short_name);

} // namespace

HeartsGame::HeartsGame(const GameParameters& params)
Expand Down
5 changes: 5 additions & 0 deletions open_spiel/games/hearts_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ void BasicGameTests() {
testing::ChanceOutcomesTest(*LoadGame("hearts"));
testing::RandomSimTest(*LoadGame("hearts"), 10);
testing::ResampleInfostateTest(*LoadGame("hearts"), /*num_sims=*/10);

auto observer = LoadGame("hearts")
->MakeObserver(kInfoStateObsType,
GameParametersFromString("single_tensor"));
testing::RandomSimTestCustomObserver(*LoadGame("hearts"), observer);
}

void ShootTheMoonTest() {
Expand Down
2 changes: 2 additions & 0 deletions open_spiel/games/universal_poker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ std::shared_ptr<const Game> Factory(const GameParameters &params) {

REGISTER_SPIEL_GAME(kGameType, Factory);

open_spiel::RegisterSingleTensorObserver single_tensor(kGameType.short_name);

// Returns how many actions are available at a choice node (3 when limit
// and 4 for no limit).
// TODO(author2): Is that a bug? There are 5 actions? Is no limit means
Expand Down
5 changes: 5 additions & 0 deletions open_spiel/games/universal_poker_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ void BasicUniversalPokerTests() {
// testing::RandomSimBenchmark("universal_poker", 10000, false);

testing::CheckChanceOutcomes(*LoadGame("universal_poker"));

auto observer = LoadGame("universal_poker")
->MakeObserver(kDefaultObsType,
GameParametersFromString("single_tensor"));
testing::RandomSimTestCustomObserver(*LoadGame("universal_poker"), observer);
}

constexpr absl::string_view kHULHString =
Expand Down

0 comments on commit bec9201

Please sign in to comment.