Skip to content

Commit 9250447

Browse files
author
Joseph Suarez
committed
Rename school to battle
1 parent c5c4742 commit 9250447

File tree

7 files changed

+39
-39
lines changed

7 files changed

+39
-39
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[base]
22
package = ocean
3-
env_name = puffer_school
3+
env_name = puffer_battle
44
policy_name = Policy
55
rnn_name = Recurrent
66

@@ -23,7 +23,7 @@ size_y = 2
2323
size_z = 2
2424

2525
[train]
26-
total_timesteps = 250_000_000
26+
total_timesteps = 100_000_000
2727

2828
learning_rate = 0.0015534438005054883
2929
gamma = 0.9923382806478448
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/* Pure C demo file for School. Build it with:
2-
* bash scripts/build_ocean.sh school local (debug)
3-
* bash scripts/build_ocean.sh school fast
1+
/* Pure C demo file for Battle. Build it with:
2+
* bash scripts/build_ocean.sh battle local (debug)
3+
* bash scripts/build_ocean.sh battle fast
44
* We suggest building and debugging your env in pure C first. You
55
* get faster builds and better error messages
66
*/
7-
#include "school.h"
7+
#include "battle.h"
88

99
/* Puffernet is our lightweight cpu inference library that
1010
* lets you load basic PyTorch model architectures so that
@@ -14,12 +14,12 @@
1414

1515
int main() {
1616
// Weights are exported by running puffer export
17-
//Weights* weights = load_weights("resources/puffer_school_weights.bin", 137743);
17+
//Weights* weights = load_weights("resources/puffer_battle_weights.bin", 137743);
1818

1919
//int logit_sizes[2] = {9, 5};
2020
//LinearLSTM* net = make_linearlstm(weights, num_agents, num_obs, logit_sizes, 2);
2121

22-
School env = {
22+
Battle env = {
2323
.width = 1980,
2424
.height = 1020,
2525
.size_x = 8,
Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* School: a sample multiagent env about puffers eating stars.
1+
/* Battle: a sample multiagent env about puffers eating stars.
22
* Use this as a tutorial and template for your own multiagent envs.
33
* We suggest starting with the Squared env for a simpler intro.
44
* Star PufferLib on GitHub to support. It really, really helps!
@@ -135,13 +135,13 @@ typedef struct {
135135
int num_agents;
136136
int num_armies;
137137
float* terrain;
138-
} School;
138+
} Battle;
139139

140-
int map_idx(School* env, float x, float y) {
140+
int map_idx(Battle* env, float x, float y) {
141141
return env->terrain_width*(int)y + (int)x;
142142
}
143143

144-
float ground_height(School* env, float x, float z) {
144+
float ground_height(Battle* env, float x, float z) {
145145
int agent_map_x = 128*x + 128*env->size_x;
146146
int agent_map_z = 128*z + 128*env->size_z;
147147
if (agent_map_x == 256*env->size_x) {
@@ -195,7 +195,7 @@ void perlin_noise(float* map, int width, int height,
195195
}
196196
}
197197

198-
void init(School* env) {
198+
void init(Battle* env) {
199199
env->agents = calloc(env->num_agents, sizeof(Entity));
200200
env->bases = calloc(env->num_armies, sizeof(Entity));
201201
env->terrain_width = 256*env->size_x;
@@ -250,7 +250,7 @@ void update_abilities(Entity* agent) {
250250
}
251251
}
252252

253-
void respawn(School* env, int idx) {
253+
void respawn(Battle* env, int idx) {
254254
Entity* agent = &env->agents[idx];
255255
int army = agent->army;
256256
agent->orientation = QuaternionIdentity();
@@ -454,7 +454,7 @@ bool attack_aa(Entity *agent, Entity *target) {
454454
return false;
455455
}
456456

457-
void move_basic(School* env, Entity* agent, float* actions) {
457+
void move_basic(Battle* env, Entity* agent, float* actions) {
458458
float d_vx = actions[0]/100.0f;
459459
float d_vy = actions[1]/100.0f;
460460
float d_vz = actions[2]/100.0f;
@@ -476,7 +476,7 @@ void move_basic(School* env, Entity* agent, float* actions) {
476476
agent->z = clip(agent->z, -env->size_z, env->size_z);
477477
}
478478

479-
void move_ground(School* env, Entity* agent, float* actions) {
479+
void move_ground(Battle* env, Entity* agent, float* actions) {
480480
float d_theta = -actions[1]/10.0f;
481481

482482
// Update speed and clamp
@@ -499,7 +499,7 @@ void move_ground(School* env, Entity* agent, float* actions) {
499499
agent->y = ground_height(env, agent->x, agent->z);
500500
}
501501

502-
void move_ship(School* env, Entity* agent, float* actions, int i) {
502+
void move_ship(Battle* env, Entity* agent, float* actions, int i) {
503503
// Compute deltas from actions (same as original)
504504
float d_pitch = agent->max_turn * actions[0] / 10.0f;
505505
float d_roll = agent->max_turn * actions[1] / 10.0f;
@@ -571,7 +571,7 @@ void move_ship(School* env, Entity* agent, float* actions, int i) {
571571
agent->z = clampf(agent->z, -env->size_z, env->size_z);
572572
}
573573

574-
void compute_observations(School* env) {
574+
void compute_observations(Battle* env) {
575575
float centroids[env->num_armies][3];
576576
memset(centroids, 0, env->num_armies*3*sizeof(float));
577577

@@ -652,7 +652,7 @@ void compute_observations(School* env) {
652652
}
653653

654654
// Required function
655-
void c_reset(School* env) {
655+
void c_reset(Battle* env) {
656656
int agents_per_army = env->num_agents / env->num_armies;
657657
for (int i=0; i<env->num_armies; i++) {
658658
bool spawn = false;
@@ -708,7 +708,7 @@ void c_reset(School* env) {
708708
compute_observations(env);
709709
}
710710

711-
void c_step(School* env) {
711+
void c_step(Battle* env) {
712712
memset(env->rewards, 0, env->num_agents*sizeof(float));
713713
memset(env->terminals, 0, env->num_agents*sizeof(unsigned char));
714714

@@ -948,21 +948,21 @@ void update_heightmap_mesh(Mesh* mesh, float* heightMap, Vector3 size) {
948948

949949

950950
// Required function. Should handle creating the client on first call
951-
void c_render(School* env) {
951+
void c_render(Battle* env) {
952952
if (env->client == NULL) {
953953
SetConfigFlags(FLAG_MSAA_4X_HINT);
954-
InitWindow(env->width, env->height, "PufferLib School");
954+
InitWindow(env->width, env->height, "PufferLib Battle");
955955
SetTargetFPS(30);
956956
Client* client = (Client*)calloc(1, sizeof(Client));
957957
env->client = client;
958-
client->models[DRONE] = LoadModel("resources/school/drone.glb");
959-
client->models[FIGHTER] = LoadModel("resources/school/fighter.glb");
960-
client->models[MOTHERSHIP] = LoadModel("resources/school/mothership.glb");
961-
client->models[BOMBER] = LoadModel("resources/school/bomber.glb");
962-
client->models[INFANTRY] = LoadModel("resources/school/car.glb");
963-
client->models[TANK] = LoadModel("resources/school/tank.glb");
964-
client->models[ARTILLERY] = LoadModel("resources/school/artillery.glb");
965-
client->models[BASE] = LoadModel("resources/school/base.glb");
958+
client->models[DRONE] = LoadModel("resources/battle/drone.glb");
959+
client->models[FIGHTER] = LoadModel("resources/battle/fighter.glb");
960+
client->models[MOTHERSHIP] = LoadModel("resources/battle/mothership.glb");
961+
client->models[BOMBER] = LoadModel("resources/battle/bomber.glb");
962+
client->models[INFANTRY] = LoadModel("resources/battle/car.glb");
963+
client->models[TANK] = LoadModel("resources/battle/tank.glb");
964+
client->models[ARTILLERY] = LoadModel("resources/battle/artillery.glb");
965+
client->models[BASE] = LoadModel("resources/battle/base.glb");
966966
//env->client->ship = LoadModel("resources/puffer.glb");
967967

968968
char vsPath[256];
@@ -997,8 +997,8 @@ void c_render(School* env) {
997997
update_heightmap_mesh(client->mesh, env->terrain, (Vector3){env->terrain_width, 1, env->terrain_height});
998998

999999
client->terrain_shader = LoadShader(
1000-
TextFormat("resources/school/shader_%i.vs", GLSL_VERSION),
1001-
TextFormat("resources/school/shader_%i.fs", GLSL_VERSION)
1000+
TextFormat("resources/battle/shader_%i.vs", GLSL_VERSION),
1001+
TextFormat("resources/battle/shader_%i.fs", GLSL_VERSION)
10021002
);
10031003

10041004
Image img = GenImageColor(env->terrain_width, env->terrain_height, WHITE);
@@ -1101,7 +1101,7 @@ void c_render(School* env) {
11011101

11021102
// Required function. Should clean up anything you allocated
11031103
// Do not free env->observations, actions, rewards, terminals
1104-
void c_close(School* env) {
1104+
void c_close(Battle* env) {
11051105
free(env->agents);
11061106
free(env->bases);
11071107
if (env->client != NULL) {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import numpy as np
55

66
import pufferlib
7-
from pufferlib.ocean.school import binding
7+
from pufferlib.ocean.battle import binding
88

9-
class School(pufferlib.PufferEnv):
9+
class Battle(pufferlib.PufferEnv):
1010
def __init__(self, num_envs=1, width=1920, height=1080, size_x=1.0,
1111
size_y=1.0, size_z=1.0, num_agents=1024, num_factories=32,
1212
num_armies=4, render_mode=None, log_interval=128, buf=None, seed=0):
@@ -68,7 +68,7 @@ def close(self):
6868
if __name__ == '__main__':
6969
N = 512
7070

71-
env = School(num_envs=N)
71+
env = Battle(num_envs=N)
7272
env.reset()
7373
steps = 0
7474

@@ -83,4 +83,4 @@ def close(self):
8383
steps += env.num_agents
8484
i += 1
8585

86-
print('School SPS:', int(steps / (time.time() - start)))
86+
print('Battle SPS:', int(steps / (time.time() - start)))
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include "school.h"
1+
#include "battle.h"
22

3-
#define Env School
3+
#define Env Battle
44
#include "../env_binding.h"
55

66
static int my_init(Env* env, PyObject* args, PyObject* kwargs) {

0 commit comments

Comments
 (0)