Skip to content

Commit

Permalink
fix pernil for perlin
Browse files Browse the repository at this point in the history
Signed-off-by: jparisu <[email protected]>
  • Loading branch information
jparisu committed Aug 27, 2024
1 parent 077e74a commit b5cb2af
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 22 deletions.
File renamed without changes
4 changes: 2 additions & 2 deletions docs/resources/scripts/tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#####################################################################

from sIArena.terrain.Terrain import Coordinate, Terrain, Path
from sIArena.terrain.generator.PernilGenerator import PernilGenerator
from sIArena.terrain.generator.PerlinGenerator import PerlinGenerator

terrain = PernilGenerator().generate_random_terrain(
terrain = PerlinGenerator().generate_random_terrain(
n=25,
m=25,
min_height=0,
Expand Down
4 changes: 2 additions & 2 deletions docs/rst/getting_started/tldr.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ Use the following code changing some parameters:
from sIArena.terrain.generator.Generator import TerrainGenerator
from sIArena.terrain.generator.FocusedGenerator import FocusedGenerator
from sIArena.terrain.generator.PernilGenerator import PernilGenerator
from sIArena.terrain.generator.PerlinGenerator import PerlinGenerator
terrain = PernilGenerator().generate_random_terrain(
terrain = PerlinGenerator().generate_random_terrain(
n=20,
m=20,
min_height=0,
Expand Down
8 changes: 4 additions & 4 deletions docs/rst/modules/generation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ There exist different generators that create the random matrix from different cr
.. code-block:: python
from sIArena.terrain.generator.FocusedGenerator import FocusedGenerator
from sIArena.terrain.generator.PernilGenerator import PernilGenerator
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``:
Expand All @@ -57,7 +57,7 @@ It tends to create very craggy and with diagonal mountains.
.. image:: /resources/images/focused100x100_0.png


Pernil Generator
Perlin Generator
================

This generator uses perlin noise to generate the terrain.
Expand All @@ -66,9 +66,9 @@ It tends to create smooth terrains with some hills and valleys.

.. code-block:: python
terrain = PernilGenerator().generate_random_terrain(n=100, m=100, seed=0)
terrain = PerlinGenerator().generate_random_terrain(n=100, m=100, seed=0)
.. image:: /resources/images/pernil100x100_0.png
.. image:: /resources/images/perlin100x100_0.png



Expand Down
2 changes: 1 addition & 1 deletion docs/spelling/spelling_wordlist.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Colab
IArena
sIArena
pernil
perlin
4 changes: 2 additions & 2 deletions resources/measurement_template.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"\n",
"from sIArena.terrain.plot.plot_2D import plot_terrain_2D\n",
"from sIArena.terrain.plot.plot_3D import plot_terrain_3D\n",
"from sIArena.terrain.generator.PernilGenerator import PernilGenerator\n",
"from sIArena.terrain.generator.PerlinGenerator import PerlinGenerator\n",
"\n",
"N = 50\n",
"M = 50\n",
Expand All @@ -32,7 +32,7 @@
"ORIGIN = None\n",
"DESTINATION = None\n",
"\n",
"terrain = PernilGenerator().generate_random_terrain(\n",
"terrain = PerlinGenerator().generate_random_terrain(\n",
" n=N,\n",
" m=M,\n",
" min_height=MIN_HEIGHT,\n",
Expand Down
17 changes: 10 additions & 7 deletions src/sIArena/terrain/Terrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,16 @@ def get_path_cost(self, path: Path) -> int:
return cost


def is_complete_path(self, path: Path) -> Tuple[bool, str]:
def is_complete_path(self, path: Path) -> bool:
"""True if valid path"""
return self.is_valid_path(path)


def is_valid_path(self, path: Path) -> bool:
return self.why_valid_path()[0]
return self.why_valid_path(path)[0]

def why_valid_path(self, path: Path) -> Tuple[bool, str]:
"""Returns True if the given path is valid"""
return self.why_valid_path(path)

def why_valid_path(self, path: Path) -> Tuple[bool, str]:
"""Returns True if the given path is valid"""
Expand Down Expand Up @@ -189,12 +192,12 @@ def __init__(


def is_complete_path(self, path: Path) -> bool:
return self.is_complete_path()[0]
return self.why_complete_path(path)[0]

def why_complete_path(self, path: Path) -> Tuple[bool, str]:
"""Returns True if the given path goes from the origin to the destination"""
# Check that the path is valid
valid = self.is_valid_path(path)
valid = self.why_valid_path(path)
if not valid[0]:
return valid

Expand Down Expand Up @@ -282,12 +285,12 @@ def __init__(


def is_complete_path(self, path: Path) -> bool:
return self.why_complete_path()[0]
return self.why_complete_path(path)[0]

def why_complete_path(self, path: Path) -> Tuple[bool, str]:
"""Returns True if the given path goes from the origin to all the destinations"""
# Check that the path is valid
valid = self.is_valid_path(path)
valid = self.why_valid_path(path)
if not valid[0]:
return valid

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from sIArena.utils.decorators import override

class PernilGenerator(TerrainGenerator):
class PerlinGenerator(TerrainGenerator):

@override
def generate_random_matrix_(
Expand All @@ -33,12 +33,12 @@ def generate_random_matrix_(
map = np.zeros((n,m))
for i in range(n):
for j in range(m):
map[i][j] = PernilGenerator.pernil_value_generator(
map[i][j] = PerlinGenerator.perlin_value_generator(
i, j, base, scale)
return map


def pernil_value_generator(
def perlin_value_generator(
i: int,
j: int,
base: int,
Expand All @@ -48,7 +48,7 @@ def pernil_value_generator(
lacunarity: float = 2.0
) -> int:
"""
Generates a random value for a cell of a terrain using Pernil noise
Generates a random value for a cell of a terrain using Perlin noise
:param i: row of the cell
:param j: column of the cell
Expand Down

0 comments on commit b5cb2af

Please sign in to comment.