Environments API¶
The envs package exposes all simulation environments and supporting
utilities as a clean programmatic Python API.
Quick-start¶
from envs import BattalionEnv, RewardWeights, Formation
# Custom reward shaping
rw = RewardWeights(win_bonus=20.0, loss_penalty=-20.0, time_penalty=-0.005)
env = BattalionEnv(reward_weights=rw, curriculum_level=3)
obs, info = env.reset(seed=42)
Environments¶
envs.battalion_env.BattalionEnv
¶
Bases: Env
1v1 battalion RL environment.
The agent controls the Blue battalion; Red is driven either by a
built-in scripted opponent (controlled by curriculum_level) or by an
optional red_policy (any object with a predict method, e.g. a
Stable-Baselines3 PPO model). When red_policy is provided it takes
precedence over the scripted opponent and curriculum_level is ignored for
movement and fire decisions.
Curriculum levels (scripted opponent only) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ===== ============================================= Level Red opponent behaviour ===== ============================================= 1 Stationary — Red does not move or fire. 2 Turning only — Red faces Blue but stays put. 3 Advance only — Red turns and advances; no fire. 4 Soft fire — Red turns, advances, fires at 50 % intensity. 5 Full combat — Red turns, advances, fires at 100 % intensity (default). ===== =============================================
Observation space — Box(shape=(17,), dtype=float32) (formations disabled)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
===== =========================== =========
Index Feature Range
===== =========================== =========
0 blue x / map_width [0, 1]
1 blue y / map_height [0, 1]
2 cos(blue θ) [-1, 1]
3 sin(blue θ) [-1, 1]
4 blue strength [0, 1]
5 blue morale [0, 1]
6 distance to red / diagonal [0, 1]
7 cos(bearing to red) [-1, 1]
8 sin(bearing to red) [-1, 1]
9 red strength [0, 1]
10 red morale [0, 1]
11 step / max_steps [0, 1]
12 blue elevation (normalised) [0, 1]
13 blue cover [0, 1]
14 red elevation (normalised) [0, 1]
15 red cover [0, 1]
16 line-of-sight (0=blocked) [0, 1]
===== =========================== =========
When enable_formations is True, two extra dimensions are appended:
===== ===================================== ========= Index Feature Range ===== ===================================== ========= 17 blue formation / (NUM_FORMATIONS−1) [0, 1] 18 blue transitioning (1=yes) [0, 1] ===== ===================================== =========
When enable_logistics is True, three more dimensions follow the
terrain / formations dims:
===== =========================== ========= Index Feature Range ===== =========================== ========= N+0 blue ammo level [0, 1] N+1 blue food level [0, 1] N+2 blue fatigue level [0, 1] ===== =========================== =========
(where N = 17 with formations disabled or 19 with formations enabled).
When enable_weather is True, two more dimensions are appended after
any logistics dims:
===== =========================== ========= Index Feature Range ===== =========================== ========= M+0 weather condition id [0, 1] M+1 combined visibility fraction [0, 1] ===== =========================== =========
(where M = N + 3 when logistics are enabled, or N when disabled).
Action space — Box(shape=(3,), dtype=float32) (formations disabled)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
===== =========== ======== ============================================
Index Name Range Effect
===== =========== ======== ============================================
0 move [-1, 1] Scale max_speed; positive = forward
1 rotate [-1, 1] Scale max_turn_rate; positive = CCW
2 fire [0, 1] Fire intensity this step
===== =========== ======== ============================================
When enable_formations is True, a fourth dimension is added:
===== =========== ======== ============================================ Index Name Range Effect ===== =========== ======== ============================================ 3 formation [0, 3] Desired formation (rounded to nearest int) ===== =========== ======== ============================================
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
map_width
|
float
|
Map dimensions in metres (default 1 km × 1 km). |
MAP_WIDTH
|
map_height
|
float
|
Map dimensions in metres (default 1 km × 1 km). |
MAP_WIDTH
|
max_steps
|
int
|
Episode length cap (default 500). |
MAX_STEPS
|
terrain
|
Optional[TerrainMap]
|
Optional :class: |
None
|
randomize_terrain
|
bool
|
When |
True
|
hill_speed_factor
|
float
|
Movement speed multiplier applied to units on maximum-elevation
terrain. Must be in |
0.5
|
curriculum_level
|
int
|
Scripted Red opponent difficulty (1–5). Level 1 is the easiest
(stationary target); level 5 is full combat. Defaults to |
5
|
reward_weights
|
Optional[RewardWeights]
|
:class: |
None
|
red_policy
|
Optional[RedPolicy]
|
Optional policy object for driving the Red battalion. Must expose
a |
None
|
render_mode
|
Optional[str]
|
Render mode. |
None
|
enable_formations
|
bool
|
When |
False
|
enable_logistics
|
bool
|
When |
False
|
logistics_config
|
Optional[LogisticsConfig]
|
Optional :class: |
None
|
enable_weather
|
bool
|
When |
False
|
weather_config
|
Optional[WeatherConfig]
|
Optional :class: |
None
|
Source code in envs/battalion_env.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 | |
close()
¶
render()
¶
Render the current environment state.
When render_mode="human" a pygame window is opened on the first
call and kept alive for subsequent calls. The window is closed by
:meth:close. When render_mode is None this is a no-op.
Source code in envs/battalion_env.py
reset(*, seed=None, options=None)
¶
Reset the environment and return the initial observation.
When randomize_terrain is True (the default when no fixed
terrain map is passed to __init__), a new procedural terrain
is generated from the seeded RNG on every call. Passing the same
seed therefore always produces the same terrain layout and unit
positions.
Blue spawns in the western half of the map facing roughly east; Red spawns in the eastern half facing roughly west.
Source code in envs/battalion_env.py
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 | |
set_red_policy(policy)
¶
Swap the Red opponent policy at runtime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
policy
|
Optional[RedPolicy]
|
New policy to use for Red, or |
required |
Source code in envs/battalion_env.py
step(action)
¶
Advance the environment by one step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
ndarray
|
Array of shape |
required |
Returns:
| Type | Description |
|---|---|
(observation, reward, terminated, truncated, info)
|
|
Source code in envs/battalion_env.py
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 | |
envs.brigade_env.BrigadeEnv
¶
Bases: Env
Gymnasium environment for a brigade-level HRL commander.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_blue
|
int
|
Number of Blue battalions controlled by the brigade. |
2
|
n_red
|
int
|
Number of Red opponent battalions. |
2
|
map_width
|
float
|
Map width in metres. |
MAP_WIDTH
|
map_height
|
float
|
Map height in metres. |
MAP_HEIGHT
|
max_steps
|
int
|
Maximum primitive-step episode length. |
MAX_STEPS
|
options
|
Optional[list[Option]]
|
Option vocabulary. |
None
|
temporal_ratio
|
int
|
Number of primitive battalion steps per brigade macro-step (option
duration cap). Ignored when an explicit |
10
|
battalion_policy
|
Optional frozen :class: |
None
|
|
red_random
|
bool
|
When |
False
|
randomize_terrain
|
bool
|
Pass-through to :class: |
True
|
visibility_radius
|
float
|
Pass-through to :class: |
600.0
|
render_mode
|
Optional[str]
|
|
None
|
Source code in envs/brigade_env.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 | |
close()
¶
render()
¶
reset(seed=None, options=None)
¶
Reset the environment and return the initial brigade observation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seed
|
Optional[int]
|
RNG seed forwarded to the inner :class: |
None
|
options
|
Optional[dict]
|
Unused; present for Gymnasium API compatibility. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
obs |
np.ndarray of shape ``(obs_dim,)``
|
|
info |
dict
|
|
Source code in envs/brigade_env.py
set_battalion_policy(policy)
¶
Set (or clear) the frozen policy used to drive Red agents.
When a policy is supplied its parameters are frozen
(requires_grad=False) and placed in evaluation mode so
no gradients flow through it during brigade training.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
policy
|
A :class: |
required |
Source code in envs/brigade_env.py
step(brigade_action)
¶
Execute one macro-step: dispatch options to Blue battalions.
For each alive Blue battalion, the selected option runs for multiple primitive steps until the option terminates or the underlying episode ends.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
brigade_action
|
ndarray
|
Array of shape |
required |
Returns:
| Name | Type | Description |
|---|---|---|
obs |
np.ndarray — brigade observation after the macro-step
|
|
reward |
float — mean reward across all Blue battalions
|
|
terminated |
bool — True when the episode ended naturally
|
|
truncated |
bool — True when the episode was cut short
|
|
info |
dict — metadata including primitive step count and option names
|
|
Source code in envs/brigade_env.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 | |
envs.division_env.DivisionEnv
¶
Bases: Env
Gymnasium environment for a division-level HRL commander.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_brigades
|
int
|
Number of Blue brigades. Each brigade is a group of n_blue_per_brigade battalions. |
2
|
n_blue_per_brigade
|
int
|
Number of Blue battalions per brigade. |
2
|
n_red_brigades
|
Optional[int]
|
Number of Red brigades. Defaults to n_brigades. |
None
|
n_red_per_brigade
|
Optional[int]
|
Number of Red battalions per Red brigade. Defaults to n_blue_per_brigade. |
None
|
map_width
|
float
|
Map width in metres (passed through to inner env). |
MAP_WIDTH
|
map_height
|
float
|
Map height in metres (passed through to inner env). |
MAP_HEIGHT
|
max_steps
|
int
|
Maximum primitive-step episode length. |
MAX_STEPS
|
brigade_policy
|
Optional frozen brigade-level policy for Red brigades.
Must expose |
None
|
|
red_random
|
bool
|
When |
False
|
randomize_terrain
|
bool
|
Pass-through to :class: |
True
|
visibility_radius
|
float
|
Fog-of-war visibility radius in metres. |
600.0
|
render_mode
|
Optional[str]
|
|
None
|
Source code in envs/division_env.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 | |
close()
¶
render()
¶
reset(seed=None, options=None)
¶
Reset the environment and return the initial division observation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seed
|
Optional[int]
|
RNG seed forwarded to the inner :class: |
None
|
options
|
Optional[dict]
|
Unused; present for Gymnasium API compatibility. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
obs |
np.ndarray of shape ``(obs_dim,)``
|
|
info |
dict
|
|
Source code in envs/division_env.py
set_brigade_policy(policy)
¶
Set (or clear) the frozen brigade policy for Red.
When policy is supplied any PyTorch parameters are frozen
(requires_grad=False) and placed in evaluation mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
policy
|
An object with a |
required |
Source code in envs/division_env.py
step(div_action)
¶
Execute one division macro-step.
Translates the division operational command for each brigade into
brigade-level actions (option indices for all battalions in the
brigade) and delegates to :meth:~envs.brigade_env.BrigadeEnv.step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
div_action
|
ndarray
|
Array of shape |
required |
Returns:
| Name | Type | Description |
|---|---|---|
obs |
np.ndarray — division observation after the macro-step
|
|
reward |
float — brigade reward (passed through from BrigadeEnv)
|
|
terminated |
bool
|
|
truncated |
bool
|
|
info |
dict — includes ``div_steps``, ``brigade_action``, and
|
fields from :class: |
Source code in envs/division_env.py
envs.corps_env.CorpsEnv
¶
Bases: Env
Gymnasium environment for a corps-level HRL commander.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_divisions
|
int
|
Number of Blue divisions. Must be ≥ 1. |
3
|
n_brigades_per_division
|
int
|
Number of Blue brigades per division. Must be ≥ 1. |
3
|
n_blue_per_brigade
|
int
|
Number of Blue battalions per brigade. Must be ≥ 1. |
4
|
n_red_divisions
|
Optional[int]
|
Number of Red divisions. Defaults to n_divisions. |
None
|
n_red_brigades_per_division
|
Optional[int]
|
Red brigades per division. Defaults to n_brigades_per_division. |
None
|
n_red_per_brigade
|
Optional[int]
|
Red battalions per brigade. Defaults to n_blue_per_brigade. |
None
|
map_width
|
float
|
Map dimensions in metres (default 10 km × 5 km = 50 km²). |
CORPS_MAP_WIDTH
|
map_height
|
float
|
Map dimensions in metres (default 10 km × 5 km = 50 km²). |
CORPS_MAP_WIDTH
|
max_steps
|
int
|
Maximum primitive-step episode length. |
MAX_STEPS
|
road_network
|
Optional[RoadNetwork]
|
Optional :class: |
None
|
supply_network
|
Optional[SupplyNetwork]
|
Optional :class: |
None
|
objectives
|
Optional[List[OperationalObjective]]
|
Optional list of :class: |
None
|
comm_radius
|
float
|
Inter-division communication radius in metres. Enemy threat vectors beyond this distance are replaced with sentinels. |
DEFAULT_COMM_RADIUS
|
red_random
|
bool
|
When |
True
|
randomize_terrain
|
bool
|
Pass-through to the inner env. |
True
|
visibility_radius
|
float
|
Fog-of-war visibility radius in metres. |
DEFAULT_VISIBILITY_RADIUS
|
render_mode
|
Optional[str]
|
|
None
|
Source code in envs/corps_env.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 | |
close()
¶
render()
¶
reset(seed=None, options=None)
¶
Reset the environment and return the initial corps observation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seed
|
Optional[int]
|
RNG seed forwarded to the inner :class: |
None
|
options
|
Optional[dict]
|
Unused; present for Gymnasium API compatibility. |
None
|
Source code in envs/corps_env.py
step(corps_action)
¶
Execute one corps macro-step.
Translates the per-division operational command into a division-level
action and delegates to the inner :class:~envs.division_env.DivisionEnv.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
corps_action
|
ndarray
|
Integer array of shape |
required |
Returns:
| Name | Type | Description |
|---|---|---|
obs |
np.ndarray — corps observation after the macro-step
|
|
reward |
float — pass-through from DivisionEnv plus objective bonuses
|
|
terminated |
bool
|
|
truncated |
bool
|
|
info |
dict — includes ``corps_steps``, ``division_action``,
|
|
Source code in envs/corps_env.py
643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 | |
envs.cavalry_corps_env.CavalryCorpsEnv
¶
Bases: CorpsEnv
Gymnasium environment for a corps commander with an independent cavalry arm.
Extends :class:~envs.corps_env.CorpsEnv with cavalry brigades that
execute reconnaissance, raiding, and pursuit missions each step.
Cavalry intelligence reduces the fog-of-war for allied divisions
when units are on RECONNAISSANCE mission.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_divisions
|
int
|
Number of Blue infantry divisions. |
3
|
n_brigades_per_division
|
int
|
Blue infantry brigades per division. |
3
|
n_blue_per_brigade
|
int
|
Blue battalions per brigade. |
4
|
n_red_divisions
|
Optional[int]
|
Red force composition (mirrors Blue by default). |
None
|
n_red_brigades_per_division
|
Optional[int]
|
Red force composition (mirrors Blue by default). |
None
|
n_red_per_brigade
|
Optional[int]
|
Red force composition (mirrors Blue by default). |
None
|
map_width
|
float
|
Map dimensions in metres. |
CORPS_MAP_WIDTH
|
map_height
|
float
|
Map dimensions in metres. |
CORPS_MAP_WIDTH
|
max_steps
|
int
|
Episode length cap. |
MAX_STEPS
|
road_network
|
Optional[RoadNetwork]
|
Optional overrides passed through to :class: |
None
|
supply_network
|
Optional[RoadNetwork]
|
Optional overrides passed through to :class: |
None
|
objectives
|
Optional[RoadNetwork]
|
Optional overrides passed through to :class: |
None
|
comm_radius
|
float
|
Base inter-division communication radius. Overridden to |
3000.0
|
red_random
|
bool
|
When |
True
|
randomize_terrain
|
bool
|
Pass-through to inner env. |
True
|
visibility_radius
|
float
|
Fog-of-war visibility radius for the inner simulation. |
1500.0
|
render_mode
|
Optional[str]
|
|
None
|
n_cavalry_brigades
|
int
|
Number of Blue cavalry brigades (default |
2
|
cavalry_corps
|
Optional[CavalryCorps]
|
Optional pre-built :class: |
None
|
cav_config
|
Optional[CavalryUnitConfig]
|
Optional :class: |
None
|
Source code in envs/cavalry_corps_env.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 | |
reset(seed=None, options=None)
¶
Reset the environment and return the initial cavalry corps observation.
Calls :meth:~envs.corps_env.CorpsEnv.reset on the base env,
resets cavalry unit positions, and returns the extended observation.
Source code in envs/cavalry_corps_env.py
step(action)
¶
Execute one cavalry-corps macro-step.
Splits the combined action into corps commands and cavalry mission
assignments. Infantry and supply logic executes first (via the
base :class:~envs.corps_env.CorpsEnv); cavalry then acts on the
updated battlefield state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
ndarray
|
Integer array of shape
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
obs |
np.ndarray — extended cavalry corps observation
|
|
reward |
float — base corps reward (cavalry adds no extra reward)
|
|
terminated |
bool
|
|
truncated |
bool
|
|
info |
dict — base corps info plus ``"cavalry"`` sub-dict
|
|
Source code in envs/cavalry_corps_env.py
envs.artillery_corps_env.ArtilleryCorpsEnv
¶
Bases: CorpsEnv
Gymnasium environment for a corps commander with an independent artillery arm.
Extends :class:~envs.corps_env.CorpsEnv with artillery batteries that
execute grand battery, counter-battery, siege, and fortification missions
each step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_divisions
|
int
|
Number of Blue infantry divisions. |
3
|
n_brigades_per_division
|
int
|
Blue infantry brigades per division. |
3
|
n_blue_per_brigade
|
int
|
Blue battalions per brigade. |
4
|
n_red_divisions
|
Optional[int]
|
Red force composition (mirrors Blue by default). |
None
|
n_red_brigades_per_division
|
Optional[int]
|
Red force composition (mirrors Blue by default). |
None
|
n_red_per_brigade
|
Optional[int]
|
Red force composition (mirrors Blue by default). |
None
|
map_width
|
float
|
Map dimensions in metres. |
CORPS_MAP_WIDTH
|
map_height
|
float
|
Map dimensions in metres. |
CORPS_MAP_WIDTH
|
max_steps
|
int
|
Episode length cap. |
MAX_STEPS
|
road_network
|
Optional[RoadNetwork]
|
Optional overrides passed through to :class: |
None
|
supply_network
|
Optional[RoadNetwork]
|
Optional overrides passed through to :class: |
None
|
objectives
|
Optional[RoadNetwork]
|
Optional overrides passed through to :class: |
None
|
comm_radius
|
float
|
Base inter-division communication radius. |
3000.0
|
red_random
|
bool
|
When |
True
|
randomize_terrain
|
bool
|
Pass-through to inner env. |
True
|
visibility_radius
|
float
|
Fog-of-war visibility radius for the inner simulation. |
1500.0
|
render_mode
|
Optional[str]
|
|
None
|
n_artillery_batteries
|
int
|
Number of Blue artillery batteries (default |
4
|
artillery_corps
|
Optional[ArtilleryCorps]
|
Optional pre-built :class: |
None
|
art_config
|
Optional[ArtilleryUnitConfig]
|
Optional :class: |
None
|
n_red_artillery_batteries
|
Optional[int]
|
Number of Red artillery batteries for counter-battery targeting (default equals n_artillery_batteries). |
None
|
Source code in envs/artillery_corps_env.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 | |
reset(seed=None, options=None)
¶
Reset the environment and return the initial artillery corps observation.
Calls :meth:~envs.corps_env.CorpsEnv.reset on the base env,
resets artillery positions, and returns the extended observation.
Source code in envs/artillery_corps_env.py
step(action)
¶
Execute one artillery-corps macro-step.
Splits the combined action into corps commands and artillery mission
assignments. Infantry and supply logic executes first (via the
base :class:~envs.corps_env.CorpsEnv); artillery then acts on the
updated battlefield state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
ndarray
|
Integer array of shape
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
obs |
np.ndarray — extended artillery corps observation
|
|
reward |
float — base corps reward + fortification reward shaping
|
|
terminated |
bool
|
|
truncated |
bool
|
|
info |
dict — base corps info plus ``"artillery"`` sub-dict
|
|
Source code in envs/artillery_corps_env.py
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 | |
envs.multi_battalion_env.MultiBattalionEnv
¶
Bases: ParallelEnv
PettingZoo ParallelEnv for NvN battalion combat.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_blue
|
int
|
Number of Blue (team 0) battalions. Must be |
2
|
n_red
|
int
|
Number of Red (team 1) battalions. Must be |
2
|
map_width
|
float
|
Map dimensions in metres (default 1 km × 1 km). |
MAP_WIDTH
|
map_height
|
float
|
Map dimensions in metres (default 1 km × 1 km). |
MAP_WIDTH
|
max_steps
|
int
|
Episode length cap (default 500). |
MAX_STEPS
|
terrain
|
Optional[TerrainMap]
|
Optional fixed :class: |
None
|
randomize_terrain
|
bool
|
When |
True
|
hill_speed_factor
|
float
|
Movement speed multiplier on maximum-elevation terrain. Must be
in |
0.5
|
visibility_radius
|
float
|
Fog-of-war cutoff distance (metres). Enemy units beyond this distance have their strength and morale hidden in observations. |
VISIBILITY_RADIUS
|
render_mode
|
Optional[str]
|
Currently unused; reserved for future rendering support. |
None
|
Source code in envs/multi_battalion_env.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 | |
action_space(agent)
¶
close()
¶
get_coordination_metrics(support_radius=300.0)
¶
Compute per-step coordination metrics for the current environment state.
Calls :func:~envs.metrics.coordination.compute_all on the currently
alive and non-routed Blue and Red battalions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
support_radius
|
float
|
Distance threshold (metres) for
:func: |
300.0
|
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Keys: |
Source code in envs/multi_battalion_env.py
observation_space(agent)
¶
render()
¶
reset(seed=None, options=None)
¶
Reset the environment and return initial observations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seed
|
Optional[int]
|
RNG seed. Passing the same seed always produces the same terrain layout and starting positions. |
None
|
options
|
Optional[dict]
|
Currently unused; accepted for API compatibility. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
observations |
dict[agent_id, ndarray]
|
|
infos |
dict[agent_id, dict]
|
|
Source code in envs/multi_battalion_env.py
state()
¶
Return the global state tensor for centralized critics.
Concatenates [x/w, y/h, cos θ, sin θ, strength, morale] for
every agent in possible_agents order, followed by
step / max_steps. Dead-agent slots are all-zero.
Returns:
| Type | Description |
|---|---|
np.ndarray of shape ``(6 * (n_blue + n_red) + 1,)`` and dtype
|
|
``float32``.
|
|
Source code in envs/multi_battalion_env.py
step(actions)
¶
Advance the environment one step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
actions
|
dict[str, ndarray]
|
Dict mapping each live agent ID to its action array of shape
|
required |
Returns:
| Type | Description |
|---|---|
(observations, rewards, terminations, truncations, infos)
|
All keyed by agent ID; contain entries for every agent that was alive at the start of this step. |
Source code in envs/multi_battalion_env.py
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 | |
Reward shaping¶
envs.reward.RewardWeights
dataclass
¶
Configurable multipliers for each reward component.
All weights are applied by multiplying against their respective raw
component value before summing into the total reward. Set a weight
to 0.0 to disable that component entirely.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
delta_enemy_strength
|
float
|
Multiplier applied to the fraction of enemy strength destroyed in a
step ( |
5.0
|
delta_own_strength
|
float
|
Multiplier applied to the fraction of own strength lost in a step
( |
5.0
|
survival_bonus
|
float
|
Per-step bonus scaled by Blue's current strength. Set to |
0.0
|
win_bonus
|
float
|
Terminal reward added when Blue wins (Red routed or destroyed). |
10.0
|
loss_penalty
|
float
|
Terminal reward added when Blue loses (Blue routed or destroyed). Should be negative. |
-10.0
|
time_penalty
|
float
|
Constant added every step. A small negative value (e.g. |
-0.01
|
Source code in envs/reward.py
enemy_routed_bonus = 0.0
class-attribute
instance-attribute
¶
Bonus added each step that the enemy is in a routing state.
A positive value (e.g. 2.0) encourages pursuit of routing enemies and
exploitation of broken units. Set to 0.0 (default) to disable.
own_routing_penalty = 0.0
class-attribute
instance-attribute
¶
Penalty added each step that the agent's own unit is routing.
A negative value (e.g. -2.0) discourages allowing the agent's
battalion to be broken. Set to 0.0 (default) to disable.
envs.reward.RewardComponents
dataclass
¶
Per-component reward breakdown for a single environment step.
Use components.total to obtain the scalar reward to return from
env.step(). The individual fields can be logged to W&B for
analysis of the learning signal.
Source code in envs/reward.py
total
property
¶
Scalar sum of all reward components.
as_dict()
¶
Return a {component_name: value} mapping suitable for logging.
Source code in envs/reward.py
envs.reward.compute_reward(*, dmg_b2r, dmg_r2b, blue_strength, blue_won, blue_lost, weights, enemy_routed=False, own_routing=False)
¶
Compute all reward components for a single environment step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dmg_b2r
|
float
|
Damage dealt by Blue to Red this step (strength-fraction units,
typically in |
required |
dmg_r2b
|
float
|
Damage dealt by Red to Blue this step. |
required |
blue_strength
|
float
|
Blue's current strength after casualties (used for the survival
bonus), in |
required |
blue_won
|
bool
|
|
required |
blue_lost
|
bool
|
|
required |
weights
|
RewardWeights
|
:class: |
required |
enemy_routed
|
bool
|
|
False
|
own_routing
|
bool
|
|
False
|
Returns:
| Type | Description |
|---|---|
RewardComponents
|
Individual reward components; call |
Source code in envs/reward.py
Configuration types¶
envs.battalion_env.LogisticsConfig
dataclass
¶
Configurable parameters for the supply, ammunition, and fatigue model.
Pass an instance to :class:~envs.battalion_env.BattalionEnv (via the
logistics_config parameter) to enable the full logistics model. All
parameters have historically-informed defaults; adjust them to tune
scenario difficulty.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
initial_ammo
|
float
|
Starting ammunition level in |
DEFAULT_INITIAL_AMMO
|
initial_food
|
float
|
Starting food/water level in |
DEFAULT_INITIAL_FOOD
|
ammo_per_volley
|
float
|
Ammunition consumed per unit of fire intensity per step. A value
of |
0.01
|
food_per_step
|
float
|
Food/water consumed per simulation step regardless of activity. Models the steady drain of rations on campaign. |
0.0005
|
fatigue_per_move_step
|
float
|
Fatigue accumulated per step when the unit is moving ( |
0.002
|
fatigue_per_fire_step
|
float
|
Fatigue accumulated per step when the unit is firing ( |
0.001
|
fatigue_recovery_per_halt_step
|
float
|
Fatigue recovered per step when the unit is stationary and not
firing. Should exceed |
0.003
|
resupply_radius
|
float
|
Distance in metres within which a battalion can draw on a supply wagon. The unit must be within this radius and the wagon must be alive. |
100.0
|
ammo_resupply_rate
|
float
|
Ammunition recovered per step while within resupply radius. |
0.02
|
food_resupply_rate
|
float
|
Food/water recovered per step while within resupply radius. |
0.01
|
low_ammo_accuracy_penalty
|
float
|
Multiplicative fire-intensity modifier applied when ammo is below
:data: |
0.5
|
fatigue_speed_penalty
|
float
|
Maximum fractional speed reduction at full fatigue ( |
0.3
|
fatigue_accuracy_penalty
|
float
|
Maximum fractional fire-intensity reduction at full fatigue. Applies the same capped formula as fatigue_speed_penalty. |
0.2
|
enable_resupply
|
bool
|
When |
True
|
wagon_speed
|
float
|
Maximum movement speed of supply wagons (metres per step at dt=1). Wagons are slow: ~10 m/step vs 50 m/step for infantry. |
10.0
|
wagon_max_strength
|
float
|
Initial strength of a new supply wagon in |
1.0
|
Source code in envs/sim/logistics.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
envs.battalion_env.MoraleConfig
dataclass
¶
Configurable parameters for the morale state machine.
Pass an instance to :func:update_morale, :class:~envs.sim.engine.SimEngine,
or :class:~envs.battalion_env.BattalionEnv to enable the full morale
stressor model. All parameters have sensible defaults; tweak them to
adjust scenario difficulty or historical calibration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cohesion_threshold
|
float
|
Morale below this value causes cohesion loss. The
:func: |
DEFAULT_COHESION_THRESHOLD
|
rout_threshold
|
float
|
Morale below this value triggers the probabilistic routing check.
Must be |
DEFAULT_ROUT_THRESHOLD
|
base_recovery_rate
|
float
|
Passive morale recovery per step when the unit is not under fire. Increase to make recovery faster (easier scenario). |
0.01
|
distance_recovery_bonus
|
float
|
Additional recovery per step, scaled by |
0.01
|
friendly_support_bonus
|
float
|
Per-step morale bonus when a friendly unit is within
|
0.015
|
commander_proximity_bonus
|
float
|
Per-step morale bonus when the brigade commander is within
|
0.02
|
commander_range
|
float
|
Radius in metres within which the commander or a friendly unit must be to grant a proximity bonus. |
300.0
|
rally_threshold_multiplier
|
float
|
A routing unit can only attempt to rally once its morale has
recovered to at least |
2.0
|
rally_probability
|
float
|
Probability per step that a unit attempts to rally (given it has reached the rally morale gate). |
0.05
|
rout_speed_multiplier
|
float
|
Routing units move at |
1.5
|
safe_distance
|
float
|
Reference distance (metres) used to normalise the distance recovery
bonus. Units at or beyond this distance from the enemy receive the
full |
400.0
|
Source code in envs/sim/morale.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
envs.battalion_env.WeatherConfig
dataclass
¶
All tunable parameters for the weather and time-of-day system.
Pass an instance to :class:~envs.battalion_env.BattalionEnv via the
weather_config argument to enable the full weather model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fixed_condition
|
Optional[WeatherCondition]
|
Force a specific :class: |
None
|
fixed_time_of_day
|
Optional[TimeOfDay]
|
Force a specific :class: |
None
|
steps_per_time_of_day
|
int
|
Number of simulation steps between time-of-day transitions.
|
0
|
condition_weights
|
List[float]
|
Sampling weights for :class: |
(lambda: [0.4, 0.25, 0.15, 0.1, 0.1])()
|
base_visibility_range
|
float
|
Base visibility range in metres before weather modification (> 0).
The combined |
DEFAULT_BASE_VISIBILITY_RANGE
|
Source code in envs/sim/weather.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | |
envs.battalion_env.Formation
¶
Bases: IntEnum
Discrete formation states for a Napoleonic infantry battalion.
The integer values are stable indices used in observation vectors and action spaces; do not change them without updating downstream code.
========== === ==================================================== Formation Int Historical role ========== === ==================================================== LINE 0 Two- or three-rank line — maximum firepower front. COLUMN 1 Attack or march column — highest movement speed. SQUARE 2 Hollow square — impenetrable to unsupported cavalry. SKIRMISH 3 Extended order — loose screen, independent aimed fire. ========== === ====================================================
Source code in envs/sim/formations.py
Simulation primitives¶
envs.sim.engine.SimEngine
¶
Run a 1v1 battalion episode to completion.
Each :meth:step:
- Resets per-step damage accumulators on both :class:
CombatStateobjects. - Computes fire damage from both sides simultaneously (before applying either, so there are no ordering effects on damage calculation).
- Applies terrain cover to reduce incoming damage at each unit's position.
- Applies casualties and updates strength.
- Runs a morale check for each unit, potentially triggering routing.
The episode ends (:meth:is_over returns True) when:
- Either side's :class:
CombatStatereportsis_routing = True, or - Either side's strength falls to :data:
DESTROYED_THRESHOLDor below, or step_countreachesmax_steps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
blue
|
Battalion
|
The two opposing battalions. Modified in-place by each step. |
required |
red
|
Battalion
|
The two opposing battalions. Modified in-place by each step. |
required |
terrain
|
Optional[TerrainMap]
|
Optional :class: |
None
|
max_steps
|
int
|
Hard cap on episode length (default 500, matching acceptance criterion AC-1 of Epic E1.2). |
500
|
rng
|
Optional[Generator]
|
Seeded random generator. Defaults to a fresh unseeded generator. Pass a seeded generator for reproducible results. |
None
|
Source code in envs/sim/engine.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | |
is_over()
¶
Return True when the episode should end.
run()
¶
step()
¶
Advance one simulation step.
Returns:
| Type | Description |
|---|---|
dict with keys:
|
|
Source code in envs/sim/engine.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
envs.sim.engine.EpisodeResult
dataclass
¶
Summary returned by :meth:SimEngine.run.
Attributes:
| Name | Type | Description |
|---|---|---|
winner |
int | None
|
|
steps |
int
|
Number of simulation steps taken. |
blue_strength, red_strength |
Final strength values in |
|
blue_morale, red_morale |
Final morale values in |
|
blue_routed, red_routed |
Whether each side is routing at episode end. |
Source code in envs/sim/engine.py
HRL options framework¶
envs.options.MacroAction
¶
Bases: IntEnum
Indices for the six standard macro-actions in the SMDP vocabulary.
Source code in envs/options.py
envs.options.Option
dataclass
¶
An SMDP Option — a temporally-extended macro-action.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Human-readable label used in logging and debugging. |
required |
initiation_set
|
Callable[[ndarray], bool]
|
Callable |
required |
policy
|
Callable[[ndarray], ndarray]
|
Callable |
required |
termination
|
Callable[[ndarray, int], bool]
|
Callable |
required |
max_steps
|
int
|
Hard cap on option duration in primitive steps. The option is
forced to terminate once |
50
|
Source code in envs/options.py
can_initiate(obs)
¶
get_action(obs)
¶
Return a primitive action from this option's policy for obs.
The returned action is validated to ensure it matches the expected
shape (3,) and contains only finite values. This provides
earlier and more informative errors than downstream index failures
in the environment step logic.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the policy returns an action with shape other than |
Source code in envs/options.py
should_terminate(obs, steps_active)
¶
Return True if this option should terminate.
Terminates when the hard cap max_steps is reached or the
caller-supplied termination callable returns True.
Source code in envs/options.py
envs.options.make_default_options(max_steps=30)
¶
Return the six-element default macro-action vocabulary.
All option policies use only the agent's self-state (obs[0:6])
which occupies fixed positions in every observation regardless of team
size. This makes the options environment-agnostic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_steps
|
int
|
Maximum primitive steps per option execution (time-limit
termination). Flanking options use |
30
|
Returns:
| Type | Description |
|---|---|
list[Option]
|
Six |
Source code in envs/options.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
envs.smdp_wrapper.SMDPWrapper
¶
Bases: ParallelEnv
PettingZoo ParallelEnv wrapping MultiBattalionEnv with SMDP options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env
|
MultiBattalionEnv
|
The underlying :class: |
required |
options
|
Optional[list[Option]]
|
Option vocabulary — a list of :class: |
None
|
Source code in envs/smdp_wrapper.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 | |
temporal_abstraction_ratio
property
¶
Macro-steps / primitive-steps for the current episode.
Returns 0.0 before the first macro-step completes.
action_space(agent)
¶
close()
¶
observation_space(agent)
¶
render()
¶
reset(seed=None, options=None)
¶
Reset the environment and return initial observations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seed
|
Optional[int]
|
RNG seed forwarded to the underlying environment. |
None
|
options
|
Optional[dict]
|
Currently unused; accepted for API compatibility. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
observations |
dict[agent_id, ndarray]
|
|
infos |
dict[agent_id, dict]
|
|
Source code in envs/smdp_wrapper.py
state()
¶
step(macro_actions)
¶
Execute one macro-step.
Runs each agent's chosen option for multiple primitive steps until all active options have terminated (option termination condition fires, hard time-limit reached, or the underlying env terminates the agent).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
macro_actions
|
dict[str, int]
|
Dict mapping each live agent ID to a macro-action index
|
required |
Returns:
| Type | Description |
|---|---|
(observations, aggregate_rewards, terminated, truncated, infos)
|
Keyed by agent IDs that were alive at the start of this macro-step, matching the PettingZoo convention. |
Source code in envs/smdp_wrapper.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | |