diff --git a/open_spiel/games/CMakeLists.txt b/open_spiel/games/CMakeLists.txt index 6af3133c2c..36438f533f 100644 --- a/open_spiel/games/CMakeLists.txt +++ b/open_spiel/games/CMakeLists.txt @@ -206,10 +206,6 @@ if (${OPEN_SPIEL_BUILD_WITH_GAMUT}) add_subdirectory(gamut) endif() - -# Uncomment to build the Ludii demo -# add_subdirectory (ludii) - add_library(bridge_double_dummy_solver OBJECT bridge/double_dummy_solver/include/dll.h bridge/double_dummy_solver/include/portab.h diff --git a/open_spiel/games/ludii/CMakeLists.txt b/open_spiel/games/ludii/CMakeLists.txt deleted file mode 100644 index e1a501e776..0000000000 --- a/open_spiel/games/ludii/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -set (JDK_HOME /usr/lib/jvm/java-8-openjdk-amd64) - -add_library (ludii OBJECT - chunk_set.h - chunk_set.cc - container_state.h - container_state.cc - context.h - context.cc - game.h - game.cc - game_loader.h - game_loader.cc - jni_utils.h - jni_utils.cc - mode.h - mode.cc - move.h - move.cc - moves.h - moves.cc - region.h - region.cc - state.h - state.cc - trial.h - trial.cc -) -target_include_directories (ludii PUBLIC ${JDK_HOME}/include/linux ${JDK_HOME}/include) -target_link_directories (ludii PUBLIC ${JDK_HOME}/jre/lib/amd64/server) -target_link_libraries (ludii jvm) - -add_executable(ludii_demo ludii_demo.cc $) -target_include_directories (ludii_demo PUBLIC ${JDK_HOME}/include/linux ${JDK_HOME}/include) -target_link_directories (ludii_demo PUBLIC ${JDK_HOME}/jre/lib/amd64/server) -target_link_libraries (ludii_demo jvm) diff --git a/open_spiel/games/ludii/README.md b/open_spiel/games/ludii/README.md deleted file mode 100644 index 4e0360d2f3..0000000000 --- a/open_spiel/games/ludii/README.md +++ /dev/null @@ -1,32 +0,0 @@ -# Ludii Wrapper - -This is an experimental work-in-progress C++ wrapper of the -[Ludii General Game System](https://ludii.games/). The Ludii library is written -in Java so this wrapper uses -[JNI](https://docs.oracle.com/javase/8/docs/technotes/guides/jni/) to interact -with the Ludii jar through C++. - -For discussion on the development of this wrapper, please see -[issue #39](https://github.com/deepmind/open_spiel/issues/39). - -## How to build - -Tested on Ubuntu 16.04 with Java 8 openJDK and Ludii player (0.3.0). - -1. Install openjdk if you haven't already. - -2. Download Ludii player (0.3.0) jar from - [downloads page](https://ludii.games/downloads.php). - -3. Check `games/ludii/CMakeLists`. Assuming Java 8 openJDK is installed the - JDK_HOME is set to `/usr/lib/jvm/java-8-openjdk-amd64`. This might have to - be changed if a different version is installed. - -4. Uncomment the `add_subdirectory (ludii)` line in `games/CMakeLists.txt` - -5. Build OpenSpiel as usual, then run `build/games/ludii/ludii_demo ` - -If `libjvm.so` is not found, run: - -`export LD_LIBRARY_PATH=/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/` diff --git a/open_spiel/games/ludii/chunk_set.cc b/open_spiel/games/ludii/chunk_set.cc deleted file mode 100644 index 2f4adb02ab..0000000000 --- a/open_spiel/games/ludii/chunk_set.cc +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2019 DeepMind Technologies Limited -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "open_spiel/games/ludii/chunk_set.h" - -namespace open_spiel { -namespace ludii { - -ChunkSet::ChunkSet(JNIEnv *env, jobject chunkset) - : env(env), chunkset(chunkset) {} - -std::string ChunkSet::Print() const { - jclass chunkSetClass = env->FindClass("util/ChunkSet"); - jmethodID tostring_id = - env->GetMethodID(chunkSetClass, "toString", "()Ljava/lang/String;"); - jstring string_obj = (jstring)env->CallObjectMethod(chunkset, tostring_id); - - const char *rawString = env->GetStringUTFChars(string_obj, 0); - std::string cppString(rawString); - env->ReleaseStringUTFChars(string_obj, rawString); - - return cppString; -} - -std::string ChunkSet::ToChunkString() const { - jclass chunkSetClass = env->FindClass("util/ChunkSet"); - jmethodID toChunkString_id = - env->GetMethodID(chunkSetClass, "toChunkString", "()Ljava/lang/String;"); - jstring string_obj = - (jstring)env->CallObjectMethod(chunkset, toChunkString_id); - - const char *rawString = env->GetStringUTFChars(string_obj, 0); - std::string cppString(rawString); - env->ReleaseStringUTFChars(string_obj, rawString); - - return cppString; -} - -} // namespace ludii -} // namespace open_spiel diff --git a/open_spiel/games/ludii/chunk_set.h b/open_spiel/games/ludii/chunk_set.h deleted file mode 100644 index 040082cca5..0000000000 --- a/open_spiel/games/ludii/chunk_set.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2019 DeepMind Technologies Limited -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef OPEN_SPIEL_GAMES_LUDII_CHUNKSET_H_ -#define OPEN_SPIEL_GAMES_LUDII_CHUNKSET_H_ - -#include - -#include "jni.h" // NOLINT - -namespace open_spiel { -namespace ludii { - -class ChunkSet { - public: - ChunkSet(JNIEnv *env, jobject chunkset); - - std::string Print() const; - - std::string ToChunkString() const; - - private: - JNIEnv *env; - jobject chunkset; -}; - -} // namespace ludii -} // namespace open_spiel - -#endif // OPEN_SPIEL_GAMES_LUDII_CHUNKSET_H_ diff --git a/open_spiel/games/ludii/container_state.cc b/open_spiel/games/ludii/container_state.cc deleted file mode 100644 index 5026c15969..0000000000 --- a/open_spiel/games/ludii/container_state.cc +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2019 DeepMind Technologies Limited -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "open_spiel/games/ludii/container_state.h" - -namespace open_spiel { -namespace ludii { - -ContainerState::ContainerState(JNIEnv *env, jobject container_state) - : env(env), container_state(container_state) {} - -Region ContainerState::Empty() const { - jclass ContainerStateClass = - env->FindClass("util/state/containerState/ContainerState"); - jmethodID empty_id = - env->GetMethodID(ContainerStateClass, "empty", "()Lutil/Region;"); - jobject region_obj = env->CallObjectMethod(container_state, empty_id); - - return Region(env, region_obj); -} - -ChunkSet ContainerState::CloneWho() const { - jclass ContainerStateClass = - env->FindClass("util/state/containerState/ContainerState"); - jmethodID cloneWho_id = - env->GetMethodID(ContainerStateClass, "cloneWho", "()Lutil/ChunkSet;"); - jobject chunkset_obj = env->CallObjectMethod(container_state, cloneWho_id); - - return ChunkSet(env, chunkset_obj); -} - -ChunkSet ContainerState::CloneWhat() const { - jclass ContainerStateClass = - env->FindClass("util/state/containerState/ContainerState"); - jmethodID cloneWhat_id = - env->GetMethodID(ContainerStateClass, "cloneWhat", "()Lutil/ChunkSet;"); - jobject chunkset_obj = env->CallObjectMethod(container_state, cloneWhat_id); - - return ChunkSet(env, chunkset_obj); -} - -} // namespace ludii -} // namespace open_spiel diff --git a/open_spiel/games/ludii/container_state.h b/open_spiel/games/ludii/container_state.h deleted file mode 100644 index 3947804b87..0000000000 --- a/open_spiel/games/ludii/container_state.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2019 DeepMind Technologies Limited -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef OPEN_SPIEL_GAMES_LUDII_CONTAINER_STATE_H_ -#define OPEN_SPIEL_GAMES_LUDII_CONTAINER_STATE_H_ - -#include "jni.h" // NOLINT -#include "open_spiel/games/ludii/chunk_set.h" -#include "open_spiel/games/ludii/region.h" - -namespace open_spiel { -namespace ludii { - -class ContainerState { - public: - ContainerState(JNIEnv *env, jobject container_state); - - Region Empty() const; - - ChunkSet CloneWho() const; - - ChunkSet CloneWhat() const; - - private: - JNIEnv *env; - jobject container_state; -}; - -} // namespace ludii -} // namespace open_spiel - -#endif // OPEN_SPIEL_GAMES_LUDII_CONTAINER_STATE_H_ diff --git a/open_spiel/games/ludii/context.cc b/open_spiel/games/ludii/context.cc deleted file mode 100644 index 61238e4b80..0000000000 --- a/open_spiel/games/ludii/context.cc +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2019 DeepMind Technologies Limited -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "open_spiel/games/ludii/context.h" - -#include "open_spiel/games/ludii/game.h" - -namespace open_spiel { -namespace ludii { - -Context::Context(JNIEnv *env, Game game, Trial trial) : env(env) { - jclass context_class = env->FindClass("util/Context"); - jmethodID context_const_id = - env->GetMethodID(context_class, "", "(Lgame/Game;Lutil/Trial;)V"); - jobject context_obj = env->NewObject(context_class, context_const_id, - game.GetObj(), trial.GetObj()); - - context = context_obj; -} - -jobject Context::GetObj() const { return context; } - -} // namespace ludii -} // namespace open_spiel diff --git a/open_spiel/games/ludii/context.h b/open_spiel/games/ludii/context.h deleted file mode 100644 index c2aa0cacbe..0000000000 --- a/open_spiel/games/ludii/context.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2019 DeepMind Technologies Limited -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef OPEN_SPIEL_GAMES_LUDII_CONTAINER_STATE_CONTEXT_H_ -#define OPEN_SPIEL_GAMES_LUDII_CONTAINER_STATE_CONTEXT_H_ - -#include "open_spiel/games/ludii/trial.h" - -namespace open_spiel { -namespace ludii { - -class Game; - -class Context { - public: - Context(JNIEnv *env, Game game, Trial trial); - - jobject GetObj() const; - - private: - JNIEnv *env; - jobject context; -}; - -} // namespace ludii -} // namespace open_spiel - -#endif // OPEN_SPIEL_GAMES_LUDII_CONTAINER_STATE_CONTEXT_H_ diff --git a/open_spiel/games/ludii/game.cc b/open_spiel/games/ludii/game.cc deleted file mode 100644 index 7eb1e78001..0000000000 --- a/open_spiel/games/ludii/game.cc +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2019 DeepMind Technologies Limited -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "open_spiel/games/ludii/game.h" - -#include "open_spiel/games/ludii/context.h" - -namespace open_spiel { -namespace ludii { - -Game::Game(JNIEnv *env, jobject game, std::string game_path) - : env(env), game(game), game_path(game_path) {} - -std::string Game::GetPath() const { return game_path; } - -jobject Game::GetObj() const { return game; } - -std::string Game::GetName() const { - jclass gameClass = env->FindClass("game/Game"); - jmethodID name_id = - env->GetMethodID(gameClass, "name", "()Ljava/lang/String;"); - jstring stringArray = (jstring)env->CallObjectMethod(game, name_id); - - // convert jstring game name to char array - const char *strReturn = env->GetStringUTFChars(stringArray, 0); - std::string string_name(strReturn); - env->ReleaseStringUTFChars(stringArray, strReturn); - - return string_name; -} - -void Game::Create(int viewSize) const { - jclass gameClass = env->FindClass("game/Game"); - jmethodID create_id = env->GetMethodID(gameClass, "create", "(I)V"); - env->CallVoidMethod(game, create_id, viewSize); -} - -int Game::StateFlags() const { - jclass gameClass = env->FindClass("game/Game"); - jmethodID stateFlags_id = env->GetMethodID(gameClass, "stateFlags", "()I"); - return (int)env->CallIntMethod(game, stateFlags_id); -} - -Mode Game::GetMode() const { - jclass gameClass = env->FindClass("game/Game"); - jmethodID mode_id = env->GetMethodID(gameClass, "mode", "()Lgame/mode/Mode;"); - jobject mode = env->CallObjectMethod(game, mode_id); - return Mode(env, mode); -} - -void Game::Start(Context context) const { - jclass gameClass = env->FindClass("game/Game"); - jmethodID start_id = - env->GetMethodID(gameClass, "start", "(Lutil/Context;)V"); - env->CallVoidMethod(game, start_id, context.GetObj()); -} - -Moves Game::GetMoves(Context context) const { - jclass gameClass = env->FindClass("game/Game"); - jmethodID moves_id = env->GetMethodID( - gameClass, "moves", "(Lutil/Context;)Lgame/rules/play/moves/Moves;"); - jobject moves_obj = env->CallObjectMethod(game, moves_id, context.GetObj()); - jclass clsObj = env->GetObjectClass(context.GetObj()); - - return Moves(env, moves_obj); -} - -Move Game::Apply(Context context, Move move) const { - jclass gameClass = env->FindClass("game/Game"); - jmethodID apply_id = env->GetMethodID( - gameClass, "apply", "(Lutil/Context;Lutil/Move;)Lutil/Move;"); - jobject move_obj = - env->CallObjectMethod(game, apply_id, context.GetObj(), move.GetObj()); - - return Move(env, move_obj); -} - -} // namespace ludii -} // namespace open_spiel diff --git a/open_spiel/games/ludii/game.h b/open_spiel/games/ludii/game.h deleted file mode 100644 index 159e98d68d..0000000000 --- a/open_spiel/games/ludii/game.h +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2019 DeepMind Technologies Limited -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef OPEN_SPIEL_GAMES_LUDII_GAME_H_ -#define OPEN_SPIEL_GAMES_LUDII_GAME_H_ - -#include - -#include "jni.h" // NOLINT -#include "open_spiel/games/ludii/mode.h" -#include "open_spiel/games/ludii/move.h" -#include "open_spiel/games/ludii/moves.h" - -namespace open_spiel { -namespace ludii { - -class Context; - -class Game { - public: - Game(JNIEnv *env, jobject game, std::string game_path); - - std::string GetPath() const; - - jobject GetObj() const; - - void Create(int viewSize) const; - - std::string GetName() const; - - int StateFlags() const; - - Mode GetMode() const; - - void Start(Context context) const; - - Moves GetMoves(Context context) const; - - Move Apply(Context context, Move move) const; - - private: - JNIEnv *env; - jobject game; - std::string game_path; -}; - -} // namespace ludii -} // namespace open_spiel - -#endif // OPEN_SPIEL_GAMES_LUDII_ diff --git a/open_spiel/games/ludii/game_loader.cc b/open_spiel/games/ludii/game_loader.cc deleted file mode 100644 index 43af7209cd..0000000000 --- a/open_spiel/games/ludii/game_loader.cc +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2019 DeepMind Technologies Limited -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "open_spiel/games/ludii/game_loader.h" - -#include -#include - -namespace open_spiel { -namespace ludii { - -GameLoader::GameLoader(JNIEnv *env) : env(env) {} - -std::vector GameLoader::ListGames() const { - std::vector gamesVector; - - jclass gameLoader = env->FindClass("player/GameLoader"); - jmethodID mid = - env->GetStaticMethodID(gameLoader, "listGames", "()[Ljava/lang/String;"); - jobjectArray stringArray = - (jobjectArray)env->CallStaticObjectMethod(gameLoader, mid); - - int stringCount = env->GetArrayLength(stringArray); - - for (int i = 0; i < stringCount; i++) { - // get array element and convert it from jstring - jstring string = (jstring)(env->GetObjectArrayElement(stringArray, i)); - const char *rawString = env->GetStringUTFChars(string, 0); - - std::string cppString(rawString); - gamesVector.push_back(cppString); - - env->ReleaseStringUTFChars(string, rawString); - } - - return gamesVector; -} - -Game GameLoader::LoadGame(std::string game_name) const { - jclass gameLoader = env->FindClass("player/GameLoader"); - jmethodID mid = env->GetStaticMethodID(gameLoader, "loadGameFromName", - "(Ljava/lang/String;)Lgame/Game;"); - - // convert game name to java string - jstring j_game_name = env->NewStringUTF(game_name.c_str()); - jobject game_obj = env->CallStaticObjectMethod(gameLoader, mid, j_game_name); - - return Game(env, game_obj, game_name); -} - -} // namespace ludii -} // namespace open_spiel diff --git a/open_spiel/games/ludii/game_loader.h b/open_spiel/games/ludii/game_loader.h deleted file mode 100644 index 8bd2214180..0000000000 --- a/open_spiel/games/ludii/game_loader.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2019 DeepMind Technologies Limited -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef OPEN_SPIEL_GAMES_LUDII_LUDII_H_ -#define OPEN_SPIEL_GAMES_LUDII_LUDII_H_ - -#include -#include - -#include "jni.h" // NOLINT -#include "open_spiel/games/ludii/game.h" - -namespace open_spiel { -namespace ludii { - -class GameLoader { - public: - GameLoader(JNIEnv *env_const); - std::vector ListGames() const; - Game LoadGame(std::string game_name) const; - - private: - JNIEnv *env; -}; - -} // namespace ludii -} // namespace open_spiel - -#endif // OPEN_SPIEL_GAMES_LUDII_LUDII_H_ diff --git a/open_spiel/games/ludii/jni_utils.cc b/open_spiel/games/ludii/jni_utils.cc deleted file mode 100644 index 04ea5d1faa..0000000000 --- a/open_spiel/games/ludii/jni_utils.cc +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2019 DeepMind Technologies Limited -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "open_spiel/games/ludii/jni_utils.h" - -#include -#include -#include - -namespace open_spiel { -namespace ludii { - -JNIUtils::JNIUtils(std::string jar_location) { InitJVM(jar_location); } - -JNIUtils::~JNIUtils() { CloseJVM(); } - -JNIEnv *JNIUtils::GetEnv() const { return env; } - -void JNIUtils::InitJVM(std::string jar_location) { - std::cout << "intializing JVM" << std::endl; -#ifdef JNI_VERSION_1_2 - JavaVMInitArgs vm_args; - JavaVMOption options[1]; - std::string java_classpath = "-Djava.class.path=" + jar_location; - char *c_classpath = strdup(java_classpath.c_str()); - options[0].optionString = c_classpath; - vm_args.version = 0x00010002; - vm_args.options = options; - vm_args.nOptions = 1; - vm_args.ignoreUnrecognized = JNI_TRUE; - /* Create the Java VM */ - res = JNI_CreateJavaVM(&jvm, (void **)&env, &vm_args); - free(c_classpath); -#else - JDK1_1InitArgs vm_args; - std::string classpath = vm_args.classpath + ";" + jar_location; - char* c_classpath = strdup(java_classpath.c_str()); - vm_args.version = 0x00010001; - JNI_GetDefaultJavaVMInitArgs(&vm_args); - /* Append jar location to the default system class path */ - vm_args.classpath = c_classpath; - /* Create the Java VM */ - res = JNI_CreateJavaVM(&jvm, &env, &vm_args); - free(c_classpath); -#endif /* JNI_VERSION_1_2 */ -} - -void JNIUtils::CloseJVM() { - std::cout << "destroying JVM" << std::endl; - jvm->DestroyJavaVM(); -} - -} // namespace ludii -} // namespace open_spiel diff --git a/open_spiel/games/ludii/jni_utils.h b/open_spiel/games/ludii/jni_utils.h deleted file mode 100644 index 6ee02fef39..0000000000 --- a/open_spiel/games/ludii/jni_utils.h +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2019 DeepMind Technologies Limited -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef OPEN_SPIEL_GAMES_LUDII_JNIUTILS_H_ -#define OPEN_SPIEL_GAMES_LUDII_JNIUTILS_H_ - -#include -#include - -#include "jni.h" // NOLINT - -namespace open_spiel { -namespace ludii { - -class JNIUtils { - public: - JNIUtils(const std::string jar_location); - ~JNIUtils(); - - JNIEnv *GetEnv() const; - - void InitJVM(std::string jar_location); - void CloseJVM(); - - private: - JavaVM *jvm; - JNIEnv *env; - jint res; -}; - -} // namespace ludii -} // namespace open_spiel - -#endif // OPEN_SPIEL_GAMES_LUDII_JNIUTILS_H_ diff --git a/open_spiel/games/ludii/ludii_demo.cc b/open_spiel/games/ludii/ludii_demo.cc deleted file mode 100644 index 9761ed107b..0000000000 --- a/open_spiel/games/ludii/ludii_demo.cc +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright 2019 DeepMind Technologies Limited -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include -#include -#include - -#include "open_spiel/games/ludii/chunk_set.h" -#include "open_spiel/games/ludii/container_state.h" -#include "open_spiel/games/ludii/context.h" -#include "open_spiel/games/ludii/game.h" -#include "open_spiel/games/ludii/game_loader.h" -#include "open_spiel/games/ludii/jni_utils.h" -#include "open_spiel/games/ludii/move.h" -#include "open_spiel/games/ludii/moves.h" -#include "open_spiel/games/ludii/region.h" -#include "open_spiel/games/ludii/state.h" -#include "open_spiel/games/ludii/trial.h" - -namespace ludii = open_spiel::ludii; - -int main(int argc, char** argv) { - if (argc < 2) { - std::cout << "Usage: ludii_demo " << std::endl; - exit(-1); - } - - // launch JVM with the Ludii jar on the classpath - std::cout << "Loading jar: " << argv[1] << std::endl; - ludii::JNIUtils test_utils = ludii::JNIUtils(argv[1]); - - // Get JNI environment variable - JNIEnv* env = test_utils.GetEnv(); - - // Ludii GameLoader object - ludii::GameLoader gameLoader = ludii::GameLoader(env); - - // List Ludii games - std::vector game_names = gameLoader.ListGames(); - - std::cout << "listing games" << std::endl; - for (std::vector::const_iterator i = game_names.begin(); - i != game_names.end(); ++i) - std::cout << *i << ' ' << std::endl; - - // Load a Ludii game - ludii::Game test_game = - gameLoader.LoadGame("board/space/blocking/Amazons.lud"); - - // Test some Ludii API calls - test_game.Create(0); - - int stateFlgs = test_game.StateFlags(); - std::cout << "state flags: " << stateFlgs << std::endl; - - ludii::Mode m = test_game.GetMode(); - - int numPlys = m.NumPlayers(); - std::cout << "number of players: " << numPlys << std::endl; - - ludii::Trial t = ludii::Trial(env, test_game); - - ludii::Context c = ludii::Context(env, test_game, t); - - test_game.Start(c); - - ludii::State s = t.GetState(); - - std::vector c_states = s.ContainerStates(); - - bool is_ov = t.Over(); - - int mo = s.Mover(); - - ludii::ContainerState cs = c_states[0]; - - ludii::Region r = cs.Empty(); - - ludii::ChunkSet chunks = r.BitSet(); - - std::cout << "chunk set: " << chunks.Print() << std::endl; - - ludii::ChunkSet chunks2 = cs.CloneWho(); - - ludii::ChunkSet chunks3 = cs.CloneWhat(); - - ludii::Moves ms = test_game.GetMoves(c); - - // get the moves for the game - std::vector mv = ms.GetMoves(); - - // apply a move to the game - ludii::Move move_after_apply = test_game.Apply(c, mv[0]); - - return 1; -} diff --git a/open_spiel/games/ludii/mode.cc b/open_spiel/games/ludii/mode.cc deleted file mode 100644 index 4c72d8dd68..0000000000 --- a/open_spiel/games/ludii/mode.cc +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2019 DeepMind Technologies Limited -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "open_spiel/games/ludii/mode.h" - -namespace open_spiel { -namespace ludii { - -Mode::Mode(JNIEnv *env, jobject mode) : env(env), mode(mode) {} - -int Mode::NumPlayers() const { - jclass gameClass = env->FindClass("game/mode/Mode"); - jmethodID stateFlags_id = env->GetMethodID(gameClass, "numPlayers", "()I"); - return (int)env->CallIntMethod(mode, stateFlags_id); -} - -} // namespace ludii -} // namespace open_spiel diff --git a/open_spiel/games/ludii/mode.h b/open_spiel/games/ludii/mode.h deleted file mode 100644 index aec1c18919..0000000000 --- a/open_spiel/games/ludii/mode.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2019 DeepMind Technologies Limited -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef OPEN_SPIEL_GAMES_LUDII_MODE_H_ -#define OPEN_SPIEL_GAMES_LUDII_MODE_H_ - -#include "jni.h" // NOLINT - -namespace open_spiel { -namespace ludii { - -class Mode { - public: - Mode(JNIEnv *env, jobject mode); - - int NumPlayers() const; - - private: - JNIEnv *env; - jobject mode; -}; - -} // namespace ludii -} // namespace open_spiel - -#endif // OPEN_SPIEL_GAMES_LUDII_MODE_H_ diff --git a/open_spiel/games/ludii/move.cc b/open_spiel/games/ludii/move.cc deleted file mode 100644 index fd3fb15872..0000000000 --- a/open_spiel/games/ludii/move.cc +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2019 DeepMind Technologies Limited -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "open_spiel/games/ludii/move.h" - -namespace open_spiel { -namespace ludii { - -Move::Move(JNIEnv *env, jobject move) : env(env), move(move) {} - -jobject Move::GetObj() const { return move; } - -} // namespace ludii -} // namespace open_spiel diff --git a/open_spiel/games/ludii/move.h b/open_spiel/games/ludii/move.h deleted file mode 100644 index 7d32c0e9a4..0000000000 --- a/open_spiel/games/ludii/move.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2019 DeepMind Technologies Limited -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef OPEN_SPIEL_GAMES_LUDII_MOVE_H_ -#define OPEN_SPIEL_GAMES_LUDII_MOVE_H_ - -#include -#include - -#include "jni.h" // NOLINT - -namespace open_spiel { -namespace ludii { - -class Move { - public: - Move(JNIEnv *env, jobject move); - - jobject GetObj() const; - - private: - JNIEnv *env; - jobject move; -}; - -} // namespace ludii -} // namespace open_spiel - -#endif // OPEN_SPIEL_GAMES_LUDII_MOVE_H_ diff --git a/open_spiel/games/ludii/moves.cc b/open_spiel/games/ludii/moves.cc deleted file mode 100644 index 0e3114d44d..0000000000 --- a/open_spiel/games/ludii/moves.cc +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2019 DeepMind Technologies Limited -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "open_spiel/games/ludii/moves.h" - -namespace open_spiel { -namespace ludii { - -Moves::Moves(JNIEnv *env, jobject moves) : env(env), moves(moves) {} - -std::vector Moves::GetMoves() const { - std::vector moveVector; - - jclass moves_class = env->FindClass("game/rules/play/moves/Moves"); - jmethodID moves_id = - env->GetMethodID(moves_class, "moves", "()Lmain/FastArrayList;"); - jobject moveFastArray_obj = env->CallObjectMethod(moves, moves_id); - - jclass fastArray_class = env->FindClass("main/FastArrayList"); - jmethodID fastArraySize_id = env->GetMethodID(fastArray_class, "size", "()I"); - jmethodID fastArrayGet_id = - env->GetMethodID(fastArray_class, "get", "(I)Ljava/lang/Object;"); - - jint fastArraySize = env->CallIntMethod(moveFastArray_obj, fastArraySize_id); - - for (int i = 0; i < fastArraySize; i++) { - jobject move_obj = - env->CallObjectMethod(moveFastArray_obj, fastArrayGet_id, i); - moveVector.push_back(Move(env, move_obj)); - } - - return moveVector; -} - -} // namespace ludii -} // namespace open_spiel diff --git a/open_spiel/games/ludii/moves.h b/open_spiel/games/ludii/moves.h deleted file mode 100644 index d1e539ee6b..0000000000 --- a/open_spiel/games/ludii/moves.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2019 DeepMind Technologies Limited -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef OPEN_SPIEL_GAMES_LUDII_MOVES_H_ -#define OPEN_SPIEL_GAMES_LUDII_MOVES_H_ - -#include -#include - -#include "jni.h" // NOLINT -#include "open_spiel/games/ludii/move.h" - -namespace open_spiel { -namespace ludii { - -class Moves { - public: - Moves(JNIEnv *env, jobject moves); - - std::vector GetMoves() const; - - private: - JNIEnv *env; - jobject moves; -}; - -} // namespace ludii -} // namespace open_spiel - -#endif // OPEN_SPIEL_GAMES_LUDII_MOVES_H_ diff --git a/open_spiel/games/ludii/region.cc b/open_spiel/games/ludii/region.cc deleted file mode 100644 index 8dfa0d9611..0000000000 --- a/open_spiel/games/ludii/region.cc +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2019 DeepMind Technologies Limited -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "open_spiel/games/ludii/region.h" - -namespace open_spiel { -namespace ludii { - -Region::Region(JNIEnv *env, jobject region) : env(env), region(region) {} - -ChunkSet Region::BitSet() const { - jclass regionClass = env->FindClass("util/Region"); - jmethodID bitSet_id = - env->GetMethodID(regionClass, "bitSet", "()Lutil/ChunkSet;"); - jobject chunkset_obj = env->CallObjectMethod(region, bitSet_id); - - return ChunkSet(env, chunkset_obj); -} - -} // namespace ludii -} // namespace open_spiel diff --git a/open_spiel/games/ludii/region.h b/open_spiel/games/ludii/region.h deleted file mode 100644 index e81a3030d0..0000000000 --- a/open_spiel/games/ludii/region.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2019 DeepMind Technologies Limited -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef OPEN_SPIEL_GAMES_LUDII_REGION_H_ -#define OPEN_SPIEL_GAMES_LUDII_REGION_H_ - -#include "jni.h" // NOLINT -#include "open_spiel/games/ludii/chunk_set.h" - -namespace open_spiel { -namespace ludii { - -class Region { - public: - Region(JNIEnv *env, jobject region); - - ChunkSet BitSet() const; - - private: - JNIEnv *env; - jobject region; -}; - -} // namespace ludii -} // namespace open_spiel - -#endif // OPEN_SPIEL_GAMES_LUDII_REGION_H_ diff --git a/open_spiel/games/ludii/state.cc b/open_spiel/games/ludii/state.cc deleted file mode 100644 index fa23fb6bc0..0000000000 --- a/open_spiel/games/ludii/state.cc +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2019 DeepMind Technologies Limited -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "open_spiel/games/ludii/state.h" - -namespace open_spiel { -namespace ludii { - -State::State(JNIEnv *env, jobject state) : env(env), state(state) {} - -std::vector State::ContainerStates() const { - std::vector containerStateVector; - - jclass stateClass = env->FindClass("util/state/State"); - jmethodID containerStates_id = - env->GetMethodID(stateClass, "containerStates", - "()[Lutil/state/containerState/ContainerState;"); - jobjectArray containerStateArray = - (jobjectArray)env->CallObjectMethod(state, containerStates_id); - int containerStateCount = env->GetArrayLength(containerStateArray); - - for (int i = 0; i < containerStateCount; i++) { - jobject containerStateObj = - env->GetObjectArrayElement(containerStateArray, i); - containerStateVector.push_back(ContainerState(env, containerStateObj)); - } - - return containerStateVector; -} - -int State::Mover() const { - jclass stateClass = env->FindClass("util/state/State"); - jmethodID mover_id = env->GetMethodID(stateClass, "mover", "()I"); - - return (int)env->CallIntMethod(state, mover_id); -} - -} // namespace ludii -} // namespace open_spiel diff --git a/open_spiel/games/ludii/state.h b/open_spiel/games/ludii/state.h deleted file mode 100644 index 3800ed72a4..0000000000 --- a/open_spiel/games/ludii/state.h +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2019 DeepMind Technologies Limited -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef OPEN_SPIEL_GAMES_LUDII_STATE_H_ -#define OPEN_SPIEL_GAMES_LUDII_STATE_H_ - -#include - -#include "jni.h" // NOLINT -#include "open_spiel/games/ludii/container_state.h" - -namespace open_spiel { -namespace ludii { - -class State { - public: - State(JNIEnv *env, jobject state); - - std::vector ContainerStates() const; - - int Mover() const; - - private: - JNIEnv *env; - jobject state; -}; - -} // namespace ludii -} // namespace open_spiel - -#endif // OPEN_SPIEL_GAMES_LUDII_STATE_H_ diff --git a/open_spiel/games/ludii/trial.cc b/open_spiel/games/ludii/trial.cc deleted file mode 100644 index 6119e6ce84..0000000000 --- a/open_spiel/games/ludii/trial.cc +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2019 DeepMind Technologies Limited -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "open_spiel/games/ludii/trial.h" - -namespace open_spiel { -namespace ludii { - -Trial::Trial(JNIEnv *env, Game game) : env(env) { - jclass trial_class = env->FindClass("util/Trial"); - jmethodID trial_const_id = - env->GetMethodID(trial_class, "", "(Lgame/Game;)V"); - jobject trial_obj = - env->NewObject(trial_class, trial_const_id, game.GetObj()); - - trial = trial_obj; -} - -jobject Trial::GetObj() const { return trial; } - -State Trial::GetState() const { - jclass trial_class = env->FindClass("util/Trial"); - jmethodID state_id = - env->GetMethodID(trial_class, "state", "()Lutil/state/State;"); - jobject state_obj = env->CallObjectMethod(trial, state_id); - - return State(env, state_obj); -} - -bool Trial::Over() const { - jclass trial_class = env->FindClass("util/Trial"); - jmethodID over_id = env->GetMethodID(trial_class, "over", "()Z"); - - return (bool)env->CallObjectMethod(trial, over_id); -} - -} // namespace ludii -} // namespace open_spiel diff --git a/open_spiel/games/ludii/trial.h b/open_spiel/games/ludii/trial.h deleted file mode 100644 index 2e36d2ad5c..0000000000 --- a/open_spiel/games/ludii/trial.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2019 DeepMind Technologies Limited -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef OPEN_SPIEL_GAMES_LUDII_TRIAL_H_ -#define OPEN_SPIEL_GAMES_LUDII_TRIAL_H_ - -#include "jni.h" // NOLINT -#include "open_spiel/games/ludii/game.h" -#include "open_spiel/games/ludii/state.h" - -namespace open_spiel { -namespace ludii { - -class Trial { - public: - Trial(JNIEnv *env, Game game); - - jobject GetObj() const; - - State GetState() const; - - bool Over() const; - - private: - JNIEnv *env; - jobject trial; -}; - -} // namespace ludii -} // namespace open_spiel - -#endif // OPEN_SPIEL_GAMES_LUDII_TRIAL_H_