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 ) {
0 commit comments