From 0eacb8ae45938c7023773c10e1302a04f8c1e93a Mon Sep 17 00:00:00 2001 From: Devin Hill <98devin@gmail.com> Date: Thu, 30 Jul 2020 10:30:51 -0400 Subject: [PATCH 1/2] Fix pyhanabi.HanabiState.copy incorrectly retrieving state parent game object. --- hanabi_learning_environment/pyhanabi.cc | 9 +++++---- hanabi_learning_environment/pyhanabi.h | 2 +- hanabi_learning_environment/pyhanabi.py | 5 +++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/hanabi_learning_environment/pyhanabi.cc b/hanabi_learning_environment/pyhanabi.cc index 3c4a3bc4..e4688044 100644 --- a/hanabi_learning_environment/pyhanabi.cc +++ b/hanabi_learning_environment/pyhanabi.cc @@ -311,12 +311,13 @@ void DeleteState(pyhanabi_state_t* state) { state->state = nullptr; } -const void* StateParentGame(pyhanabi_state_t* state) { +void StateParentGame(pyhanabi_state_t* state, pyhanabi_game_t* game) { REQUIRE(state != nullptr); REQUIRE(state->state != nullptr); - return static_cast( - reinterpret_cast(state->state) - ->ParentGame()); + REQUIRE(game != nullptr); + auto hanabi_state = + reinterpret_cast(state->state); + game->game = (void*)hanabi_state->ParentGame(); } void StateApplyMove(pyhanabi_state_t* state, pyhanabi_move_t* move) { diff --git a/hanabi_learning_environment/pyhanabi.h b/hanabi_learning_environment/pyhanabi.h index 385428ca..05fefe54 100644 --- a/hanabi_learning_environment/pyhanabi.h +++ b/hanabi_learning_environment/pyhanabi.h @@ -111,7 +111,7 @@ int HistoryItemDealToPlayer(pyhanabi_history_item_t* item); void NewState(pyhanabi_game_t* game, pyhanabi_state_t* state); void CopyState(const pyhanabi_state_t* src, pyhanabi_state_t* dest); void DeleteState(pyhanabi_state_t* state); -const void* StateParentGame(pyhanabi_state_t* state); +void StateParentGame(pyhanabi_state_t* state, pyhanabi_game_t* game); void StateApplyMove(pyhanabi_state_t* state, pyhanabi_move_t* move); int StateCurPlayer(pyhanabi_state_t* state); void StateDealRandomCard(pyhanabi_state_t* state); diff --git a/hanabi_learning_environment/pyhanabi.py b/hanabi_learning_environment/pyhanabi.py index 592e7039..e98190d4 100644 --- a/hanabi_learning_environment/pyhanabi.py +++ b/hanabi_learning_environment/pyhanabi.py @@ -68,7 +68,7 @@ def try_cdef(header=PYHANABI_HEADER, prefixes=DEFAULT_CDEF_PREFIXES): cdef_string = cdef_string + line + "\n" ffi.cdef(cdef_string) cdef_loaded_flag = True - return True + return True except IOError: pass return False @@ -516,7 +516,8 @@ def __init__(self, game, c_state=None): self._game = game.c_game lib.NewState(self._game, self._state) else: - self._game = lib.StateParentGame(c_state) + self._game = ffi.new("pyhanabi_game_t*") + lib.StateParentGame(c_state, self._game) lib.CopyState(c_state, self._state) def copy(self): From 44ee2bf9793634ace9ae5c443c90a5ea7fc04f1f Mon Sep 17 00:00:00 2001 From: Devin Hill <98devin@gmail.com> Date: Thu, 30 Jul 2020 10:35:25 -0400 Subject: [PATCH 2/2] update .gitignore to ignore CMake files --- .gitignore | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 7e99e367..f6e884fb 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ -*.pyc \ No newline at end of file +*.pyc +Makefile +CMakeFiles/ +CMakeCache.txt +*.cmake \ No newline at end of file