Skip to content

Commit

Permalink
Add final features and some docs
Browse files Browse the repository at this point in the history
Signed-off-by: jparisu <[email protected]>
  • Loading branch information
jparisu committed Jan 31, 2024
1 parent e8706a6 commit 153ab38
Show file tree
Hide file tree
Showing 16 changed files with 330 additions and 31 deletions.
10 changes: 9 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,13 @@
:maxdepth: 2
:hidden:

/src/getting_started
/src/installation
/src/tutorial
/src/tlnr

.. toctree::
:caption: Elements
:maxdepth: 2
:hidden:

/src/elements/elements
14 changes: 14 additions & 0 deletions docs/src/elements/elements.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.. _elements:

########
Elements
########

.. toctree::
:caption: Project
:maxdepth: 2
:hidden:

terrain
measure
generation
10 changes: 10 additions & 0 deletions docs/src/elements/generation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.. _elements_generation:

################
Generate Terrain
################

.. warning::

Coming soon.
TODO
10 changes: 10 additions & 0 deletions docs/src/elements/measure.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.. _elements_measure:

######################
Path and Measure tools
######################

.. warning::

Coming soon.
TODO
10 changes: 10 additions & 0 deletions docs/src/elements/terrain.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.. _elements_terrain:

#######
Terrain
#######

.. warning::

Coming soon.
TODO
20 changes: 0 additions & 20 deletions docs/src/getting_started.rst

This file was deleted.

51 changes: 51 additions & 0 deletions docs/src/tldr.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
.. _tldr:

#####
TL;DR
#####

================
Project Overview
================

This project helps you to generate 2D terrains, that are matrix of integers, with a point of origin and a point of destination.
Over these terrains you have several features:

- You can print it in the console
- You can plot it in a matplotlib 2D plot
- You can plot it in 3D with different angles
- **You can check the total path of a given path**
- You can even draw the paths in the plots previously mentioned


============
Installation
============

Just use the following command in your notebook:

.. code-block:: py
!pip install git+https://github.com/jparisu/sIArena.git
Check the :ref:`installation guide <installation>` for more details.


=========================
How to generate a terrain
=========================

.. warning::

Coming soon.
TODO


=====================================
How to write a path finding algorithm
=====================================

.. warning::

Coming soon.
TODO
10 changes: 10 additions & 0 deletions docs/src/tutorial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.. _tutorial:

########
Tutorial
########

.. warning::

Coming soon.
TODO
4 changes: 3 additions & 1 deletion src/sIArena/measurements/measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ def measure_function(
search_function,
terrain: Terrain,
iterations: int = 1,
debug: bool = False
debug: bool = False,
max_seconds: float = 60*5
) -> Tuple[int, float, Path]:
"""
This function uses a search function to calculate a path from the beggining to the end of a terrain.
Expand All @@ -35,6 +36,7 @@ def measure_function(
if debug:
print(f"Running iteration {i}...")

# TODO add max time stop
timer = Timer()
path = search_function(terrain)
times.append(timer.elapsed_s())
Expand Down
4 changes: 4 additions & 0 deletions src/sIArena/terrain/Terrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ def __init__(

if self.origin is None:
self.origin = (0, 0)
else:
self.origin = (origin[0], origin[1])

if self.destination is None:
self.destination = (self.n - 1, self.m - 1)
else:
self.destination = (destination[0], destination[1])

# Check that the origin is valid
if self.origin[0] < 0 and self.origin[0] >= self.n:
Expand Down
2 changes: 0 additions & 2 deletions src/sIArena/terrain/generator/FocusedGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ def generate_random_matrix_(
matrix[i][j] = FocusedGenerator.focused_value_generator(
[matrix[i - 1][j], matrix[i][j - 1]], abruptness)

print(matrix)

return matrix


Expand Down
10 changes: 7 additions & 3 deletions src/sIArena/terrain/generator/Generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,15 @@ def generate_random_terrain(
m = scalade(m, min_height, vmax)

# Convert the matrix to integers using numpy
m = np.array(m, dtype=int)
final_m = np.zeros(m.shape, dtype=int)
for i in range(m.shape[0]):
for j in range(m.shape[1]):
final_m[i,j] = round(m[i,j])

m *= min_step
final_m *= min_step

return Terrain(final_m, origin=origin, destination=destination)

return Terrain(m, origin=origin, destination=destination)

@pure_virtual
def generate_random_matrix_(
Expand Down
30 changes: 30 additions & 0 deletions src/sIArena/terrain/generator/easy_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

from sIArena.terrain.Terrain import Coordinate, Terrain
from sIArena.terrain.generator.Generator import TerrainGenerator
from sIArena.terrain.generator.PernilGenerator import PernilGenerator
from sIArena.terrain.generator.FocusedGenerator import FocusedGenerator


def generate_random_terrain(
generator_ctor: TerrainGenerator,
n: int,
m: int,
min_height: int = 0,
max_height: int = 99,
min_step: int = 1,
abruptness: float = 0.2,
seed: int = None,
origin: Coordinate = None,
destination: Coordinate = None
) -> Terrain:
return generator_ctor().generate_random_terrain(
n=n,
m=m,
min_height=min_height,
max_height=max_height,
min_step=min_step,
abruptness=abruptness,
seed=seed,
origin=origin,
destination=destination
)
Loading

0 comments on commit 153ab38

Please sign in to comment.