Generate Terrain
There are several classes that help to generate a random terrain so the user does not have to create the matrix manually.
The class Generator has a function generate_random_terrain that create an object of type Terrain (or DestinationSetTerrain if set).
These are the arguments for such function (some arguments are not used for different Generators):
n: intnumber of rowsm: intnumber of columnsmin_height: int = 0minimum height of the terrainmax_height: int = 99maximum height of the terrainmin_step: int = 1minimum step between two heightsabruptness: float = 0.20: smooth, 1: abruptseed: int = Noneseed for the random number generatororigin: Coordinate = Noneorigin of the terraindestination: Coordinate = Nonedestination of the terrainterrain_ctor: Terrain = Terrainwhether to useTerrain``or ``DestinationSetTerraincost_function: callable = Nonecost function for the terrain (if None use default)
There exist different generators that create the random matrix from different criteria:
from sIArena.terrain.generator.FocusedGenerator import FocusedGenerator
from sIArena.terrain.generator.PerlinGenerator import PerlinGenerator
from sIArena.terrain.generator.MazeGenerator import MazeGenerator
In order to generate a terrain, the user must create a generator object and call the function generate_random_terrain:
generator = FocusedGenerator()
terrain = generator.generate_random_terrain(n=10, m=10)
Focused Generator
This generator generates the map from top-left corner to bottom-right corner. It generates each cell depending on the contiguous cells and a distribution probability.
It tends to create very craggy and with diagonal mountains.
terrain = FocusedGenerator().generate_random_terrain(n=100, m=100, seed=0)
Perlin Generator
This generator uses perlin noise to generate the terrain.
It tends to create smooth terrains with some hills and valleys.
terrain = PerlinGenerator().generate_random_terrain(n=100, m=100, seed=0)
Maze Generator
This generator creates a maze. This is, it creates a terrain with 1 width valley and 1 width very high wall. The valley connects the whole map, so the terrain can be walked through without climbing any wall.
The origin and destination must be set afterwards. It is assured to connect every valley point, and the top-left corner and bottom-right corner are always in a valley.
terrain = MazeGenerator().generate_random_terrain(n=100, m=100, seed=0)