Skip to main content

Tower Defense Environment

A deterministic tower defense game and Gymnasium environment focused on long-term planning in reinforcement learning.

This project provides a custom single-player tower defense environment where an agent must manage resources, place towers, and prepare for future enemy waves. The environment is designed to emphasize delayed consequences and long-term planning rather than only short-term reactions.

The package includes:

  • a Gymnasium compatible reinforcement learning environment
  • a renderable tower defense game mode
  • procedural map generation
  • procedural wave generation
  • default map and wave data
  • command-line tools for generating maps and waves

Installation

Install the package with pip:

pip install dermek-bp-tower-defense-env

Alternatively, clone the GitHub repository and run the Python files directly:

python file_name.py arguments

Command-line tools

After installation, the map generator can be run with:

tower-defense-map-maker --difficulty 10 --seed 42

The wave generator can be run with:

tower-defense-wave-maker --difficulty 10 --num-waves 20 --seed 42

Map generator arguments

  • -h: print available arguments with descrptions
  • --seed: choose a seed for randomness, if not included, chooses a random seed
  • --difficulty: choose a difficulty value, required argument, gets clamped to <1;20>

Wave generator arguments

  • -h: print available arguments with descrptions
  • --seed: choose a seed for randomness, if not included, chooses a random seed
  • --difficulty: choose a difficulty value, required argument
  • --num-waves: choose the number of waves to generate, required argument

Basic usage

Direct package usage

from dermek_bp_tower_defense_env import TowerDefenseEnv

env = TowerDefenseEnv(render_mode="dictionary")

obs, info = env.reset(seed=42)

terminated = False
truncated = False

while not (terminated or truncated):
    action = env.action_space.sample()
    obs, reward, terminated, truncated, info = env.step(action)
    game_state = info.get("game_state")

env.close()

Gymnasium usage

import gymnasium as gym
import dermek_bp_tower_defense_env

env = gym.make("DermekBPTowerDefense-v0", render_mode="dictionary")

obs, info = env.reset(seed=42)

terminated = False
truncated = False

while not (terminated or truncated):
    action = env.action_space.sample()
    obs, reward, terminated, truncated, info = env.step(action)
    game_state = info.get("game_state")

env.close()

Render modes

The environment supports two render modes:

  • dictionary: no visual output, intended for faster reinforcement learning experiments
  • human: renders the game to a Pygame window, intended for demonstration

Observation space

The observation is returned as a dictionary.

The main observation keys are:

  • board: current board state
  • resources: current money, resource 1, resource 2, health and wave index
  • next_wave: enemy composition of the next wave
  • next_3_waves: enemy composition of the next three waves

Action space

The action space is:

MultiDiscrete([3, 3, 10, 10])

The action has the following structure:

[action_type, action_subtype, x, y]

Action type

  • 0: build tower
  • 1: build factory
  • 2: start wave phase

Action subtype

The subtype represents the tower or factory type. It is ignored when starting the wave phase.

Coordinates

The x and y values represent the target tile on the 10x10 board. They are used for building actions and ignored when starting wave phase.

Invalid actions

The environment allows invalid actions. Invalid actions do not change the game state and are penalized through the rewards.

Examples of invalid actions include:

  • building on a path tile
  • building on an occupied tile
  • building without enough resources
  • choosing an invalid building subtype

Reproducibility

The map generator, wave generator and environment reset support seed values. Using the same seeds and configurations should produce reproducible scenarios and environment behavior.

Metadata

Release files for dermek-bp-tower-defense-env 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dermek-bp-tower-defense-env 0.1.5
File Size Uploaded Provenance Actions
dermek_bp_tower_defense_env-0.1.5.tar.gz 29.3 kB Without provenance Details for dermek_bp_tower_defense_env-0.1.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dermek-bp-tower-defense-env 0.1.5
File Interpreter ABI Platform Actions
dermek_bp_tower_defense_env-0.1.5-py3-none-any.whl Python 3 none any Details for dermek_bp_tower_defense_env-0.1.5-py3-none-any.whl

Total release size: 62.0 kB

Release files / dermek_bp_tower_defense_env-0.1.5.tar.gz

Download URL dermek_bp_tower_defense_env-0.1.5.tar.gz
Size 29.3 kB
Tags Source
SHA-256 checksum
How to use checksums
57072bae9b7d35b2e1234cdf7f99df8149488f9e99c3040e2b72c309b23bb19f
BLAKE2b-256 checksum
How to use checksums
b56b090f1abda8715502790f6dba1f375c8832af3d5349e5f35ae4b7fe317708
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.2

Release files / dermek_bp_tower_defense_env-0.1.5-py3-none-any.whl

Download URL dermek_bp_tower_defense_env-0.1.5-py3-none-any.whl
Size 32.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7f0b6a50d9f322afacd404f727c6dbe1455a052eddf0dc53976181ec2aff2fbc
BLAKE2b-256 checksum
How to use checksums
a2f9fb511b4400472a2430d78537f54392325a0111dddbb2db783191e1c68ba8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.2

Security for dermek-bp-tower-defense-env 0.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page