From 345072a1c181d4c27489b82c299864fce90f2760 Mon Sep 17 00:00:00 2001 From: Emma Tosch Date: Fri, 8 Mar 2019 12:13:14 -0500 Subject: [PATCH 01/21] working on #43 --- ctoybox/Cargo.toml | 3 +++ ctoybox/src/build.rs | 13 ++++++++++ ctoybox/toybox/setup.py | 31 ++++++++++++++++++++--- ctoybox/toybox/toybox/__init__.py | 42 ++++++++++++++++++------------- 4 files changed, 67 insertions(+), 22 deletions(-) create mode 100644 ctoybox/src/build.rs diff --git a/ctoybox/Cargo.toml b/ctoybox/Cargo.toml index d5ca2812..3e96f8c3 100644 --- a/ctoybox/Cargo.toml +++ b/ctoybox/Cargo.toml @@ -2,6 +2,7 @@ name = "ctoybox" version = "0.1.0" authors = ["Emma 'Frank' Tosch "] +build = "build.rs" [lib] name = "ctoybox" @@ -19,3 +20,5 @@ toybox = {path = "../toybox", version="*"} version = "*" path = "../core" +[build-dependencies] +cbindgen = "0.4" \ No newline at end of file diff --git a/ctoybox/src/build.rs b/ctoybox/src/build.rs new file mode 100644 index 00000000..21a6bfc0 --- /dev/null +++ b/ctoybox/src/build.rs @@ -0,0 +1,13 @@ +// from https://github.com/getsentry/milksnake +extern crate cbindgen; + +use std::env; + +fn main() { + let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); + let mut config: cbindgen::Config = Default::default(); + config.language = cbindgen::Language::C; + cbindgen::generate_with_config(&crate_dir, config) + .unwrap() + .write_to_file("../../target/ctoybox.h"); +} \ No newline at end of file diff --git a/ctoybox/toybox/setup.py b/ctoybox/toybox/setup.py index 5c6d7202..f36dac4a 100644 --- a/ctoybox/toybox/setup.py +++ b/ctoybox/toybox/setup.py @@ -1,6 +1,29 @@ +# From https://github.com/getsentry/milksnake from setuptools import setup -setup(name='openai_shim', - version='0.0.1', - install_requires=['gym'] # And any other dependencies foo needs -) \ No newline at end of file +def build_native(spec): + # build an example rust library + build = spec.add_external_build( + cmd=['cargo', 'build', '--release'], + path='../..' + ) + + spec.add_cffi_module( + module_path='toybox._native', + dylib=lambda: build.find_dylib('ctoybox', in_path='../../target/release'), + header_filename=lambda: build.find_header('ctoybox.h', in_path='../../target'), + rtld_flags=['NOW', 'NODELETE'] + ) + +setup( + name='toybox', + version='0.0.1', + packages=['toybox'], + zip_safe=False, + platforms='any', + setup_requires=['milksnake'], + install_requires=['milksnake'], + milksnake_tasks=[ + build_native + ] +) \ No newline at end of file diff --git a/ctoybox/toybox/toybox/__init__.py b/ctoybox/toybox/toybox/__init__.py index a1d147f6..1c1191c3 100644 --- a/ctoybox/toybox/toybox/__init__.py +++ b/ctoybox/toybox/toybox/__init__.py @@ -1,26 +1,32 @@ -from gym.envs.registration import register import toybox.toybox as toybox import toybox.envs as envs import toybox.interventions as interventions import toybox.sample_tests as sample_tests -# Updated to use v4 to be analogous with the ALE versioning -register( - id='BreakoutToyboxNoFrameskip-v4', - entry_point='toybox.envs.atari:BreakoutEnv', - nondeterministic=True -) +try: + from gym.envs.registration import register -register( - id='AmidarToyboxNoFrameskip-v4', - entry_point='toybox.envs.atari:AmidarEnv', - nondeterministic=False -) + # Updated to use v4 to be analogous with the ALE versioning + register( + id='BreakoutToyboxNoFrameskip-v4', + entry_point='toybox.envs. atari:BreakoutEnv', + nondeterministic=True + ) -register( - id='SpaceInvadersToyboxNoFrameskip-v4', - entry_point='toybox.envs.atari:SpaceInvadersEnv', - nondeterministic=False -) + register( + id='AmidarToyboxNoFrameskip-v4', + entry_point='toybox.envs.atari:AmidarEnv', + nondeterministic=False + ) -print("Loaded Toybox environments.") \ No newline at end of file + register( + id='SpaceInvadersToyboxNoFrameskip-v4', + entry_point='toybox.envs. atari:SpaceInvadersEnv', + nondeterministic=False + ) + + print("Registered Toybox environments with gym.") + +except: + # ModuleNotFoundError only in 3.6 and above + print("Loaded Toybox environments.") From e5e9e32dfc008065b81d52e988af20177dd5e031 Mon Sep 17 00:00:00 2001 From: Emma Tosch Date: Fri, 8 Mar 2019 15:00:06 -0500 Subject: [PATCH 02/21] cbindgen issue resolved, but getting amidar errors; @jjfiv --- ctoybox/Cargo.toml | 2 +- ctoybox/{src => }/build.rs | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename ctoybox/{src => }/build.rs (100%) diff --git a/ctoybox/Cargo.toml b/ctoybox/Cargo.toml index 3e96f8c3..1659fbb6 100644 --- a/ctoybox/Cargo.toml +++ b/ctoybox/Cargo.toml @@ -21,4 +21,4 @@ version = "*" path = "../core" [build-dependencies] -cbindgen = "0.4" \ No newline at end of file +cbindgen = "0.5" \ No newline at end of file diff --git a/ctoybox/src/build.rs b/ctoybox/build.rs similarity index 100% rename from ctoybox/src/build.rs rename to ctoybox/build.rs From 885449ece01954861f9041d457f423dea86357b5 Mon Sep 17 00:00:00 2001 From: Emma Tosch Date: Fri, 8 Mar 2019 15:14:30 -0500 Subject: [PATCH 03/21] setup prefixes paths with the default stuff --- ctoybox/toybox/setup.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ctoybox/toybox/setup.py b/ctoybox/toybox/setup.py index f36dac4a..40facf52 100644 --- a/ctoybox/toybox/setup.py +++ b/ctoybox/toybox/setup.py @@ -10,8 +10,8 @@ def build_native(spec): spec.add_cffi_module( module_path='toybox._native', - dylib=lambda: build.find_dylib('ctoybox', in_path='../../target/release'), - header_filename=lambda: build.find_header('ctoybox.h', in_path='../../target'), + dylib=lambda: build.find_dylib('ctoybox', in_path='target/release'), + header_filename=lambda: build.find_header('ctoybox.h', in_path='target'), rtld_flags=['NOW', 'NODELETE'] ) @@ -26,4 +26,4 @@ def build_native(spec): milksnake_tasks=[ build_native ] -) \ No newline at end of file +) From 415345a906976c9fad36a80e3bec39b1db1c02b9 Mon Sep 17 00:00:00 2001 From: Emma Tosch Date: Fri, 8 Mar 2019 15:27:11 -0500 Subject: [PATCH 04/21] updated path for header --- ctoybox/build.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ctoybox/build.rs b/ctoybox/build.rs index 21a6bfc0..23c50526 100644 --- a/ctoybox/build.rs +++ b/ctoybox/build.rs @@ -8,6 +8,6 @@ fn main() { let mut config: cbindgen::Config = Default::default(); config.language = cbindgen::Language::C; cbindgen::generate_with_config(&crate_dir, config) - .unwrap() - .write_to_file("../../target/ctoybox.h"); -} \ No newline at end of file + .unwrap() + .write_to_file("../target/ctoybox.h"); +} From 8341ce3617a519f48975cf90d4775e620739fbac Mon Sep 17 00:00:00 2001 From: Emma Tosch Date: Fri, 8 Mar 2019 15:46:54 -0500 Subject: [PATCH 05/21] just declared it here, so it gets exported --- ctoybox/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ctoybox/src/lib.rs b/ctoybox/src/lib.rs index f58c1217..6870f63f 100644 --- a/ctoybox/src/lib.rs +++ b/ctoybox/src/lib.rs @@ -22,3 +22,5 @@ pub struct WrapState { mod core; pub use core::*; + +pub struct Input; \ No newline at end of file From 823d279577123a9ea4bd3e02b68b5dae807fe923 Mon Sep 17 00:00:00 2001 From: Emma Tosch Date: Fri, 15 Mar 2019 12:04:40 -0400 Subject: [PATCH 06/21] #43: pip install this mofo, yall --- ctoybox/toybox/setup.py | 8 ++++---- ctoybox/toybox/toybox/__init__.py | 4 ++-- ctoybox/toybox/toybox/toybox.py | 6 +++++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ctoybox/toybox/setup.py b/ctoybox/toybox/setup.py index 40facf52..bbda43f3 100644 --- a/ctoybox/toybox/setup.py +++ b/ctoybox/toybox/setup.py @@ -5,20 +5,20 @@ def build_native(spec): # build an example rust library build = spec.add_external_build( cmd=['cargo', 'build', '--release'], - path='../..' + path='.' ) spec.add_cffi_module( module_path='toybox._native', - dylib=lambda: build.find_dylib('ctoybox', in_path='target/release'), - header_filename=lambda: build.find_header('ctoybox.h', in_path='target'), + dylib=lambda: build.find_dylib('ctoybox', in_path='../../target/release'), + header_filename=lambda: build.find_header('ctoybox.h', in_path='../../target'), rtld_flags=['NOW', 'NODELETE'] ) setup( name='toybox', version='0.0.1', - packages=['toybox'], + packages=['toybox', 'toybox.envs', 'toybox.interventions', 'toybox.sample_tests'], zip_safe=False, platforms='any', setup_requires=['milksnake'], diff --git a/ctoybox/toybox/toybox/__init__.py b/ctoybox/toybox/toybox/__init__.py index 1c1191c3..0d96e407 100644 --- a/ctoybox/toybox/toybox/__init__.py +++ b/ctoybox/toybox/toybox/__init__.py @@ -9,7 +9,7 @@ # Updated to use v4 to be analogous with the ALE versioning register( id='BreakoutToyboxNoFrameskip-v4', - entry_point='toybox.envs. atari:BreakoutEnv', + entry_point='toybox.envs.atari:BreakoutEnv', nondeterministic=True ) @@ -21,7 +21,7 @@ register( id='SpaceInvadersToyboxNoFrameskip-v4', - entry_point='toybox.envs. atari:SpaceInvadersEnv', + entry_point='toybox.envs.atari:SpaceInvadersEnv', nondeterministic=False ) diff --git a/ctoybox/toybox/toybox/toybox.py b/ctoybox/toybox/toybox/toybox.py index bc722cbf..a1e1a33c 100644 --- a/ctoybox/toybox/toybox/toybox.py +++ b/ctoybox/toybox/toybox/toybox.py @@ -7,7 +7,11 @@ import time import json -from toybox.clib import _lib, Input, NOOP, LEFT, RIGHT, UP, DOWN, BUTTON1, BUTTON2 +#from toybox.clib import _lib, Input, NOOP, LEFT, RIGHT, UP, DOWN, BUTTON1, BUTTON2 +#from toybox.clib import Input, NOOP, LEFT, RIGHT, UP, DOWN, BUTTON1, BUTTON2 +from toybox._native import ffi, lib + +_lib = lib def rust_str(result): txt = ctypes.cast(result, ctypes.c_char_p).value.decode('UTF-8') From f7f1b6944a63da2366cf2419e9eed7b89b2f9afb Mon Sep 17 00:00:00 2001 From: Emma Tosch Date: Fri, 15 Mar 2019 12:55:08 -0400 Subject: [PATCH 07/21] translating ctypes to ffi on account of milksnake using ffi #43 --- ctoybox/src/core.rs | 6 +++--- ctoybox/toybox/toybox/toybox.py | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/ctoybox/src/core.rs b/ctoybox/src/core.rs index 434f35dd..bd481be7 100644 --- a/ctoybox/src/core.rs +++ b/ctoybox/src/core.rs @@ -1,6 +1,6 @@ use super::WrapSimulator; use super::WrapState; -use libc::c_char; +use libc::{c_char, c_void}; use serde_json; use std::boxed::Box; use std::ffi::{CStr, CString}; @@ -246,7 +246,7 @@ pub extern "C" fn state_score(state_ptr: *mut WrapState) -> i32 { } #[no_mangle] -pub extern "C" fn state_to_json(state_ptr: *mut WrapState) -> *const c_char { +pub extern "C" fn state_to_json(state_ptr: *mut WrapState) -> *mut c_void { let &mut WrapState { ref mut state } = unsafe { assert!(!state_ptr.is_null()); &mut *state_ptr @@ -254,7 +254,7 @@ pub extern "C" fn state_to_json(state_ptr: *mut WrapState) -> *const c_char { let json: String = state.to_json(); let cjson: CString = CString::new(json).expect("Conversion to CString should succeed!"); - CString::into_raw(cjson) + CString::into_raw(cjson) as *mut c_void } #[no_mangle] diff --git a/ctoybox/toybox/toybox/toybox.py b/ctoybox/toybox/toybox/toybox.py index a1e1a33c..7415bf5c 100644 --- a/ctoybox/toybox/toybox/toybox.py +++ b/ctoybox/toybox/toybox/toybox.py @@ -7,14 +7,21 @@ import time import json -#from toybox.clib import _lib, Input, NOOP, LEFT, RIGHT, UP, DOWN, BUTTON1, BUTTON2 -#from toybox.clib import Input, NOOP, LEFT, RIGHT, UP, DOWN, BUTTON1, BUTTON2 -from toybox._native import ffi, lib +try: + # This is for pip install + from toybox._native import ffi, lib + _lib = lib + +except: + # deprecated + from toybox.clib import _lib, Input, NOOP, LEFT, RIGHT, UP, DOWN, BUTTON1, BUTTON2 + from toybox.clib import Input, NOOP, LEFT, RIGHT, UP, DOWN, BUTTON1, BUTTON2 + + -_lib = lib def rust_str(result): - txt = ctypes.cast(result, ctypes.c_char_p).value.decode('UTF-8') + txt = ffi.cast("char *", result).value.decode('UTF-8') _lib.free_str(result) return txt From 9a8c5335f8f8262a38cb1c43fee1d7332dffdf6d Mon Sep 17 00:00:00 2001 From: Emma Tosch Date: Fri, 15 Mar 2019 15:03:27 -0400 Subject: [PATCH 08/21] string conversion issue fixed for json state (#43) --- .gitignore | 7 ++++++- ctoybox/toybox/toybox/toybox.py | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index ad15fb23..0e1dc86a 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,9 @@ ctoybox/*.model.data-00000-of-00001 ctoybox/*.model.index ctoybox/*.model.meta ctoybox/checkpoint -ctoybox/*.model \ No newline at end of file +ctoybox/*.modeltoybox/build +toybox/dist +ctoybox/toybox/build +ctoybox/toybox/dist +ctoybox/toybox/toybox.egg-info +ctoybox/toybox/toybox/_native__lib.so diff --git a/ctoybox/toybox/toybox/toybox.py b/ctoybox/toybox/toybox/toybox.py index 7415bf5c..eeff13b2 100644 --- a/ctoybox/toybox/toybox/toybox.py +++ b/ctoybox/toybox/toybox/toybox.py @@ -21,7 +21,8 @@ def rust_str(result): - txt = ffi.cast("char *", result).value.decode('UTF-8') + txt = ffi.cast("char *", result) #.value.decode('UTF-8') + txt = ffi.string(txt).decode('UTF-8') _lib.free_str(result) return txt From a7a64edff812cd2d10c4fdcc59ea95e1d313b389 Mon Sep 17 00:00:00 2001 From: Emma Tosch Date: Sat, 16 Mar 2019 11:37:03 -0400 Subject: [PATCH 09/21] Migrating from ctypes to ffi library, since that is what milksnake uses. This commit around: 1. Migrated from exchanging Input structs to exchanging json blobs. 2. Added back local dll load. 3. Tested apply_action --- ctoybox/src/core.rs | 9 +- ctoybox/start_python | 1 + ctoybox/toybox/toybox/clib.py | 436 ++++++++++++++++---------------- ctoybox/toybox/toybox/toybox.py | 187 +++++++++++--- 4 files changed, 380 insertions(+), 253 deletions(-) diff --git a/ctoybox/src/core.rs b/ctoybox/src/core.rs index bd481be7..96711d58 100644 --- a/ctoybox/src/core.rs +++ b/ctoybox/src/core.rs @@ -215,16 +215,17 @@ pub extern "C" fn state_apply_ale_action(state_ptr: *mut WrapState, input: i32) } #[no_mangle] -pub extern "C" fn state_apply_action(state_ptr: *mut WrapState, input_ptr: *mut Input) { +pub extern "C" fn state_apply_action(state_ptr: *mut WrapState, input_ptr: *const c_char) { let &mut WrapState { ref mut state } = unsafe { assert!(!state_ptr.is_null()); &mut *state_ptr }; - let input = unsafe { + let input_str = unsafe { assert!(!input_ptr.is_null()); - &mut *input_ptr + CStr::from_ptr(input_ptr).to_str().expect("Could not convert input json str to UTF-8") }; - state.update_mut(*input); + let input : Input = serde_json::from_str(input_str).expect("Could not convert input to JSON"); + state.update_mut(input); } #[no_mangle] diff --git a/ctoybox/start_python b/ctoybox/start_python index b74d73fa..89337e37 100755 --- a/ctoybox/start_python +++ b/ctoybox/start_python @@ -2,6 +2,7 @@ #pip3 install -q -r REQUIREMENTS.txt --user export PYTHONPATH=${PWD}/baselines:${PWD}/toybox:${PYTHONPATH}:${HOME}/toybox/ctoybox/baselines:${HOME}/toybox/ctoybox/toybox export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${PWD}/../target/release:${HOME}/toybox/target/release:${HOME}/dev/toybox/target/release +export LIBCTOYBOX=${HOME}/dev/Toybox echo "PYTHONPATH $PYTHONPATH" echo "LD_LIBRARY_PATH $LD_LIBRARY_PATH" echo "LIBCTOYBOX $LIBCTOYBOX" diff --git a/ctoybox/toybox/toybox/clib.py b/ctoybox/toybox/toybox/clib.py index 1d2ca4fe..a668e4d2 100644 --- a/ctoybox/toybox/toybox/clib.py +++ b/ctoybox/toybox/toybox/clib.py @@ -1,240 +1,240 @@ -from collections import deque -import ctypes -import numpy as np -from PIL import Image -import os -import platform -import time -import json - -platform = platform.system() -lib_env_var = 'LIBCTOYBOX' -lib_dylib = 'libctoybox.dylib' -lib_so = 'libctoybox.so' - - -if platform == 'Darwin': - _lib_prefix = os.environ[lib_env_var] if lib_env_var in os.environ else '..' - _lib_path_debug = os.path.sep.join([_lib_prefix, 'target', 'debug', lib_dylib]) - _lib_path_release = os.path.sep.join([_lib_prefix, 'target', 'release', lib_dylib]) - print('Looking for toybox lib in\n\t%s\nor\n\t%s' % ( - _lib_path_debug, - _lib_path_release - )) - - _lib_ts_release = os.stat(_lib_path_release).st_birthtime \ - if os.path.exists(_lib_path_release) else 0 - _lib_ts_debug = os.stat(_lib_path_debug).st_birthtime \ - if os.path.exists(_lib_path_debug) else 0 +# from collections import deque +# import ctypes +# import numpy as np +# from PIL import Image +# import os +# import platform +# import time +# import json + +# platform = platform.system() +# lib_env_var = 'LIBCTOYBOX' +# lib_dylib = 'libctoybox.dylib' +# lib_so = 'libctoybox.so' + + +# if platform == 'Darwin': +# _lib_prefix = os.environ[lib_env_var] if lib_env_var in os.environ else '..' +# _lib_path_debug = os.path.sep.join([_lib_prefix, 'target', 'debug', lib_dylib]) +# _lib_path_release = os.path.sep.join([_lib_prefix, 'target', 'release', lib_dylib]) +# print('Looking for toybox lib in\n\t%s\nor\n\t%s' % ( +# _lib_path_debug, +# _lib_path_release +# )) + +# _lib_ts_release = os.stat(_lib_path_release).st_birthtime \ +# if os.path.exists(_lib_path_release) else 0 +# _lib_ts_debug = os.stat(_lib_path_debug).st_birthtime \ +# if os.path.exists(_lib_path_debug) else 0 - if (not (_lib_ts_debug or _lib_ts_release)): - raise OSError('%s not found on this machine' % lib_dylib) +# if (not (_lib_ts_debug or _lib_ts_release)): +# raise OSError('%s not found on this machine' % lib_dylib) - _lib_path = _lib_path_debug if _lib_ts_debug > _lib_ts_release else _lib_path_release - print(_lib_path) +# _lib_path = _lib_path_debug if _lib_ts_debug > _lib_ts_release else _lib_path_release +# print(_lib_path) -elif platform == 'Linux': - _lib_path = lib_so +# elif platform == 'Linux': +# _lib_path = lib_so -else: - raise Exception('Unsupported platform: %s' % platform) - - -try: - _lib = ctypes.CDLL(_lib_path) -except Exception: - raise Exception('Could not load libopenai from path %s.' % _lib_path - + """If you are on OSX, this may be due the relative path being different - from `target/(target|release)/libopenai.dylib. If you are on Linux, try - prefixing your call with `LD_LIBRARY_PATH=/path/to/library`.""") - -class WrapSimulator(ctypes.Structure): - pass - -class WrapState(ctypes.Structure): - pass - - -# I don't know how actions will be issued, so let's have lots of options available -NOOP = 'noop' -LEFT = "left" -RIGHT = "right" -UP = "up" -DOWN = "down" -BUTTON1 = "button1" -BUTTON2 = "button2" - -class Input(ctypes.Structure): - _fields_ = [(LEFT, ctypes.c_bool), - (RIGHT, ctypes.c_bool), - (UP, ctypes.c_bool), - (DOWN, ctypes.c_bool), - (BUTTON1, ctypes.c_bool), - (BUTTON2, ctypes.c_bool)] - - def _set_default(self): - self.left = False - self.right = False - self.up = False - self.down = False - self.button1 = False - self.button2 = False - - """ - ALE_ACTION_MEANING = { - 0 : "NOOP", - 1 : "FIRE", - 2 : "UP", - 3 : "RIGHT", - 4 : "LEFT", - 5 : "DOWN", - 6 : "UPRIGHT", - 7 : "UPLEFT", - 8 : "DOWNRIGHT", - 9 : "DOWNLEFT", - 10 : "UPFIRE", - 11 : "RIGHTFIRE", - 12 : "LEFTFIRE", - 13 : "DOWNFIRE", - 14 : "UPRIGHTFIRE", - 15 : "UPLEFTFIRE", - 16 : "DOWNRIGHTFIRE", - 17 : "DOWNLEFTFIRE", - } - """ - def set_ale(self, num): - if num == 0: - pass - elif num == 1: - self.button1 = True - elif num == 2: - self.up = True - elif num == 3: - self.right = True - elif num == 4: - self.left = True - elif num == 5: - self.down = True - elif num == 6: - self.up = True - self.right = True - elif num == 7: - self.up = True - self.left = True - elif num == 8: - self.down = True - self.right = True - elif num == 9: - self.down = True - self.left = True - elif num == 10: - self.up = True - self.button1 = True - elif num == 11: - self.right = True - self.button1 = True - elif num == 12: - self.left = True - self.button1 = True - elif num == 13: - self.down = True - self.button1 = True - elif num == 14: - self.up = True - self.right = True - self.button1 = True - elif num == 15: - self.up = True - self.left = True - self.button1 = True - elif num == 16: - self.down = True - self.right = True - self.button1 = True - elif num == 17: - self.down = True - self.left = True - self.button1 = True - - - def set_input(self, input_dir, button=NOOP): - self._set_default() - input_dir = input_dir.lower() - button = button.lower() - - # reset all directions - if input_dir == NOOP: - pass - elif input_dir == LEFT: - self.left = True - elif input_dir == RIGHT: - self.right = True - elif input_dir == UP: - self.up = True - elif input_dir == DOWN: - self.down = True - else: - print('input_dir:', input_dir) - assert False - - # reset buttons - if button == NOOP: - pass - elif button == BUTTON1: - self.button1 = True - elif button == BUTTON2: - self.button2 = True - else: - assert False +# else: +# raise Exception('Unsupported platform: %s' % platform) + + +# try: +# _lib = ctypes.CDLL(_lib_path) +# except Exception: +# raise Exception('Could not load libopenai from path %s.' % _lib_path +# + """If you are on OSX, this may be due the relative path being different +# from `target/(target|release)/libopenai.dylib. If you are on Linux, try +# prefixing your call with `LD_LIBRARY_PATH=/path/to/library`.""") + +# class WrapSimulator(ctypes.Structure): +# pass + +# class WrapState(ctypes.Structure): +# pass + + +# # I don't know how actions will be issued, so let's have lots of options available +# NOOP = 'noop' +# LEFT = "left" +# RIGHT = "right" +# UP = "up" +# DOWN = "down" +# BUTTON1 = "button1" +# BUTTON2 = "button2" + +# class Input(ctypes.Structure): +# _fields_ = [(LEFT, ctypes.c_bool), +# (RIGHT, ctypes.c_bool), +# (UP, ctypes.c_bool), +# (DOWN, ctypes.c_bool), +# (BUTTON1, ctypes.c_bool), +# (BUTTON2, ctypes.c_bool)] + +# def _set_default(self): +# self.left = False +# self.right = False +# self.up = False +# self.down = False +# self.button1 = False +# self.button2 = False + +# """ +# ALE_ACTION_MEANING = { +# 0 : "NOOP", +# 1 : "FIRE", +# 2 : "UP", +# 3 : "RIGHT", +# 4 : "LEFT", +# 5 : "DOWN", +# 6 : "UPRIGHT", +# 7 : "UPLEFT", +# 8 : "DOWNRIGHT", +# 9 : "DOWNLEFT", +# 10 : "UPFIRE", +# 11 : "RIGHTFIRE", +# 12 : "LEFTFIRE", +# 13 : "DOWNFIRE", +# 14 : "UPRIGHTFIRE", +# 15 : "UPLEFTFIRE", +# 16 : "DOWNRIGHTFIRE", +# 17 : "DOWNLEFTFIRE", +# } +# """ +# def set_ale(self, num): +# if num == 0: +# pass +# elif num == 1: +# self.button1 = True +# elif num == 2: +# self.up = True +# elif num == 3: +# self.right = True +# elif num == 4: +# self.left = True +# elif num == 5: +# self.down = True +# elif num == 6: +# self.up = True +# self.right = True +# elif num == 7: +# self.up = True +# self.left = True +# elif num == 8: +# self.down = True +# self.right = True +# elif num == 9: +# self.down = True +# self.left = True +# elif num == 10: +# self.up = True +# self.button1 = True +# elif num == 11: +# self.right = True +# self.button1 = True +# elif num == 12: +# self.left = True +# self.button1 = True +# elif num == 13: +# self.down = True +# self.button1 = True +# elif num == 14: +# self.up = True +# self.right = True +# self.button1 = True +# elif num == 15: +# self.up = True +# self.left = True +# self.button1 = True +# elif num == 16: +# self.down = True +# self.right = True +# self.button1 = True +# elif num == 17: +# self.down = True +# self.left = True +# self.button1 = True + + +# def set_input(self, input_dir, button=NOOP): +# self._set_default() +# input_dir = input_dir.lower() +# button = button.lower() + +# # reset all directions +# if input_dir == NOOP: +# pass +# elif input_dir == LEFT: +# self.left = True +# elif input_dir == RIGHT: +# self.right = True +# elif input_dir == UP: +# self.up = True +# elif input_dir == DOWN: +# self.down = True +# else: +# print('input_dir:', input_dir) +# assert False + +# # reset buttons +# if button == NOOP: +# pass +# elif button == BUTTON1: +# self.button1 = True +# elif button == BUTTON2: +# self.button2 = True +# else: +# assert False -_lib.simulator_alloc.argtypes = [ctypes.c_char_p] -_lib.simulator_alloc.restype = ctypes.POINTER(WrapSimulator) +# _lib.simulator_alloc.argtypes = [ctypes.c_char_p] +# _lib.simulator_alloc.restype = ctypes.POINTER(WrapSimulator) -_lib.simulator_seed.argtypes = [ctypes.POINTER(WrapSimulator), ctypes.c_uint] -_lib.simulator_seed.restype = None +# _lib.simulator_seed.argtypes = [ctypes.POINTER(WrapSimulator), ctypes.c_uint] +# _lib.simulator_seed.restype = None -_lib.simulator_is_legal_action.argtypes = [ctypes.POINTER(WrapSimulator), ctypes.c_int32] -_lib.simulator_is_legal_action.restype = ctypes.c_bool +# _lib.simulator_is_legal_action.argtypes = [ctypes.POINTER(WrapSimulator), ctypes.c_int32] +# _lib.simulator_is_legal_action.restype = ctypes.c_bool -_lib.simulator_actions.argtypes = [ctypes.POINTER(WrapSimulator)] -_lib.simulator_actions.restype = ctypes.c_void_p +# _lib.simulator_actions.argtypes = [ctypes.POINTER(WrapSimulator)] +# _lib.simulator_actions.restype = ctypes.c_void_p -_lib.state_alloc.argtypes = [ctypes.POINTER(WrapSimulator)] -_lib.state_alloc.restype = ctypes.POINTER(WrapState) +# _lib.state_alloc.argtypes = [ctypes.POINTER(WrapSimulator)] +# _lib.state_alloc.restype = ctypes.POINTER(WrapState) -_lib.free_str.argtypes = [ctypes.c_void_p] -_lib.free_str.restype = None +# _lib.free_str.argtypes = [ctypes.c_void_p] +# _lib.free_str.restype = None -_lib.state_query_json.argtypes = [ctypes.POINTER(WrapState), ctypes.c_char_p, ctypes.c_char_p] -_lib.state_query_json.restype = ctypes.c_void_p +# _lib.state_query_json.argtypes = [ctypes.POINTER(WrapState), ctypes.c_char_p, ctypes.c_char_p] +# _lib.state_query_json.restype = ctypes.c_void_p -_lib.state_apply_ale_action.argtypes = [ctypes.POINTER(WrapState), ctypes.c_int32] -_lib.state_apply_ale_action.restype = ctypes.c_bool +# _lib.state_apply_ale_action.argtypes = [ctypes.POINTER(WrapState), ctypes.c_int32] +# _lib.state_apply_ale_action.restype = ctypes.c_bool -_lib.state_apply_action.argtypes = [ctypes.POINTER(WrapState), ctypes.POINTER(Input)] -_lib.state_apply_action.restype = None +# _lib.state_apply_action.argtypes = [ctypes.POINTER(WrapState), ctypes.POINTER(Input)] +# _lib.state_apply_action.restype = None -_lib.simulator_frame_width.argtypes = [ctypes.POINTER(WrapSimulator)] -_lib.simulator_frame_width.restype = ctypes.c_int32 +# _lib.simulator_frame_width.argtypes = [ctypes.POINTER(WrapSimulator)] +# _lib.simulator_frame_width.restype = ctypes.c_int32 -_lib.simulator_frame_height.argtypes = [ctypes.POINTER(WrapSimulator)] -_lib.simulator_frame_height.restype = ctypes.c_int32 +# _lib.simulator_frame_height.argtypes = [ctypes.POINTER(WrapSimulator)] +# _lib.simulator_frame_height.restype = ctypes.c_int32 -_lib.state_lives.restype = ctypes.c_int32 -_lib.state_score.restype = ctypes.c_int32 +# _lib.state_lives.restype = ctypes.c_int32 +# _lib.state_score.restype = ctypes.c_int32 -_lib.render_current_frame.argtypes = [ctypes.c_void_p, ctypes.c_size_t, ctypes.c_bool, ctypes.c_void_p, ctypes.c_void_p] - #(frame_ptr, size, sim.get_simulator(), self.__state) +# _lib.render_current_frame.argtypes = [ctypes.c_void_p, ctypes.c_size_t, ctypes.c_bool, ctypes.c_void_p, ctypes.c_void_p] +# #(frame_ptr, size, sim.get_simulator(), self.__state) -_lib.state_to_json.argtypes = [ctypes.POINTER(WrapState)] -_lib.state_to_json.restype = ctypes.c_void_p +# _lib.state_to_json.argtypes = [ctypes.POINTER(WrapState)] +# _lib.state_to_json.restype = ctypes.c_void_p -_lib.state_from_json.argtypes = [ctypes.POINTER(WrapSimulator), ctypes.c_char_p] -_lib.state_from_json.restype = ctypes.POINTER(WrapState) +# _lib.state_from_json.argtypes = [ctypes.POINTER(WrapSimulator), ctypes.c_char_p] +# _lib.state_from_json.restype = ctypes.POINTER(WrapState) -_lib.simulator_to_json.argtypes = [ctypes.POINTER(WrapSimulator)] -_lib.simulator_to_json.restype = ctypes.c_void_p +# _lib.simulator_to_json.argtypes = [ctypes.POINTER(WrapSimulator)] +# _lib.simulator_to_json.restype = ctypes.c_void_p -_lib.simulator_from_json.argtypes = [ctypes.POINTER(WrapSimulator), ctypes.c_char_p] -_lib.simulator_from_json.restype = ctypes.POINTER(WrapSimulator) +# _lib.simulator_from_json.argtypes = [ctypes.POINTER(WrapSimulator), ctypes.c_char_p] +# _lib.simulator_from_json.restype = ctypes.POINTER(WrapSimulator) diff --git a/ctoybox/toybox/toybox/toybox.py b/ctoybox/toybox/toybox/toybox.py index eeff13b2..70e2ecc8 100644 --- a/ctoybox/toybox/toybox/toybox.py +++ b/ctoybox/toybox/toybox/toybox.py @@ -1,5 +1,4 @@ from collections import deque -import ctypes import numpy as np from PIL import Image import os @@ -8,28 +7,149 @@ import json try: - # This is for pip install from toybox._native import ffi, lib - _lib = lib - -except: - # deprecated - from toybox.clib import _lib, Input, NOOP, LEFT, RIGHT, UP, DOWN, BUTTON1, BUTTON2 - from toybox.clib import Input, NOOP, LEFT, RIGHT, UP, DOWN, BUTTON1, BUTTON2 - - +except ModuleNotFoundError: + print('Global setup not found...trying local development install...') + platform = platform.system() + lib_env_var = 'LIBCTOYBOX' + lib_dylib = 'libctoybox.dylib' + lib_so = 'libctoybox.so' + + _lib_prefix = os.environ[lib_env_var] if lib_env_var in os.environ else '..' + + if platform == 'Darwin': + _lib_path_debug = os.path.sep.join([_lib_prefix, 'target', 'debug', lib_dylib]) + _lib_path_release = os.path.sep.join([_lib_prefix, 'target', 'release', lib_dylib]) + print('Looking for toybox lib in\n\t%s\nor\n\t%s' % ( + _lib_path_debug, + _lib_path_release + )) + + _lib_ts_release = os.stat(_lib_path_release).st_birthtime \ + if os.path.exists(_lib_path_release) else 0 + _lib_ts_debug = os.stat(_lib_path_debug).st_birthtime \ + if os.path.exists(_lib_path_debug) else 0 + + if (not (_lib_ts_debug or _lib_ts_release)): + raise OSError('%s not found on this machine' % lib_dylib) + + _lib_path = _lib_path_debug if _lib_ts_debug > _lib_ts_release else _lib_path_release + print(_lib_path) + + elif platform == 'Linux': + _lib_path = lib_so + + else: + raise Exception('Unsupported platform for development: %s' % platform) + + try: + from cffi import FFI + ffi = FFI() + with open(os.sep.join([_lib_prefix, 'target', 'ctoybox.h']), 'r') as f: + # directives not supported! + header = '\n'.join([line for line in f.readlines() if not line.startswith('#')]) + ffi.cdef(header) + lib = ffi.dlopen(_lib_path) + except Exception: + raise Exception('Could not load libopenai from path %s. ' % _lib_path + + """If you are on OSX, this may be due the relative path being different + from `target/(target|release)/libopenai.dylib. If you are on Linux, try + prefixing your call with `LD_LIBRARY_PATH=/path/to/library`.""") + + +class Input(): + """An input object represents a game controller having left, right, up, down, and two buttons. + + ALE mapping: + ALE_ACTION_MEANING = { + 0 : "NOOP", + 1 : "FIRE", + 2 : "UP", + 3 : "RIGHT", + 4 : "LEFT", + 5 : "DOWN", + 6 : "UPRIGHT", + 7 : "UPLEFT", + 8 : "DOWNRIGHT", + 9 : "DOWNLEFT", + 10 : "UPFIRE", + 11 : "RIGHTFIRE", + 12 : "LEFTFIRE", + 13 : "DOWNFIRE", + 14 : "UPRIGHTFIRE", + 15 : "UPLEFTFIRE", + 16 : "DOWNRIGHTFIRE", + 17 : "DOWNLEFTFIRE", + } + """ + + _LEFT = "left" + _RIGHT = "right" + _UP = "up" + _DOWN = "down" + _BUTTON1 = "button1" + _BUTTON2 = "button2" + _NOOP = "noop" + + def __init__(self): + self.reset() + + def reset(self): + self.left = False + self.right = False + self.up = False + self.down = False + self.button1 = False + self.button2 = False + + def __str__(self): + return self.__dict__.__str__() + + def __repr__(self): + return self.__dict__.__str__() + + def set_input(self, input_dir, button=_NOOP): + input_dir = input_dir.lower() + button = button.lower() + + # reset all directions + if input_dir == Input._NOOP: + pass + elif input_dir == Input._LEFT: + self.left = True + elif input_dir == Input._RIGHT: + self.right = True + elif input_dir == Input._UP: + self.up = True + elif input_dir == Input._DOWN: + self.down = True + else: + print('input_dir:', input_dir) + assert False + + # reset buttons + if button == Input._NOOP: + pass + elif button == Input._BUTTON1: + self.button1 = True + elif button == Input._BUTTON2: + self.button2 = True + else: + assert False def rust_str(result): txt = ffi.cast("char *", result) #.value.decode('UTF-8') txt = ffi.string(txt).decode('UTF-8') - _lib.free_str(result) + lib.free_str(result) return txt def json_str(js): if type(js) is dict: js = json.dumps(js) + elif type(js) is Input: + js = json.dumps(js.__dict__) elif type(js) is not str: raise ValueError('Unknown json type: %s (only str and dict supported)' % type(js)) return js @@ -37,19 +157,19 @@ def json_str(js): class Simulator(object): def __init__(self, game_name, sim=None): if sim is None: - sim = _lib.simulator_alloc(game_name.encode('utf-8')) + sim = lib.simulator_alloc(game_name.encode('utf-8')) # sim should be a pointer #self.__sim = ctypes.pointer(ctypes.c_int(sim)) self.game_name = game_name self.__sim = sim - self.__width = _lib.simulator_frame_width(sim) - self.__height = _lib.simulator_frame_height(sim) + self.__width = lib.simulator_frame_width(sim) + self.__height = lib.simulator_frame_height(sim) self.deleted = False def __del__(self): if not self.deleted: self.deleted = True - _lib.simulator_free(self.__sim) + lib.simulator_free(self.__sim) self.__sim = None def __enter__(self): @@ -59,7 +179,7 @@ def __exit__(self, exc_type, exc_value, traceback): self.__del__() def set_seed(self, value): - _lib.simulator_seed(self.__sim, value) + lib.simulator_seed(self.__sim, value) def get_frame_width(self): return self.__width @@ -74,22 +194,22 @@ def new_game(self): return State(self) def state_from_json(self, js): - state = _lib.state_from_json(self.get_simulator(), json_str(js).encode('utf-8')) + state = lib.state_from_json(self.get_simulator(), json_str(js).encode('utf-8')) return State(self, state=state) def to_json(self): - json_str = rust_str(_lib.simulator_to_json(self.get_simulator())) + json_str = rust_str(lib.simulator_to_json(self.get_simulator())) return json.loads(str(json_str)) def from_json(self, config_js): old_sim = self.__sim - self.__sim = _lib.simulator_from_json(self.get_simulator(), json_str(config_js).encode('utf-8')) + self.__sim = lib.simulator_from_json(self.get_simulator(), json_str(config_js).encode('utf-8')) del old_sim class State(object): def __init__(self, sim, state=None): - self.__state = state or _lib.state_alloc(sim.get_simulator()) + self.__state = state or lib.state_alloc(sim.get_simulator()) self.game_name = sim.game_name self.deleted = False @@ -99,7 +219,7 @@ def __enter__(self): def __del__(self): if not self.deleted: self.deleted = True - _lib.state_free(self.__state) + lib.state_free(self.__state) self.__state = None def __exit__(self, exc_type, exc_value, traceback): @@ -110,16 +230,16 @@ def get_state(self): return self.__state def lives(self): - return _lib.state_lives(self.__state) + return lib.state_lives(self.__state) def score(self): - return _lib.state_score(self.__state) + return lib.state_score(self.__state) def game_over(self): return self.lives() == 0 def query_json(self, query, args="null"): - txt = rust_str(_lib.state_query_json(self.__state, json_str(query).encode('utf-8'), json_str(args).encode('utf-8'))) + txt = rust_str(lib.state_query_json(self.__state, json_str(query).encode('utf-8'), json_str(args).encode('utf-8'))) try: out = json.loads(txt) except: @@ -139,7 +259,7 @@ def render_frame_color(self, sim): size = h * w * rgba frame = np.zeros(size, dtype='uint8') frame_ptr = frame.ctypes.data_as(ctypes.POINTER(ctypes.c_uint8)) - _lib.render_current_frame(frame_ptr, size, False, sim.get_simulator(), self.__state) + lib.render_current_frame(frame_ptr, size, False, sim.get_simulator(), self.__state) return np.reshape(frame, (h,w,rgba)) def render_frame_rgb(self, sim): @@ -152,11 +272,11 @@ def render_frame_grayscale(self, sim): size = h * w frame = np.zeros(size, dtype='uint8') frame_ptr = frame.ctypes.data_as(ctypes.POINTER(ctypes.c_uint8)) - _lib.render_current_frame(frame_ptr, size, True, sim.get_simulator(), self.__state) + lib.render_current_frame(frame_ptr, size, True, sim.get_simulator(), self.__state) return np.reshape(frame, (h,w,1)) def to_json(self): - json_str = rust_str(_lib.state_to_json(self.__state)) + json_str = rust_str(lib.state_to_json(self.__state)) return json.loads(str(json_str)) class Toybox(object): @@ -182,23 +302,28 @@ def get_width(self): def get_legal_action_set(self): sim = self.rsimulator.get_simulator() - txt = rust_str(_lib.simulator_actions(sim)) + txt = rust_str(lib.simulator_actions(sim)) try: out = json.loads(txt) except: raise ValueError(txt) return out - def apply_ale_action(self, action_int): + def apply_ale_action(self, action_int): + """Takes an integer corresponding to an action, as specified in ALE and applies the action k times, where k is the sticky action constant stored in self.frames_per_action. + """ # implement frameskip(k) by sending the action (k+1) times every time we have an action. for _ in range(self.frames_per_action): - if not _lib.state_apply_ale_action(self.rstate.get_state(), action_int): + if not lib.state_apply_ale_action(self.rstate.get_state(), action_int): raise ValueError("Expected to apply action, but failed: {0}".format(action_int)) def apply_action(self, action_input_obj): + """Takes an Input + """ # implement frameskip(k) by sending the action (k+1) times every time we have an action. for _ in range(self.frames_per_action): - _lib.state_apply_action(self.rstate.get_state(), ctypes.byref(action_input_obj)) + lib.state_apply_action(self.rstate.get_state(), + ffi.new("char []", json_str(action_input_obj).encode('UTF-8') )) def get_state(self): return self.rstate.render_frame(self.rsimulator, self.grayscale) From 07e8a247b1a710b50ae706dbdd73d7c5caf93914 Mon Sep 17 00:00:00 2001 From: Emma Tosch Date: Sat, 16 Mar 2019 11:57:27 -0400 Subject: [PATCH 10/21] updates to frame rendering and human play #43 --- ctoybox/human_play.py | 13 ++-- ctoybox/toybox/toybox/clib.py | 122 -------------------------------- ctoybox/toybox/toybox/toybox.py | 12 ++-- 3 files changed, 15 insertions(+), 132 deletions(-) diff --git a/ctoybox/human_play.py b/ctoybox/human_play.py index d76ec4d7..490a3dfe 100644 --- a/ctoybox/human_play.py +++ b/ctoybox/human_play.py @@ -60,13 +60,14 @@ break key_state = pygame.key.get_pressed() player_input = Input() - player_input.left = key_state[K_LEFT] or key_state[K_a] - player_input.right = key_state[K_RIGHT] or key_state[K_d] - player_input.up = key_state[K_UP] or key_state[K_w] - player_input.down = key_state[K_DOWN] or key_state[K_s] - player_input.button1 = key_state[K_z] or key_state[K_SPACE] - player_input.button2 = key_state[K_x] or key_state[K_RSHIFT] or key_state[K_LSHIFT] + player_input.left = bool(key_state[K_LEFT] or key_state[K_a]) + player_input.right = bool(key_state[K_RIGHT] or key_state[K_d]) + player_input.up = bool(key_state[K_UP] or key_state[K_w]) + player_input.down = bool(key_state[K_DOWN] or key_state[K_s]) + player_input.button1 = bool(key_state[K_z] or key_state[K_SPACE]) + player_input.button2 = bool(key_state[K_x] or key_state[K_RSHIFT] or key_state[K_LSHIFT]) + tb.apply_action(player_input) if args.query is not None: print(args.query, tb.query_state_json(args.query, args.query_args)) diff --git a/ctoybox/toybox/toybox/clib.py b/ctoybox/toybox/toybox/clib.py index a668e4d2..26e1a51d 100644 --- a/ctoybox/toybox/toybox/clib.py +++ b/ctoybox/toybox/toybox/clib.py @@ -64,128 +64,6 @@ # BUTTON1 = "button1" # BUTTON2 = "button2" -# class Input(ctypes.Structure): -# _fields_ = [(LEFT, ctypes.c_bool), -# (RIGHT, ctypes.c_bool), -# (UP, ctypes.c_bool), -# (DOWN, ctypes.c_bool), -# (BUTTON1, ctypes.c_bool), -# (BUTTON2, ctypes.c_bool)] - -# def _set_default(self): -# self.left = False -# self.right = False -# self.up = False -# self.down = False -# self.button1 = False -# self.button2 = False - -# """ -# ALE_ACTION_MEANING = { -# 0 : "NOOP", -# 1 : "FIRE", -# 2 : "UP", -# 3 : "RIGHT", -# 4 : "LEFT", -# 5 : "DOWN", -# 6 : "UPRIGHT", -# 7 : "UPLEFT", -# 8 : "DOWNRIGHT", -# 9 : "DOWNLEFT", -# 10 : "UPFIRE", -# 11 : "RIGHTFIRE", -# 12 : "LEFTFIRE", -# 13 : "DOWNFIRE", -# 14 : "UPRIGHTFIRE", -# 15 : "UPLEFTFIRE", -# 16 : "DOWNRIGHTFIRE", -# 17 : "DOWNLEFTFIRE", -# } -# """ -# def set_ale(self, num): -# if num == 0: -# pass -# elif num == 1: -# self.button1 = True -# elif num == 2: -# self.up = True -# elif num == 3: -# self.right = True -# elif num == 4: -# self.left = True -# elif num == 5: -# self.down = True -# elif num == 6: -# self.up = True -# self.right = True -# elif num == 7: -# self.up = True -# self.left = True -# elif num == 8: -# self.down = True -# self.right = True -# elif num == 9: -# self.down = True -# self.left = True -# elif num == 10: -# self.up = True -# self.button1 = True -# elif num == 11: -# self.right = True -# self.button1 = True -# elif num == 12: -# self.left = True -# self.button1 = True -# elif num == 13: -# self.down = True -# self.button1 = True -# elif num == 14: -# self.up = True -# self.right = True -# self.button1 = True -# elif num == 15: -# self.up = True -# self.left = True -# self.button1 = True -# elif num == 16: -# self.down = True -# self.right = True -# self.button1 = True -# elif num == 17: -# self.down = True -# self.left = True -# self.button1 = True - - -# def set_input(self, input_dir, button=NOOP): -# self._set_default() -# input_dir = input_dir.lower() -# button = button.lower() - -# # reset all directions -# if input_dir == NOOP: -# pass -# elif input_dir == LEFT: -# self.left = True -# elif input_dir == RIGHT: -# self.right = True -# elif input_dir == UP: -# self.up = True -# elif input_dir == DOWN: -# self.down = True -# else: -# print('input_dir:', input_dir) -# assert False - -# # reset buttons -# if button == NOOP: -# pass -# elif button == BUTTON1: -# self.button1 = True -# elif button == BUTTON2: -# self.button2 = True -# else: -# assert False # _lib.simulator_alloc.argtypes = [ctypes.c_char_p] diff --git a/ctoybox/toybox/toybox/toybox.py b/ctoybox/toybox/toybox/toybox.py index 70e2ecc8..494cae6e 100644 --- a/ctoybox/toybox/toybox/toybox.py +++ b/ctoybox/toybox/toybox/toybox.py @@ -95,7 +95,7 @@ def __init__(self): self.reset() def reset(self): - self.left = False + self.left : bool = False self.right = False self.up = False self.down = False @@ -258,7 +258,8 @@ def render_frame_color(self, sim): rgba = 4 size = h * w * rgba frame = np.zeros(size, dtype='uint8') - frame_ptr = frame.ctypes.data_as(ctypes.POINTER(ctypes.c_uint8)) + # frame_ptr = frame.ctypes.data_as(ctypes.POINTER(ctypes.c_uint8)) + frame_ptr = ffi.cast("uint8_t *", frame.ctypes.data) lib.render_current_frame(frame_ptr, size, False, sim.get_simulator(), self.__state) return np.reshape(frame, (h,w,rgba)) @@ -271,7 +272,8 @@ def render_frame_grayscale(self, sim): w = sim.get_frame_width() size = h * w frame = np.zeros(size, dtype='uint8') - frame_ptr = frame.ctypes.data_as(ctypes.POINTER(ctypes.c_uint8)) + # frame_ptr = frame.ctypes.data_as(ctypes.POINTER(ctypes.c_uint8)) + frame_ptr = ffi.cast("uint8_t *", frame.ctypes.data) lib.render_current_frame(frame_ptr, size, True, sim.get_simulator(), self.__state) return np.reshape(frame, (h,w,1)) @@ -322,8 +324,10 @@ def apply_action(self, action_input_obj): """ # implement frameskip(k) by sending the action (k+1) times every time we have an action. for _ in range(self.frames_per_action): + js = json_str(action_input_obj).encode('UTF-8') + print("INPUT JSON", js) lib.state_apply_action(self.rstate.get_state(), - ffi.new("char []", json_str(action_input_obj).encode('UTF-8') )) + ffi.new("char []", js)) def get_state(self): return self.rstate.render_frame(self.rsimulator, self.grayscale) From 0da5d86e9469980cfebec73c1e472fce5a51a93e Mon Sep 17 00:00:00 2001 From: Emma Tosch Date: Sat, 16 Mar 2019 12:04:30 -0400 Subject: [PATCH 11/21] deleted clib, fixed start_python #43 --- ctoybox/start_python | 7 +- ctoybox/toybox/toybox/clib.py | 118 -------------------------------- ctoybox/toybox/toybox/toybox.py | 3 - 3 files changed, 4 insertions(+), 124 deletions(-) delete mode 100644 ctoybox/toybox/toybox/clib.py diff --git a/ctoybox/start_python b/ctoybox/start_python index 89337e37..ddf2c30b 100755 --- a/ctoybox/start_python +++ b/ctoybox/start_python @@ -1,8 +1,9 @@ #!/bin/bash +# RUN THIS command FROM CTOYBOX. #pip3 install -q -r REQUIREMENTS.txt --user -export PYTHONPATH=${PWD}/baselines:${PWD}/toybox:${PYTHONPATH}:${HOME}/toybox/ctoybox/baselines:${HOME}/toybox/ctoybox/toybox -export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${PWD}/../target/release:${HOME}/toybox/target/release:${HOME}/dev/toybox/target/release -export LIBCTOYBOX=${HOME}/dev/Toybox +export PYTHONPATH=${PWD}/baselines:${PWD}/toybox:${PYTHONPATH} +export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${PWD}/../target/release +export LIBCTOYBOX=${PWD}/.. echo "PYTHONPATH $PYTHONPATH" echo "LD_LIBRARY_PATH $LD_LIBRARY_PATH" echo "LIBCTOYBOX $LIBCTOYBOX" diff --git a/ctoybox/toybox/toybox/clib.py b/ctoybox/toybox/toybox/clib.py deleted file mode 100644 index 26e1a51d..00000000 --- a/ctoybox/toybox/toybox/clib.py +++ /dev/null @@ -1,118 +0,0 @@ -# from collections import deque -# import ctypes -# import numpy as np -# from PIL import Image -# import os -# import platform -# import time -# import json - -# platform = platform.system() -# lib_env_var = 'LIBCTOYBOX' -# lib_dylib = 'libctoybox.dylib' -# lib_so = 'libctoybox.so' - - -# if platform == 'Darwin': -# _lib_prefix = os.environ[lib_env_var] if lib_env_var in os.environ else '..' -# _lib_path_debug = os.path.sep.join([_lib_prefix, 'target', 'debug', lib_dylib]) -# _lib_path_release = os.path.sep.join([_lib_prefix, 'target', 'release', lib_dylib]) -# print('Looking for toybox lib in\n\t%s\nor\n\t%s' % ( -# _lib_path_debug, -# _lib_path_release -# )) - -# _lib_ts_release = os.stat(_lib_path_release).st_birthtime \ -# if os.path.exists(_lib_path_release) else 0 -# _lib_ts_debug = os.stat(_lib_path_debug).st_birthtime \ -# if os.path.exists(_lib_path_debug) else 0 - -# if (not (_lib_ts_debug or _lib_ts_release)): -# raise OSError('%s not found on this machine' % lib_dylib) - -# _lib_path = _lib_path_debug if _lib_ts_debug > _lib_ts_release else _lib_path_release -# print(_lib_path) - -# elif platform == 'Linux': -# _lib_path = lib_so - -# else: -# raise Exception('Unsupported platform: %s' % platform) - - -# try: -# _lib = ctypes.CDLL(_lib_path) -# except Exception: -# raise Exception('Could not load libopenai from path %s.' % _lib_path -# + """If you are on OSX, this may be due the relative path being different -# from `target/(target|release)/libopenai.dylib. If you are on Linux, try -# prefixing your call with `LD_LIBRARY_PATH=/path/to/library`.""") - -# class WrapSimulator(ctypes.Structure): -# pass - -# class WrapState(ctypes.Structure): -# pass - - -# # I don't know how actions will be issued, so let's have lots of options available -# NOOP = 'noop' -# LEFT = "left" -# RIGHT = "right" -# UP = "up" -# DOWN = "down" -# BUTTON1 = "button1" -# BUTTON2 = "button2" - - - -# _lib.simulator_alloc.argtypes = [ctypes.c_char_p] -# _lib.simulator_alloc.restype = ctypes.POINTER(WrapSimulator) - -# _lib.simulator_seed.argtypes = [ctypes.POINTER(WrapSimulator), ctypes.c_uint] -# _lib.simulator_seed.restype = None - -# _lib.simulator_is_legal_action.argtypes = [ctypes.POINTER(WrapSimulator), ctypes.c_int32] -# _lib.simulator_is_legal_action.restype = ctypes.c_bool - -# _lib.simulator_actions.argtypes = [ctypes.POINTER(WrapSimulator)] -# _lib.simulator_actions.restype = ctypes.c_void_p - -# _lib.state_alloc.argtypes = [ctypes.POINTER(WrapSimulator)] -# _lib.state_alloc.restype = ctypes.POINTER(WrapState) - -# _lib.free_str.argtypes = [ctypes.c_void_p] -# _lib.free_str.restype = None - -# _lib.state_query_json.argtypes = [ctypes.POINTER(WrapState), ctypes.c_char_p, ctypes.c_char_p] -# _lib.state_query_json.restype = ctypes.c_void_p - -# _lib.state_apply_ale_action.argtypes = [ctypes.POINTER(WrapState), ctypes.c_int32] -# _lib.state_apply_ale_action.restype = ctypes.c_bool - -# _lib.state_apply_action.argtypes = [ctypes.POINTER(WrapState), ctypes.POINTER(Input)] -# _lib.state_apply_action.restype = None - -# _lib.simulator_frame_width.argtypes = [ctypes.POINTER(WrapSimulator)] -# _lib.simulator_frame_width.restype = ctypes.c_int32 - -# _lib.simulator_frame_height.argtypes = [ctypes.POINTER(WrapSimulator)] -# _lib.simulator_frame_height.restype = ctypes.c_int32 - -# _lib.state_lives.restype = ctypes.c_int32 -# _lib.state_score.restype = ctypes.c_int32 - -# _lib.render_current_frame.argtypes = [ctypes.c_void_p, ctypes.c_size_t, ctypes.c_bool, ctypes.c_void_p, ctypes.c_void_p] -# #(frame_ptr, size, sim.get_simulator(), self.__state) - -# _lib.state_to_json.argtypes = [ctypes.POINTER(WrapState)] -# _lib.state_to_json.restype = ctypes.c_void_p - -# _lib.state_from_json.argtypes = [ctypes.POINTER(WrapSimulator), ctypes.c_char_p] -# _lib.state_from_json.restype = ctypes.POINTER(WrapState) - -# _lib.simulator_to_json.argtypes = [ctypes.POINTER(WrapSimulator)] -# _lib.simulator_to_json.restype = ctypes.c_void_p - -# _lib.simulator_from_json.argtypes = [ctypes.POINTER(WrapSimulator), ctypes.c_char_p] -# _lib.simulator_from_json.restype = ctypes.POINTER(WrapSimulator) diff --git a/ctoybox/toybox/toybox/toybox.py b/ctoybox/toybox/toybox/toybox.py index 494cae6e..85ba1433 100644 --- a/ctoybox/toybox/toybox/toybox.py +++ b/ctoybox/toybox/toybox/toybox.py @@ -159,7 +159,6 @@ def __init__(self, game_name, sim=None): if sim is None: sim = lib.simulator_alloc(game_name.encode('utf-8')) # sim should be a pointer - #self.__sim = ctypes.pointer(ctypes.c_int(sim)) self.game_name = game_name self.__sim = sim self.__width = lib.simulator_frame_width(sim) @@ -258,7 +257,6 @@ def render_frame_color(self, sim): rgba = 4 size = h * w * rgba frame = np.zeros(size, dtype='uint8') - # frame_ptr = frame.ctypes.data_as(ctypes.POINTER(ctypes.c_uint8)) frame_ptr = ffi.cast("uint8_t *", frame.ctypes.data) lib.render_current_frame(frame_ptr, size, False, sim.get_simulator(), self.__state) return np.reshape(frame, (h,w,rgba)) @@ -272,7 +270,6 @@ def render_frame_grayscale(self, sim): w = sim.get_frame_width() size = h * w frame = np.zeros(size, dtype='uint8') - # frame_ptr = frame.ctypes.data_as(ctypes.POINTER(ctypes.c_uint8)) frame_ptr = ffi.cast("uint8_t *", frame.ctypes.data) lib.render_current_frame(frame_ptr, size, True, sim.get_simulator(), self.__state) return np.reshape(frame, (h,w,1)) From ba52003a207a366f74214bde8c7c8bbc27f4a968 Mon Sep 17 00:00:00 2001 From: Emma Tosch Date: Sat, 16 Mar 2019 12:33:20 -0400 Subject: [PATCH 12/21] cargo fmt, delete input struct in lib --- ctoybox/human_play_config.json | 121 +++ ctoybox/human_play_state.json | 1586 ++++++++++++++++++++++++++++++++ ctoybox/src/core.rs | 6 +- ctoybox/src/lib.rs | 2 - 4 files changed, 1711 insertions(+), 4 deletions(-) create mode 100644 ctoybox/human_play_config.json create mode 100644 ctoybox/human_play_state.json diff --git a/ctoybox/human_play_config.json b/ctoybox/human_play_config.json new file mode 100644 index 00000000..a129dc3c --- /dev/null +++ b/ctoybox/human_play_config.json @@ -0,0 +1,121 @@ +{ + "bg_color": { + "a": 255, + "b": 0, + "g": 0, + "r": 0 + }, + "board": [ + "c========================c======", + "= = = = = = = =", + "= = = = = = = =", + "= = = = = = = =", + "= = = = = = = =", + "= = = = = = = =", + "================================", + "= = = = = = = =", + "= = = = = = = =", + "= = = = = = = =", + "= = = = = = = =", + "= = = = = = = =", + "================================", + "= = = = = p", + "= = = = = p", + "= = = = = p", + "= = = = = p", + "= = = = = p", + "===============================p", + "= = = = = =", + "= = = = = =", + "= = = = = =", + "= = = = = =", + "= = = = = =", + "c========================c======", + "= = = = = =", + "= = = = = =", + "= = = = = =", + "= = = = = =", + "= = = = = =", + "================================" + ], + "box_bonus": 50, + "chase_score_bonus": 100, + "chase_time": 300, + "default_board_bugs": true, + "enemies": [ + { + "EnemyLookupAI": { + "default_route_index": 0, + "next": 0 + } + }, + { + "EnemyLookupAI": { + "default_route_index": 1, + "next": 0 + } + }, + { + "EnemyLookupAI": { + "default_route_index": 2, + "next": 0 + } + }, + { + "EnemyLookupAI": { + "default_route_index": 3, + "next": 0 + } + }, + { + "EnemyLookupAI": { + "default_route_index": 4, + "next": 0 + } + } + ], + "enemy_color": { + "a": 255, + "b": 100, + "g": 50, + "r": 255 + }, + "inner_painted_color": { + "a": 255, + "b": 0, + "g": 255, + "r": 255 + }, + "jump_time": 75, + "painted_color": { + "a": 255, + "b": 30, + "g": 255, + "r": 255 + }, + "player_color": { + "a": 255, + "b": 153, + "g": 255, + "r": 255 + }, + "player_start": { + "tx": 31, + "ty": 15 + }, + "rand": { + "state": [ + 1817879012901901412, + 10917585336602961851 + ] + }, + "render_images": true, + "start_jumps": 4, + "start_lives": 3, + "unpainted_color": { + "a": 255, + "b": 211, + "g": 0, + "r": 148 + } +} diff --git a/ctoybox/human_play_state.json b/ctoybox/human_play_state.json new file mode 100644 index 00000000..c7f9a6cf --- /dev/null +++ b/ctoybox/human_play_state.json @@ -0,0 +1,1586 @@ +{ + "board": { + "boxes": [ + { + "bottom_right": { + "tx": 19, + "ty": 30 + }, + "painted": false, + "top_left": { + "tx": 12, + "ty": 24 + }, + "triggers_chase": false + }, + { + "bottom_right": { + "tx": 14, + "ty": 6 + }, + "painted": false, + "top_left": { + "tx": 10, + "ty": 0 + }, + "triggers_chase": false + }, + { + "bottom_right": { + "tx": 31, + "ty": 24 + }, + "painted": false, + "top_left": { + "tx": 26, + "ty": 18 + }, + "triggers_chase": false + }, + { + "bottom_right": { + "tx": 17, + "ty": 24 + }, + "painted": false, + "top_left": { + "tx": 14, + "ty": 18 + }, + "triggers_chase": false + }, + { + "bottom_right": { + "tx": 28, + "ty": 18 + }, + "painted": false, + "top_left": { + "tx": 20, + "ty": 12 + }, + "triggers_chase": false + }, + { + "bottom_right": { + "tx": 19, + "ty": 12 + }, + "painted": false, + "top_left": { + "tx": 12, + "ty": 6 + }, + "triggers_chase": false + }, + { + "bottom_right": { + "tx": 12, + "ty": 12 + }, + "painted": false, + "top_left": { + "tx": 9, + "ty": 6 + }, + "triggers_chase": false + }, + { + "bottom_right": { + "tx": 31, + "ty": 12 + }, + "painted": false, + "top_left": { + "tx": 27, + "ty": 6 + }, + "triggers_chase": false + }, + { + "bottom_right": { + "tx": 31, + "ty": 6 + }, + "painted": false, + "top_left": { + "tx": 25, + "ty": 0 + }, + "triggers_chase": true + }, + { + "bottom_right": { + "tx": 6, + "ty": 6 + }, + "painted": false, + "top_left": { + "tx": 0, + "ty": 0 + }, + "triggers_chase": true + }, + { + "bottom_right": { + "tx": 5, + "ty": 24 + }, + "painted": false, + "top_left": { + "tx": 0, + "ty": 18 + }, + "triggers_chase": false + }, + { + "bottom_right": { + "tx": 27, + "ty": 12 + }, + "painted": false, + "top_left": { + "tx": 22, + "ty": 6 + }, + "triggers_chase": false + }, + { + "bottom_right": { + "tx": 3, + "ty": 18 + }, + "painted": false, + "top_left": { + "tx": 0, + "ty": 12 + }, + "triggers_chase": false + }, + { + "bottom_right": { + "tx": 6, + "ty": 30 + }, + "painted": false, + "top_left": { + "tx": 0, + "ty": 24 + }, + "triggers_chase": true + }, + { + "bottom_right": { + "tx": 14, + "ty": 24 + }, + "painted": false, + "top_left": { + "tx": 5, + "ty": 18 + }, + "triggers_chase": false + }, + { + "bottom_right": { + "tx": 22, + "ty": 12 + }, + "painted": false, + "top_left": { + "tx": 19, + "ty": 6 + }, + "triggers_chase": false + }, + { + "bottom_right": { + "tx": 25, + "ty": 30 + }, + "painted": false, + "top_left": { + "tx": 19, + "ty": 24 + }, + "triggers_chase": false + }, + { + "bottom_right": { + "tx": 17, + "ty": 6 + }, + "painted": false, + "top_left": { + "tx": 14, + "ty": 0 + }, + "triggers_chase": false + }, + { + "bottom_right": { + "tx": 12, + "ty": 30 + }, + "painted": false, + "top_left": { + "tx": 6, + "ty": 24 + }, + "triggers_chase": false + }, + { + "bottom_right": { + "tx": 31, + "ty": 30 + }, + "painted": false, + "top_left": { + "tx": 25, + "ty": 24 + }, + "triggers_chase": true + }, + { + "bottom_right": { + "tx": 26, + "ty": 24 + }, + "painted": false, + "top_left": { + "tx": 17, + "ty": 18 + }, + "triggers_chase": false + }, + { + "bottom_right": { + "tx": 11, + "ty": 18 + }, + "painted": false, + "top_left": { + "tx": 3, + "ty": 12 + }, + "triggers_chase": false + }, + { + "bottom_right": { + "tx": 31, + "ty": 18 + }, + "painted": false, + "top_left": { + "tx": 28, + "ty": 12 + }, + "triggers_chase": false + }, + { + "bottom_right": { + "tx": 4, + "ty": 12 + }, + "painted": false, + "top_left": { + "tx": 0, + "ty": 6 + }, + "triggers_chase": false + }, + { + "bottom_right": { + "tx": 25, + "ty": 6 + }, + "painted": false, + "top_left": { + "tx": 21, + "ty": 0 + }, + "triggers_chase": false + }, + { + "bottom_right": { + "tx": 21, + "ty": 6 + }, + "painted": false, + "top_left": { + "tx": 17, + "ty": 0 + }, + "triggers_chase": false + }, + { + "bottom_right": { + "tx": 20, + "ty": 18 + }, + "painted": false, + "top_left": { + "tx": 11, + "ty": 12 + }, + "triggers_chase": false + }, + { + "bottom_right": { + "tx": 10, + "ty": 6 + }, + "painted": false, + "top_left": { + "tx": 6, + "ty": 0 + }, + "triggers_chase": false + }, + { + "bottom_right": { + "tx": 9, + "ty": 12 + }, + "painted": false, + "top_left": { + "tx": 4, + "ty": 6 + }, + "triggers_chase": false + } + ], + "chase_junctions": [ + 25, + 793, + 768, + 0 + ], + "height": 31, + "junctions": [ + 223, + 780, + 10, + 991, + 403, + 602, + 590, + 217, + 404, + 204, + 972, + 201, + 219, + 25, + 579, + 0, + 587, + 576, + 214, + 384, + 768, + 785, + 581, + 198, + 202, + 211, + 787, + 782, + 14, + 979, + 388, + 415, + 774, + 793, + 773, + 794, + 593, + 387, + 604, + 206, + 209, + 213, + 412, + 960, + 396, + 966, + 192, + 21, + 393, + 17, + 985, + 799, + 395, + 607, + 31, + 6, + 196, + 596, + 411, + 406 + ], + "tiles": [ + [ + "ChaseMarker", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "ChaseMarker", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted" + ], + [ + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted" + ], + [ + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted" + ], + [ + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted" + ], + [ + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted" + ], + [ + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted" + ], + [ + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted" + ], + [ + "Unpainted", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Unpainted" + ], + [ + "Unpainted", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Unpainted" + ], + [ + "Unpainted", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Unpainted" + ], + [ + "Unpainted", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Unpainted" + ], + [ + "Unpainted", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Unpainted" + ], + [ + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted" + ], + [ + "Unpainted", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Painted" + ], + [ + "Unpainted", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Painted" + ], + [ + "Unpainted", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Painted" + ], + [ + "Unpainted", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Painted" + ], + [ + "Unpainted", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Painted" + ], + [ + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Painted" + ], + [ + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted" + ], + [ + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted" + ], + [ + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted" + ], + [ + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted" + ], + [ + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted" + ], + [ + "ChaseMarker", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "ChaseMarker", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted" + ], + [ + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted" + ], + [ + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted" + ], + [ + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted" + ], + [ + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted" + ], + [ + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted", + "Empty", + "Empty", + "Empty", + "Empty", + "Empty", + "Unpainted" + ], + [ + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted", + "Unpainted" + ] + ], + "width": 32 + }, + "chase_timer": 0, + "enemies": [ + { + "ai": { + "EnemyLookupAI": { + "default_route_index": 0, + "next": 0 + } + }, + "caught": false, + "history": [], + "position": { + "x": 0, + "y": 0 + }, + "speed": 8, + "step": null + }, + { + "ai": { + "EnemyLookupAI": { + "default_route_index": 1, + "next": 0 + } + }, + "caught": false, + "history": [], + "position": { + "x": 0, + "y": 0 + }, + "speed": 8, + "step": null + }, + { + "ai": { + "EnemyLookupAI": { + "default_route_index": 2, + "next": 0 + } + }, + "caught": false, + "history": [], + "position": { + "x": 448, + "y": 0 + }, + "speed": 8, + "step": null + }, + { + "ai": { + "EnemyLookupAI": { + "default_route_index": 3, + "next": 0 + } + }, + "caught": false, + "history": [], + "position": { + "x": 0, + "y": 2000 + }, + "speed": 8, + "step": null + }, + { + "ai": { + "EnemyLookupAI": { + "default_route_index": 4, + "next": 0 + } + }, + "caught": false, + "history": [], + "position": { + "x": 576, + "y": 2400 + }, + "speed": 8, + "step": null + } + ], + "jump_timer": 0, + "jumps": 4, + "lives": 3, + "player": { + "ai": "Player", + "caught": false, + "history": [ + 607 + ], + "position": { + "x": 1984, + "y": 1200 + }, + "speed": 8, + "step": null + }, + "rand": { + "state": [ + 12735464349504863263, + 9270897318777222480 + ] + }, + "score": 0 +} diff --git a/ctoybox/src/core.rs b/ctoybox/src/core.rs index 96711d58..048e291f 100644 --- a/ctoybox/src/core.rs +++ b/ctoybox/src/core.rs @@ -222,9 +222,11 @@ pub extern "C" fn state_apply_action(state_ptr: *mut WrapState, input_ptr: *cons }; let input_str = unsafe { assert!(!input_ptr.is_null()); - CStr::from_ptr(input_ptr).to_str().expect("Could not convert input json str to UTF-8") + CStr::from_ptr(input_ptr) + .to_str() + .expect("Could not convert input json str to UTF-8") }; - let input : Input = serde_json::from_str(input_str).expect("Could not convert input to JSON"); + let input: Input = serde_json::from_str(input_str).expect("Could not convert input to JSON"); state.update_mut(input); } diff --git a/ctoybox/src/lib.rs b/ctoybox/src/lib.rs index 6870f63f..f58c1217 100644 --- a/ctoybox/src/lib.rs +++ b/ctoybox/src/lib.rs @@ -22,5 +22,3 @@ pub struct WrapState { mod core; pub use core::*; - -pub struct Input; \ No newline at end of file From c01563adf3d54326aef7c528b510b8cdcab54c77 Mon Sep 17 00:00:00 2001 From: Emma Tosch Date: Sat, 16 Mar 2019 12:33:49 -0400 Subject: [PATCH 13/21] extra crap --- ctoybox/human_play_config.json | 121 --- ctoybox/human_play_state.json | 1586 -------------------------------- 2 files changed, 1707 deletions(-) delete mode 100644 ctoybox/human_play_config.json delete mode 100644 ctoybox/human_play_state.json diff --git a/ctoybox/human_play_config.json b/ctoybox/human_play_config.json deleted file mode 100644 index a129dc3c..00000000 --- a/ctoybox/human_play_config.json +++ /dev/null @@ -1,121 +0,0 @@ -{ - "bg_color": { - "a": 255, - "b": 0, - "g": 0, - "r": 0 - }, - "board": [ - "c========================c======", - "= = = = = = = =", - "= = = = = = = =", - "= = = = = = = =", - "= = = = = = = =", - "= = = = = = = =", - "================================", - "= = = = = = = =", - "= = = = = = = =", - "= = = = = = = =", - "= = = = = = = =", - "= = = = = = = =", - "================================", - "= = = = = p", - "= = = = = p", - "= = = = = p", - "= = = = = p", - "= = = = = p", - "===============================p", - "= = = = = =", - "= = = = = =", - "= = = = = =", - "= = = = = =", - "= = = = = =", - "c========================c======", - "= = = = = =", - "= = = = = =", - "= = = = = =", - "= = = = = =", - "= = = = = =", - "================================" - ], - "box_bonus": 50, - "chase_score_bonus": 100, - "chase_time": 300, - "default_board_bugs": true, - "enemies": [ - { - "EnemyLookupAI": { - "default_route_index": 0, - "next": 0 - } - }, - { - "EnemyLookupAI": { - "default_route_index": 1, - "next": 0 - } - }, - { - "EnemyLookupAI": { - "default_route_index": 2, - "next": 0 - } - }, - { - "EnemyLookupAI": { - "default_route_index": 3, - "next": 0 - } - }, - { - "EnemyLookupAI": { - "default_route_index": 4, - "next": 0 - } - } - ], - "enemy_color": { - "a": 255, - "b": 100, - "g": 50, - "r": 255 - }, - "inner_painted_color": { - "a": 255, - "b": 0, - "g": 255, - "r": 255 - }, - "jump_time": 75, - "painted_color": { - "a": 255, - "b": 30, - "g": 255, - "r": 255 - }, - "player_color": { - "a": 255, - "b": 153, - "g": 255, - "r": 255 - }, - "player_start": { - "tx": 31, - "ty": 15 - }, - "rand": { - "state": [ - 1817879012901901412, - 10917585336602961851 - ] - }, - "render_images": true, - "start_jumps": 4, - "start_lives": 3, - "unpainted_color": { - "a": 255, - "b": 211, - "g": 0, - "r": 148 - } -} diff --git a/ctoybox/human_play_state.json b/ctoybox/human_play_state.json deleted file mode 100644 index c7f9a6cf..00000000 --- a/ctoybox/human_play_state.json +++ /dev/null @@ -1,1586 +0,0 @@ -{ - "board": { - "boxes": [ - { - "bottom_right": { - "tx": 19, - "ty": 30 - }, - "painted": false, - "top_left": { - "tx": 12, - "ty": 24 - }, - "triggers_chase": false - }, - { - "bottom_right": { - "tx": 14, - "ty": 6 - }, - "painted": false, - "top_left": { - "tx": 10, - "ty": 0 - }, - "triggers_chase": false - }, - { - "bottom_right": { - "tx": 31, - "ty": 24 - }, - "painted": false, - "top_left": { - "tx": 26, - "ty": 18 - }, - "triggers_chase": false - }, - { - "bottom_right": { - "tx": 17, - "ty": 24 - }, - "painted": false, - "top_left": { - "tx": 14, - "ty": 18 - }, - "triggers_chase": false - }, - { - "bottom_right": { - "tx": 28, - "ty": 18 - }, - "painted": false, - "top_left": { - "tx": 20, - "ty": 12 - }, - "triggers_chase": false - }, - { - "bottom_right": { - "tx": 19, - "ty": 12 - }, - "painted": false, - "top_left": { - "tx": 12, - "ty": 6 - }, - "triggers_chase": false - }, - { - "bottom_right": { - "tx": 12, - "ty": 12 - }, - "painted": false, - "top_left": { - "tx": 9, - "ty": 6 - }, - "triggers_chase": false - }, - { - "bottom_right": { - "tx": 31, - "ty": 12 - }, - "painted": false, - "top_left": { - "tx": 27, - "ty": 6 - }, - "triggers_chase": false - }, - { - "bottom_right": { - "tx": 31, - "ty": 6 - }, - "painted": false, - "top_left": { - "tx": 25, - "ty": 0 - }, - "triggers_chase": true - }, - { - "bottom_right": { - "tx": 6, - "ty": 6 - }, - "painted": false, - "top_left": { - "tx": 0, - "ty": 0 - }, - "triggers_chase": true - }, - { - "bottom_right": { - "tx": 5, - "ty": 24 - }, - "painted": false, - "top_left": { - "tx": 0, - "ty": 18 - }, - "triggers_chase": false - }, - { - "bottom_right": { - "tx": 27, - "ty": 12 - }, - "painted": false, - "top_left": { - "tx": 22, - "ty": 6 - }, - "triggers_chase": false - }, - { - "bottom_right": { - "tx": 3, - "ty": 18 - }, - "painted": false, - "top_left": { - "tx": 0, - "ty": 12 - }, - "triggers_chase": false - }, - { - "bottom_right": { - "tx": 6, - "ty": 30 - }, - "painted": false, - "top_left": { - "tx": 0, - "ty": 24 - }, - "triggers_chase": true - }, - { - "bottom_right": { - "tx": 14, - "ty": 24 - }, - "painted": false, - "top_left": { - "tx": 5, - "ty": 18 - }, - "triggers_chase": false - }, - { - "bottom_right": { - "tx": 22, - "ty": 12 - }, - "painted": false, - "top_left": { - "tx": 19, - "ty": 6 - }, - "triggers_chase": false - }, - { - "bottom_right": { - "tx": 25, - "ty": 30 - }, - "painted": false, - "top_left": { - "tx": 19, - "ty": 24 - }, - "triggers_chase": false - }, - { - "bottom_right": { - "tx": 17, - "ty": 6 - }, - "painted": false, - "top_left": { - "tx": 14, - "ty": 0 - }, - "triggers_chase": false - }, - { - "bottom_right": { - "tx": 12, - "ty": 30 - }, - "painted": false, - "top_left": { - "tx": 6, - "ty": 24 - }, - "triggers_chase": false - }, - { - "bottom_right": { - "tx": 31, - "ty": 30 - }, - "painted": false, - "top_left": { - "tx": 25, - "ty": 24 - }, - "triggers_chase": true - }, - { - "bottom_right": { - "tx": 26, - "ty": 24 - }, - "painted": false, - "top_left": { - "tx": 17, - "ty": 18 - }, - "triggers_chase": false - }, - { - "bottom_right": { - "tx": 11, - "ty": 18 - }, - "painted": false, - "top_left": { - "tx": 3, - "ty": 12 - }, - "triggers_chase": false - }, - { - "bottom_right": { - "tx": 31, - "ty": 18 - }, - "painted": false, - "top_left": { - "tx": 28, - "ty": 12 - }, - "triggers_chase": false - }, - { - "bottom_right": { - "tx": 4, - "ty": 12 - }, - "painted": false, - "top_left": { - "tx": 0, - "ty": 6 - }, - "triggers_chase": false - }, - { - "bottom_right": { - "tx": 25, - "ty": 6 - }, - "painted": false, - "top_left": { - "tx": 21, - "ty": 0 - }, - "triggers_chase": false - }, - { - "bottom_right": { - "tx": 21, - "ty": 6 - }, - "painted": false, - "top_left": { - "tx": 17, - "ty": 0 - }, - "triggers_chase": false - }, - { - "bottom_right": { - "tx": 20, - "ty": 18 - }, - "painted": false, - "top_left": { - "tx": 11, - "ty": 12 - }, - "triggers_chase": false - }, - { - "bottom_right": { - "tx": 10, - "ty": 6 - }, - "painted": false, - "top_left": { - "tx": 6, - "ty": 0 - }, - "triggers_chase": false - }, - { - "bottom_right": { - "tx": 9, - "ty": 12 - }, - "painted": false, - "top_left": { - "tx": 4, - "ty": 6 - }, - "triggers_chase": false - } - ], - "chase_junctions": [ - 25, - 793, - 768, - 0 - ], - "height": 31, - "junctions": [ - 223, - 780, - 10, - 991, - 403, - 602, - 590, - 217, - 404, - 204, - 972, - 201, - 219, - 25, - 579, - 0, - 587, - 576, - 214, - 384, - 768, - 785, - 581, - 198, - 202, - 211, - 787, - 782, - 14, - 979, - 388, - 415, - 774, - 793, - 773, - 794, - 593, - 387, - 604, - 206, - 209, - 213, - 412, - 960, - 396, - 966, - 192, - 21, - 393, - 17, - 985, - 799, - 395, - 607, - 31, - 6, - 196, - 596, - 411, - 406 - ], - "tiles": [ - [ - "ChaseMarker", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "ChaseMarker", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted" - ], - [ - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted" - ], - [ - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted" - ], - [ - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted" - ], - [ - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted" - ], - [ - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted" - ], - [ - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted" - ], - [ - "Unpainted", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Unpainted" - ], - [ - "Unpainted", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Unpainted" - ], - [ - "Unpainted", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Unpainted" - ], - [ - "Unpainted", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Unpainted" - ], - [ - "Unpainted", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Unpainted" - ], - [ - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted" - ], - [ - "Unpainted", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Painted" - ], - [ - "Unpainted", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Painted" - ], - [ - "Unpainted", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Painted" - ], - [ - "Unpainted", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Painted" - ], - [ - "Unpainted", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Painted" - ], - [ - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Painted" - ], - [ - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted" - ], - [ - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted" - ], - [ - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted" - ], - [ - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted" - ], - [ - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted" - ], - [ - "ChaseMarker", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "ChaseMarker", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted" - ], - [ - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted" - ], - [ - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted" - ], - [ - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted" - ], - [ - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted" - ], - [ - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted", - "Empty", - "Empty", - "Empty", - "Empty", - "Empty", - "Unpainted" - ], - [ - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted", - "Unpainted" - ] - ], - "width": 32 - }, - "chase_timer": 0, - "enemies": [ - { - "ai": { - "EnemyLookupAI": { - "default_route_index": 0, - "next": 0 - } - }, - "caught": false, - "history": [], - "position": { - "x": 0, - "y": 0 - }, - "speed": 8, - "step": null - }, - { - "ai": { - "EnemyLookupAI": { - "default_route_index": 1, - "next": 0 - } - }, - "caught": false, - "history": [], - "position": { - "x": 0, - "y": 0 - }, - "speed": 8, - "step": null - }, - { - "ai": { - "EnemyLookupAI": { - "default_route_index": 2, - "next": 0 - } - }, - "caught": false, - "history": [], - "position": { - "x": 448, - "y": 0 - }, - "speed": 8, - "step": null - }, - { - "ai": { - "EnemyLookupAI": { - "default_route_index": 3, - "next": 0 - } - }, - "caught": false, - "history": [], - "position": { - "x": 0, - "y": 2000 - }, - "speed": 8, - "step": null - }, - { - "ai": { - "EnemyLookupAI": { - "default_route_index": 4, - "next": 0 - } - }, - "caught": false, - "history": [], - "position": { - "x": 576, - "y": 2400 - }, - "speed": 8, - "step": null - } - ], - "jump_timer": 0, - "jumps": 4, - "lives": 3, - "player": { - "ai": "Player", - "caught": false, - "history": [ - 607 - ], - "position": { - "x": 1984, - "y": 1200 - }, - "speed": 8, - "step": null - }, - "rand": { - "state": [ - 12735464349504863263, - 9270897318777222480 - ] - }, - "score": 0 -} From 8079e82552f8ddcc2ab02c3fc1f76734e6a81b4a Mon Sep 17 00:00:00 2001 From: Emma Tosch Date: Sat, 16 Mar 2019 13:20:34 -0400 Subject: [PATCH 14/21] type annotation caused travis failure #43 --- ctoybox/toybox/toybox/toybox.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ctoybox/toybox/toybox/toybox.py b/ctoybox/toybox/toybox/toybox.py index 3064d4df..eda1c93f 100644 --- a/ctoybox/toybox/toybox/toybox.py +++ b/ctoybox/toybox/toybox/toybox.py @@ -95,7 +95,7 @@ def __init__(self): self.reset() def reset(self): - self.left : bool = False + self.left = False self.right = False self.up = False self.down = False From 0c7fd582971fe72c0bc6aaba4aea7e7de7bf0e11 Mon Sep 17 00:00:00 2001 From: Emma Tosch Date: Sat, 16 Mar 2019 13:34:34 -0400 Subject: [PATCH 15/21] ModuleNotFound error not available on travis --- ctoybox/toybox/toybox/toybox.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ctoybox/toybox/toybox/toybox.py b/ctoybox/toybox/toybox/toybox.py index eda1c93f..e5cbfd0f 100644 --- a/ctoybox/toybox/toybox/toybox.py +++ b/ctoybox/toybox/toybox/toybox.py @@ -8,7 +8,8 @@ try: from toybox._native import ffi, lib -except ModuleNotFoundError: +except: + # should be ModuleNotFoundError, but this is not available on the version of python on travis print('Global setup not found...trying local development install...') platform = platform.system() lib_env_var = 'LIBCTOYBOX' From 506528b37320c380b96d378d6e5ab5b18bf52b24 Mon Sep 17 00:00:00 2001 From: Emma Tosch Date: Sat, 16 Mar 2019 13:43:35 -0400 Subject: [PATCH 16/21] added cffi to requirements and call that in start_python #43 --- ctoybox/REQUIREMENTS.txt | 1 + ctoybox/start_python | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ctoybox/REQUIREMENTS.txt b/ctoybox/REQUIREMENTS.txt index fa52e575..de880776 100644 --- a/ctoybox/REQUIREMENTS.txt +++ b/ctoybox/REQUIREMENTS.txt @@ -2,4 +2,5 @@ tensorflow gym[atari] tensorboard pygame +cffi diff --git a/ctoybox/start_python b/ctoybox/start_python index ddf2c30b..2ccb5d8e 100755 --- a/ctoybox/start_python +++ b/ctoybox/start_python @@ -1,6 +1,6 @@ #!/bin/bash # RUN THIS command FROM CTOYBOX. -#pip3 install -q -r REQUIREMENTS.txt --user +pip3 install -q -r REQUIREMENTS.txt --user export PYTHONPATH=${PWD}/baselines:${PWD}/toybox:${PYTHONPATH} export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${PWD}/../target/release export LIBCTOYBOX=${PWD}/.. From 92e154c5b57dc251a59030d34d381d2bc8a02e3e Mon Sep 17 00:00:00 2001 From: Emma Tosch Date: Sat, 16 Mar 2019 15:05:41 -0400 Subject: [PATCH 17/21] atari env update, downstream input issues #43 --- ctoybox/toybox/toybox/envs/atari/constants.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/ctoybox/toybox/toybox/envs/atari/constants.py b/ctoybox/toybox/toybox/envs/atari/constants.py index 76916bc7..c4799276 100644 --- a/ctoybox/toybox/toybox/envs/atari/constants.py +++ b/ctoybox/toybox/toybox/envs/atari/constants.py @@ -1,17 +1,16 @@ -from toybox.toybox import NOOP, UP, RIGHT, LEFT, DOWN, BUTTON1 -from toybox.clib import Input +from toybox.toybox import Input -NOOP_STR = NOOP.upper() +NOOP_STR = Input.NOOP.upper() FIRE_STR = "FIRE" -UP_STR = UP.upper() -RIGHT_STR = RIGHT.upper() -LEFT_STR = LEFT.upper() -DOWN_STR = DOWN.upper() +UP_STR = Input.UP.upper() +RIGHT_STR = Input.RIGHT.upper() +LEFT_STR = Input.LEFT.upper() +DOWN_STR = Input.DOWN.upper() UPFIRE_STR = "UPFIRE" RIGHTFIRE_STR = "RIGHTFIRE" LEFTFIRE_STR = "LEFTFIRE" DOWNFIRE_STR = "DOWNFIRE" -BUTTON1_STR = BUTTON1.upper() +BUTTON1_STR = Input.BUTTON1.upper() # Copied from, and required by, baselines ACTION_MEANING = { @@ -35,4 +34,4 @@ 17 : "DOWNLEFTFIRE", } -ACTION_LOOKUP = { v : k for (k, v) in ACTION_MEANING.items() } \ No newline at end of file +ACTION_LOOKUP = { v : k for (k, v) in ACTION_MEANING.items() } From c58b8482f4b2e813ed9522807a8d5ba48d0f9758 Mon Sep 17 00:00:00 2001 From: Emma Tosch Date: Sat, 16 Mar 2019 15:14:32 -0400 Subject: [PATCH 18/21] update to constants; name in Input wrong #43 --- ctoybox/toybox/toybox/envs/atari/constants.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ctoybox/toybox/toybox/envs/atari/constants.py b/ctoybox/toybox/toybox/envs/atari/constants.py index c4799276..a34be6e3 100644 --- a/ctoybox/toybox/toybox/envs/atari/constants.py +++ b/ctoybox/toybox/toybox/envs/atari/constants.py @@ -1,16 +1,16 @@ from toybox.toybox import Input -NOOP_STR = Input.NOOP.upper() +NOOP_STR = Input._NOOP.upper() FIRE_STR = "FIRE" -UP_STR = Input.UP.upper() -RIGHT_STR = Input.RIGHT.upper() -LEFT_STR = Input.LEFT.upper() -DOWN_STR = Input.DOWN.upper() +UP_STR = Input._UP.upper() +RIGHT_STR = Input._RIGHT.upper() +LEFT_STR = Input._LEFT.upper() +DOWN_STR = Input._DOWN.upper() UPFIRE_STR = "UPFIRE" RIGHTFIRE_STR = "RIGHTFIRE" LEFTFIRE_STR = "LEFTFIRE" DOWNFIRE_STR = "DOWNFIRE" -BUTTON1_STR = Input.BUTTON1.upper() +BUTTON1_STR = Input._BUTTON1.upper() # Copied from, and required by, baselines ACTION_MEANING = { From 3ec668e56be9e9cd8a2ec59db89f9a0d92503efa Mon Sep 17 00:00:00 2001 From: Emma Tosch Date: Sat, 16 Mar 2019 17:34:01 -0400 Subject: [PATCH 19/21] updated with requested changes --- ctoybox/human_play.py | 2 ++ ctoybox/src/core.rs | 2 +- ctoybox/toybox/setup.py | 2 +- ctoybox/toybox/toybox/toybox.py | 4 ++-- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ctoybox/human_play.py b/ctoybox/human_play.py index 490a3dfe..80a59f1c 100644 --- a/ctoybox/human_play.py +++ b/ctoybox/human_play.py @@ -61,6 +61,8 @@ key_state = pygame.key.get_pressed() player_input = Input() + # Explicitly casting to bools because in some versions, the RHS gets converted + # to ints, causing problems when we load into the associated rust structs. player_input.left = bool(key_state[K_LEFT] or key_state[K_a]) player_input.right = bool(key_state[K_RIGHT] or key_state[K_d]) player_input.up = bool(key_state[K_UP] or key_state[K_w]) diff --git a/ctoybox/src/core.rs b/ctoybox/src/core.rs index 048e291f..c5efdaee 100644 --- a/ctoybox/src/core.rs +++ b/ctoybox/src/core.rs @@ -224,7 +224,7 @@ pub extern "C" fn state_apply_action(state_ptr: *mut WrapState, input_ptr: *cons assert!(!input_ptr.is_null()); CStr::from_ptr(input_ptr) .to_str() - .expect("Could not convert input json str to UTF-8") + .expect("Could not create input from UTF-8") }; let input: Input = serde_json::from_str(input_str).expect("Could not convert input to JSON"); state.update_mut(input); diff --git a/ctoybox/toybox/setup.py b/ctoybox/toybox/setup.py index bbda43f3..617082b9 100644 --- a/ctoybox/toybox/setup.py +++ b/ctoybox/toybox/setup.py @@ -17,7 +17,7 @@ def build_native(spec): setup( name='toybox', - version='0.0.1', + version='0.1.0', packages=['toybox', 'toybox.envs', 'toybox.interventions', 'toybox.sample_tests'], zip_safe=False, platforms='any', diff --git a/ctoybox/toybox/toybox/toybox.py b/ctoybox/toybox/toybox/toybox.py index e5cbfd0f..a8578ea4 100644 --- a/ctoybox/toybox/toybox/toybox.py +++ b/ctoybox/toybox/toybox/toybox.py @@ -52,9 +52,9 @@ ffi.cdef(header) lib = ffi.dlopen(_lib_path) except Exception: - raise Exception('Could not load libopenai from path %s. ' % _lib_path + raise Exception('Could not load libctoybox from path %s. ' % _lib_path + """If you are on OSX, this may be due the relative path being different - from `target/(target|release)/libopenai.dylib. If you are on Linux, try + from `target/(target|release)/libctoybox.dylib. If you are on Linux, try prefixing your call with `LD_LIBRARY_PATH=/path/to/library`.""") From ab326916bdb192df50d62ee6bd122df08d3fa4e2 Mon Sep 17 00:00:00 2001 From: Emma Tosch Date: Sat, 16 Mar 2019 17:48:36 -0400 Subject: [PATCH 20/21] updated message, minimized code in unsafe block --- ctoybox/src/core.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ctoybox/src/core.rs b/ctoybox/src/core.rs index c5efdaee..ddafbcc4 100644 --- a/ctoybox/src/core.rs +++ b/ctoybox/src/core.rs @@ -220,13 +220,14 @@ pub extern "C" fn state_apply_action(state_ptr: *mut WrapState, input_ptr: *cons assert!(!state_ptr.is_null()); &mut *state_ptr }; - let input_str = unsafe { + let input_ptr = unsafe { assert!(!input_ptr.is_null()); CStr::from_ptr(input_ptr) - .to_str() - .expect("Could not create input from UTF-8") }; - let input: Input = serde_json::from_str(input_str).expect("Could not convert input to JSON"); + let input_str = input_ptr + .to_str() + .expect("Could not create input string from pointer"); + let input: Input = serde_json::from_str(input_str).expect("Could not input string to Input"); state.update_mut(input); } From 95c81865a4a43cfae3d6a703537435805da899e5 Mon Sep 17 00:00:00 2001 From: Emma Tosch Date: Sat, 16 Mar 2019 18:20:53 -0400 Subject: [PATCH 21/21] forgot to run cargo fmt --- ctoybox/src/core.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ctoybox/src/core.rs b/ctoybox/src/core.rs index ddafbcc4..1f3e41d4 100644 --- a/ctoybox/src/core.rs +++ b/ctoybox/src/core.rs @@ -225,8 +225,8 @@ pub extern "C" fn state_apply_action(state_ptr: *mut WrapState, input_ptr: *cons CStr::from_ptr(input_ptr) }; let input_str = input_ptr - .to_str() - .expect("Could not create input string from pointer"); + .to_str() + .expect("Could not create input string from pointer"); let input: Input = serde_json::from_str(input_str).expect("Could not input string to Input"); state.update_mut(input); }