Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pufferlib/ocean/env_binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ static PyModuleDef module = {
methods
};

PyMODINIT_FUNC PyInit_binding(void) { \
import_array(); \
return PyModule_Create(&module); \
PyMODINIT_FUNC PyInit_binding(void) {
import_array();
return PyModule_Create(&module);
}
22 changes: 22 additions & 0 deletions pufferlib/ocean/tripletriad/binding.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "tripletriad.h"

#define Env CTripleTriad
#include "../env_binding.h"

static int my_init(Env* env, PyObject* args, PyObject* kwargs) {
env->width = unpack(kwargs, "width");
env->height = unpack(kwargs, "height");
env->card_width = unpack(kwargs, "card_width");
env->card_height = unpack(kwargs, "card_height");
init_ctripletriad(env);
return 0;
}

static int my_log(PyObject* dict, Log* log) {
assign_to_dict(dict, "perf", log->perf);
assign_to_dict(dict, "score", log->score);
assign_to_dict(dict, "episode_return", log->episode_return);
assign_to_dict(dict, "episode_length", log->episode_length);
assign_to_dict(dict, "n", log->n);
return 0;
}
112 changes: 0 additions & 112 deletions pufferlib/ocean/tripletriad/cy_tripletriad.pyx

This file was deleted.

43 changes: 38 additions & 5 deletions pufferlib/ocean/tripletriad/tripletriad.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include "tripletriad.h"
#include "puffernet.h"
#include <time.h>

int main() {
#define NOOP -1

void interactive() {
Weights* weights = load_weights("resources/tripletriad_weights.bin", 148880);
LinearLSTM* net = make_linearlstm(weights, 1, 114, 15);

Expand All @@ -15,12 +18,12 @@ int main() {
};
allocate_ctripletriad(&env);
c_reset(&env);
Client* client = make_client(env.width, env.height);
env.client = make_client(env.width, env.height);

int tick = 0;
int action;
while (!WindowShouldClose()) {
action = -1;
action = NOOP;

// User can take control of the player
if (IsKeyDown(KEY_LEFT_SHIFT)) {
Expand Down Expand Up @@ -61,15 +64,45 @@ int main() {
}

tick = (tick + 1) % 45;

if (env.actions[0] != NOOP) {
c_step(&env);
}

c_render(client, &env);
c_render(&env);
}
free_linearlstm(net);
free(weights);
close_client(client);
close_client(env.client);
free_allocated_ctripletriad(&env);
}

void performance_test() {
long test_time = 10;
CTripleTriad env = {
.width = 990,
.height = 690,
.card_width = 576 / 3,
.card_height = 672 / 3,
.game_over = 0,
.num_cards = 10,
};
allocate_ctripletriad(&env);
c_reset(&env);

long start = time(NULL);
int i = 0;
while (time(NULL) - start < test_time) {
c_step(&env);
i++;
}
long end = time(NULL);
printf("SPS: %ld\n", i / (end - start));
free_allocated_ctripletriad(&env);
}

int main() {
// performance_test();
interactive();
return 0;
}
Loading
Loading