Python package providing a custom environment for simulating tank battles
Project description
Xodia24: PocketTank Environment
Xodia24 is a Python package providing a custom environment for simulating a tank battle scenario where two tanks are positioned on a 2D grid. The objective is to train a Reinforcement Learning (RL) agent to effectively control one of the tanks and shoot at the other tank using different actions such as adjusting power, angle, and moving the tank.
Installation
You can install Xodia24 via pip:
pip install Xodia24
Usage
-
Implementing the Custom Reward Function:
Before training the RL model, it's necessary to implement the reward function according to specific problem requirements. This function should take the difference in distance between the bullet and the target tank as input and return the reward. To implement the custom reward function, you need to subclass the
PocketTank
environment and override thereward
method with your custom implementation. -
Training the RL Model:
After implementing the custom reward function, you can train your RL model using this environment by interacting with it through the
step()
method. Provide actions to the tank and observe the resulting state, reward, and other information.
Example:
# Import the environment
from Xodia24.env import PocketTank
# Train RL model using the environment
# ...
-
Using the Custom PocketTank Environment:
If you want to utilize a custom implementation of the PocketTank environment, you can create your subclass and override the necessary methods. Here's a sample implementation:
Custom PocketTank
from Xodia24.env import PocketTank
from gymnasium import spaces
import numpy as np
class CustomPocketTank(PocketTank):
def __init__(self):
super().__init__()
"""
Define a custom action space but only limit it
dont change actual crux or step function wont work
"""
# Example 1
self.action_space = spaces.MultiDiscrete([100,90,1]) # This limit movement only hit from the current position
# Example 2
self.action_space = spaces.MultiDiscrete([100,45,3]) # Limit the angle
# Example 3
self.action_space = spaces.MultiDiscrete([60,90,3])# Limit the power of firing
def reward(self, diff_distance):
"""
Custom reward function implementation.
Args:
diff_distance (float): Difference in distance between the bullet and the target tank.
Returns:
float: Custom reward value based on the difference in distance.
"""
# Implement your custom reward logic here
custom_reward = 0 # Add your reward Function
return custom_reward
Dependencies
-
gymnasium
: A toolkit for developing and comparing reinforcement learning algorithms. -
numpy
: Library for numerical computations and array operations. -
matplotlib
: Library for creating plots and visualizations.
Action Space
The action space in the Xodia24 PocketTank environment refers to the set of possible actions that the reinforcement learning (RL) agent can take at each time step. In the tank battle scenario, the agent controls one of the tanks and has several actions available to it, including adjusting the power and angle of the tank's cannon and moving the tank across the 2D grid.
Available Actions:
- Adjust Power: The agent can adjust the power setting of the tank's cannon, determining the force with which the projectile is fired.
Range: 0-100
- Adjust Angle: The agent can adjust the angle of the tank's cannon, controlling the direction in which the projectile is launched.
Range: 0 deg - 90 deg
- Move Tank: The agent can move the tank across the 2D grid, changing its position on the battlefield.
0 = Dont move only fire
1 = move +25 and then fire
2 = move -25 and then fire
Observation Space
The observation space refers to the information that the RL agent receives from the environment at each time step. This information helps the agent make decisions about which actions to take in order to achieve its objective. In the Xodia24 PocketTank environment, the observation space includes various features of the battlefield and the tanks' positions.
obs = [x1,x2,b]
x1: Your Tank Location
x2: Enemy Tank Location
b : bullet type ID
Bullet Types
The tank has seven different types of bullets available, each with unique properties and effects. The tank has access to each bullet type an unlimited number of times.
-
Standard Shell:
-
Description: A classic projectile bullet that follows projectile motion.
-
Damage: Deals 20 damage upon hitting the target.
-
Trajectory: Parabolic trajectory determined by initial angle and velocity.
-
ID: 0
-
-
Triple Threat:
-
Description: A bullet that splits into three smaller bullets upon firing.
-
Damage: Each of the three bullets deals 20 damage, similar to the Standard Shell.
-
Trajectory: Parabolic trajectory similar to Standard Shell.
-
ID: 1
-
-
Long Shot:
-
Description: A bullet that deals more damage based on the distance it travels before hitting the ground.
-
Damage: Damage increases as the distance traveled increases.
-
Trajectory: Parabolic trajectory similar to the Standard Shell.
-
ID: 2
-
-
Heavy Impact:
-
Description: A high-damage bullet with limited range and velocity.
-
Damage: Deals 40 damage upon hitting the target.
-
Trajectory: Limited velocity and range compared to other bullets.
-
ID: 3
-
-
Blast Radius:
-
Description: A bullet that causes area damage within a radius of 100.
-
Damage: Deals 10 damage in a radius of 100 around the impact point.
-
Trajectory: Parabolic trajectory similar to the Standard Shell.
-
ID: 4
-
-
Healing Halo:
-
Description: A bullet that heals the tank upon impact.
-
Healing: Heals the tank by 10 points upon hitting the ground or a target.
-
Trajectory: Parabolic trajectory similar to the Standard Shell.
-
ID: 5
-
-
Boomerang Blast:
-
Description: A bullet that follows a unique trajectory resembling a boomerang.
-
Damage: Deals 20 damage upon hitting the target.
-
Trajectory: Follows a curved trajectory that slightly reverses direction, like a boomerang.
-
ID: 6
-
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file Xodia24-0.1.19.tar.gz
.
File metadata
- Download URL: Xodia24-0.1.19.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69e42174df21364b10a3783b6668d4ef6fd3cea5460e25e28295fb3ad94bdc64 |
|
MD5 | ff01ebd59b88378878bac63003b9dde8 |
|
BLAKE2b-256 | 54a4fe1a67a77ddc2e0944cae1aef04b904bd6f48552ab052c08d20f2617b397 |
File details
Details for the file Xodia24-0.1.19-py3-none-any.whl
.
File metadata
- Download URL: Xodia24-0.1.19-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d085e8ce9ddf250a5d858e7916f8279418569a8c5a9d1bf40abb6fb0e80946b |
|
MD5 | 6cbe1f640c08d234281e72f69d4fcbde |
|
BLAKE2b-256 | 823b9ef63ef1b9cbc712b2d41f57d380438cff765445582f7eba5f34f0e825f9 |