Skip to content

Commit

Permalink
Extend single_tensor observer support to kuhn and checkers
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 512621920
Change-Id: I0a1cb9b13985027b96200b75b7afb5991eb5ce08
  • Loading branch information
DeepMind Technologies Ltd authored and lanctot committed Feb 28, 2023
1 parent 1ba66f2 commit ffab068
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 2 additions & 0 deletions open_spiel/games/checkers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ std::shared_ptr<const Game> Factory(const GameParameters& params) {

REGISTER_SPIEL_GAME(kGameType, Factory);

RegisterSingleTensorObserver single_tensor(kGameType.short_name);

int StateToPlayer(CellState state) {
switch (state) {
case CellState::kWhite:
Expand Down
6 changes: 6 additions & 0 deletions open_spiel/games/checkers_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "open_spiel/games/checkers.h"

#include "open_spiel/abseil-cpp/absl/types/optional.h"
#include "open_spiel/spiel.h"
#include "open_spiel/tests/basic_tests.h"

Expand Down Expand Up @@ -65,6 +66,11 @@ void BasicCheckersTests() {
*LoadGame("checkers",
{{"rows", GameParameter(12)}, {"columns", GameParameter(12)}}),
10);

auto observer = LoadGame("checkers")
->MakeObserver(absl::nullopt,
GameParametersFromString("single_tensor"));
testing::RandomSimTestCustomObserver(*LoadGame("checkers"), observer);
}

// Board:
Expand Down
9 changes: 1 addition & 8 deletions open_spiel/games/kuhn_poker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,7 @@ std::shared_ptr<const Game> Factory(const GameParameters& params) {

REGISTER_SPIEL_GAME(kGameType, Factory);

std::shared_ptr<Observer> MakeSingleTensorObserver(
const Game& game, absl::optional<IIGObservationType> iig_obs_type,
const GameParameters& params) {
return std::shared_ptr<Observer>(game.MakeBuiltInObserver(iig_obs_type));
}

ObserverRegisterer single_tensor(
kGameType.short_name, "single_tensor", MakeSingleTensorObserver);
open_spiel::RegisterSingleTensorObserver single_tensor(kGameType.short_name);
} // namespace

class KuhnObserver : public Observer {
Expand Down
1 change: 1 addition & 0 deletions open_spiel/games/kuhn_poker_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ void BasicKuhnTests() {
auto observer = LoadGame("kuhn_poker")
->MakeObserver(kDefaultObsType,
GameParametersFromString("single_tensor"));
testing::RandomSimTestCustomObserver(*LoadGame("kuhn_poker"), observer);
}

void CountStates() {
Expand Down

0 comments on commit ffab068

Please sign in to comment.