Skip to content

Commit

Permalink
Fix c builds after conda support
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph Suarez committed Feb 5, 2025
1 parent 542236e commit 33f4ee9
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 42 deletions.
10 changes: 5 additions & 5 deletions pufferlib/ocean/breakout/breakout.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void demo() {
.brick_cols = 18,
};
allocate(&env);
reset(&env);
c_reset(&env);

Client* client = make_client(&env);

Expand All @@ -35,8 +35,8 @@ void demo() {
forward_linearlstm(net, env.observations, env.actions);
}

step(&env);
render(client, &env);
c_step(&env);
c_render(client, &env);
}
free_linearlstm(net);
free(weights);
Expand All @@ -60,13 +60,13 @@ void performance_test() {
.brick_cols = 18,
};
allocate(&env);
reset(&env);
c_reset(&env);

long start = time(NULL);
int i = 0;
while (time(NULL) - start < test_time) {
env.actions[0] = rand() % 4;
step(&env);
c_step(&env);
i++;
}
long end = time(NULL);
Expand Down
10 changes: 5 additions & 5 deletions pufferlib/ocean/connect4/connect4.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void interactive() {
.piece_height = 96,
};
allocate_cconnect4(&env);
reset(&env);
c_reset(&env);

Client* client = make_client(env.width, env.height);
float observations[42] = {0};
Expand Down Expand Up @@ -43,10 +43,10 @@ void interactive() {

tick = (tick + 1) % 60;
if (env.actions[0] >= 0 && env.actions[0] <= 6) {
step(&env);
c_step(&env);
}

render(client, &env);
c_render(client, &env);
}
free_linearlstm(net);
free(weights);
Expand All @@ -63,13 +63,13 @@ void performance_test() {
.piece_height = 96,
};
allocate_cconnect4(&env);
reset(&env);
c_reset(&env);

long start = time(NULL);
int i = 0;
while (time(NULL) - start < test_time) {
env.actions[0] = rand() % 7;
step(&env);
c_step(&env);
i++;
}
long end = time(NULL);
Expand Down
4 changes: 2 additions & 2 deletions pufferlib/ocean/enduro/enduro.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int demo() {

unsigned int seed = 0;
init(&env, seed, 0);
reset(&env);
c_reset(&env);

while (!WindowShouldClose()) {
if (IsKeyDown(KEY_LEFT_SHIFT)) {
Expand Down Expand Up @@ -78,7 +78,7 @@ void perftest(float test_time) {

unsigned int seed = 12345;
init(&env, seed, 0);
reset(&env);
c_reset(&env);

int start = time(NULL);
int i = 0;
Expand Down
10 changes: 5 additions & 5 deletions pufferlib/ocean/go/go.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void demo(int grid_size) {
Weights* weights = load_weights("resources/go_weights.bin", 254867);
GoNet* net = init_gonet(weights, 1, grid_size);
allocate(&env);
reset(&env);
c_reset(&env);

Client* client = make_client(env.width, env.height);
int tick = 0;
Expand All @@ -147,7 +147,7 @@ void demo(int grid_size) {
if (IsKeyDown(KEY_LEFT_SHIFT)) {
env.actions[0] = human_action;
}
step(&env);
c_step(&env);
if (IsKeyDown(KEY_LEFT_SHIFT)) {
env.actions[0] = -1;
}
Expand Down Expand Up @@ -187,7 +187,7 @@ void demo(int grid_size) {
}
}
}
render(client, &env);
c_render(client, &env);
}
close_client(client);
free_allocated(&env);
Expand All @@ -209,13 +209,13 @@ void performance_test() {
.reward_move_valid = 0.1
};
allocate(&env);
reset(&env);
c_reset(&env);

long start = time(NULL);
int i = 0;
while (time(NULL) - start < test_time) {
env.actions[0] = rand() % (env.grid_size)*(env.grid_size);
step(&env);
c_step(&env);
i++;
}
long end = time(NULL);
Expand Down
6 changes: 3 additions & 3 deletions pufferlib/ocean/pong/pong.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int main() {

Client* client = make_client(&env);

reset(&env);
c_reset(&env);
while (!WindowShouldClose()) {
// User can take control of the paddle
if (IsKeyDown(KEY_LEFT_SHIFT)) {
Expand All @@ -37,8 +37,8 @@ int main() {
forward_linearlstm(net, env.observations, env.actions);
}

step(&env);
render(client, &env);
c_step(&env);
c_render(client, &env);
}
free_linearlstm(net);
free(weights);
Expand Down
10 changes: 5 additions & 5 deletions pufferlib/ocean/rware/rware.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void demo(int map_choice) {
LinearLSTM* net = make_linearlstm(weights, env.num_agents, 27, 5);

allocate(&env);
reset(&env);
c_reset(&env);
Client* client = make_client(&env);

int tick = 0;
Expand All @@ -54,7 +54,7 @@ void demo(int map_choice) {
env.actions[env.human_agent_idx] = human_action;
}

step(&env);
c_step(&env);

if (IsKeyDown(KEY_LEFT_SHIFT)) {
env.actions[env.human_agent_idx] = NOOP;
Expand Down Expand Up @@ -82,7 +82,7 @@ void demo(int map_choice) {
}
}

render(client,&env);
c_render(client,&env);
}
close_client(client);
free_allocated(&env);
Expand All @@ -99,13 +99,13 @@ void performance_test() {
.reward_type = 2
};
allocate(&env);
reset(&env);
c_reset(&env);

long start = time(NULL);
int i = 0;
while (time(NULL) - start < test_time) {
env.actions[0] = rand() % 5;
step(&env);
c_step(&env);
i++;
}
long end = time(NULL);
Expand Down
10 changes: 5 additions & 5 deletions pufferlib/ocean/snake/snake.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ int demo() {
.reward_death = -1.0f,
};
allocate_csnake(&env);
reset(&env);
c_reset(&env);

Weights* weights = load_weights("resources/snake_weights.bin", 148357);
LinearLSTM* net = make_linearlstm(weights, env.num_snakes, env.obs_size, 4);
Expand All @@ -35,8 +35,8 @@ int demo() {
}
forward_linearlstm(net, net->obs, env.actions);
}
step(&env);
render(client, &env);
c_step(&env);
c_render(client, &env);
}
free_linearlstm(net);
free(weights);
Expand All @@ -59,15 +59,15 @@ void test_performance(float test_time) {
.reward_death = -1.0f,
};
allocate_csnake(&env);
reset(&env);
c_reset(&env);

int start = time(NULL);
int i = 0;
while (time(NULL) - start < test_time) {
for (int j = 0; j < env.num_snakes; j++) {
env.actions[j] = rand()%4;
}
step(&env);
c_step(&env);
i++;
}
int end = time(NULL);
Expand Down
6 changes: 3 additions & 3 deletions pufferlib/ocean/squared/squared.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ int main() {

Client* client = make_client(&env);

reset(&env);
c_reset(&env);
while (!WindowShouldClose()) {
if (IsKeyDown(KEY_LEFT_SHIFT)) {
env.actions[0] = 0;
Expand All @@ -22,8 +22,8 @@ int main() {
env.actions[0] = NOOP;
//forward_linearlstm(net, env.observations, env.actions);
}
step(&env);
render(client, &env);
c_step(&env);
c_render(client, &env);
}
//free_linearlstm(net);
//free(weights);
Expand Down
12 changes: 6 additions & 6 deletions pufferlib/ocean/trash_pickup/trash_pickup.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void demo(int grid_size, int num_agents, int num_trash, int num_bins, int max_st
.do_human_control = true
};

bool use_pretrained_model = true;
bool use_pretrained_model = false;

Weights* weights;
ConvLSTM* net;
Expand All @@ -28,7 +28,7 @@ void demo(int grid_size, int num_agents, int num_trash, int num_bins, int max_st
allocate(&env);
Client* client = make_client(&env);

reset(&env);
c_reset(&env);

int tick = 0;
while (!WindowShouldClose()) {
Expand Down Expand Up @@ -64,12 +64,12 @@ void demo(int grid_size, int num_agents, int num_trash, int num_bins, int max_st
}

// Step the environment and render the grid
step(&env);
c_step(&env);

}
tick++;

render(client, &env);
c_render(client, &env);
}

free_convlstm(net);
Expand All @@ -91,7 +91,7 @@ void performance_test() {
.agent_sight_range = 5
};
allocate(&env);
reset(&env);
c_reset(&env);

long start = time(NULL);
int i = 0;
Expand All @@ -100,7 +100,7 @@ void performance_test() {
for (int e = 0; e < env.num_agents; e++) {
env.actions[e] = rand() % 4;
}
step(&env);
c_step(&env);
i += inc;
}
long end = time(NULL);
Expand Down
6 changes: 3 additions & 3 deletions pufferlib/ocean/tripletriad/tripletriad.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int main() {
.num_cards = 10,
};
allocate_ctripletriad(&env);
reset(&env);
c_reset(&env);
Client* client = make_client(env.width, env.height);

int tick = 0;
Expand Down Expand Up @@ -59,10 +59,10 @@ int main() {

tick = (tick + 1) % 45;
if (env.actions[0] != NOOP) {
step(&env);
c_step(&env);
}

render(client, &env);
c_render(client, &env);
}
free_linearlstm(net);
free(weights);
Expand Down

0 comments on commit 33f4ee9

Please sign in to comment.