Skip to content

Commit 2f09fb7

Browse files
committed
Thursday!
1 parent 8a79c6a commit 2f09fb7

17 files changed

+277
-136
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,4 @@ cython_debug/
158158
# and can be added to the global gitignore or merged into this file. For a more nuclear
159159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160160
#.idea/
161-
src/grid/grid.py
162161
src/profiler.txt

.idea/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/grid-engine.iml

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/profiles_settings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12-dev

README.md

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,59 @@
1-
# grid-engine
1+
# grid-engine
2+
3+
## Description
4+
5+
The **grid-engine** package provides classes for generating and manipulating grids. The grid-engine package is divided into two subpackages: **grid blueprint** and **grid**. The **grid blueprint** subpackage provides classes for generating and manipulating blueprints, which are the foundation of Grid objects created using this module. The **grid** subpackage provides classes for generating and manipulating Grid objects, which are the foundation of the grid engine.
6+
7+
## Usage
8+
9+
To use this package, import the necessary classes and functions. Here's an example:
10+
11+
```python
12+
import grid_engine
13+
from grid_engine import grid
14+
15+
# Create a grid
16+
grid = grid.Grid(cell_size=10, grid_dimensions=(1000, 1000))
17+
18+
# Save a grid
19+
grid.save_grid()
20+
21+
# Load a grid
22+
loaded_grid = grid.Grid.load_grid(1)
23+
```
24+
25+
grid-engine also provides a command line interface. To use it, run the following command:
26+
27+
```bash
28+
python -m grid_engine --help
29+
30+
# Output:
31+
# usage: grid [-h] [-i] [-b BLUEPRINT] [--ascii] [-l LOAD] [-t] [-ns NOISE_SCALE] [-no NOISE_OCTAVES] [-nr NOISE_ROUGHNESS] [-r ROWS] [-c COLUMNS] [-s SIZE] [-S] [-T TYPE] [-v]
32+
33+
# Generate a visualized grid from a blueprint. For producing a blueprint, see the blueprint module.
34+
35+
# options:
36+
# -h, --help show this help message and exit
37+
# -i, --interactive Run an interactive session
38+
# -b BLUEPRINT, --blueprint BLUEPRINT
39+
# Load a blueprint from a file
40+
# --ascii Print the grid as ascii
41+
# -l LOAD, --load LOAD Load a grid from a file
42+
# -t, --terrain Whether to generate terrain with the grid.
43+
# -ns NOISE_SCALE, --noise-scale NOISE_SCALE
44+
# Noise scale
45+
# -no NOISE_OCTAVES, --noise-octaves NOISE_OCTAVES
46+
# Noise octaves
47+
# -nr NOISE_ROUGHNESS, --noise-roughness NOISE_ROUGHNESS
48+
# Noise roughness
49+
# -r ROWS, --rows ROWS Number of rows in the grid
50+
# -c COLUMNS, --columns COLUMNS
51+
# Number of columns in the grid
52+
# -s SIZE, --size SIZE Size of each cell in the grid
53+
# -S, --save Save the grid object to a file
54+
# -T TYPE, --type TYPE Type of file to save the grid as
55+
# -v, --verbose Verbose output
56+
``````
57+
58+
![grid](src/grid/terrain_grids/test_joe6.png)
59+

src/.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12-dev

src/grid/blueprint/README.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Blueprint Package
2+
3+
## Description
4+
5+
The **Blueprint** package provides classes for generating and manipulating blueprints, which are the foundation of Grid objects created using the parent module, [grid engine](https://github.com/primal-coder/grid-engine.git).
6+
7+
## Usage
8+
To use this package, import the necessary classes and functions. Here's an example:
9+
10+
```
11+
from grid_engine.blueprint.grid_blueprint import BaseGridBlueprint, TerrainGridBlueprint
12+
13+
# Create a base grid blueprint
14+
base_blueprint = BaseGridBlueprint(cell_size=10, grid_dimensions=(1000, 1000))
15+
16+
# Create a terrain grid blueprint
17+
terrain_blueprint = TerrainGridBlueprint(cell_size=10, grid_dimensions=(1000, 1000), noise_scale=25, noise_octaves=38, noise_roughness=0.35)
18+
19+
# Save a blueprint
20+
base_blueprint.save_blueprint()
21+
22+
# Load a blueprint
23+
loaded_blueprint = BaseGridBlueprint.load_blueprint(1)
24+
```
25+
26+
# Classes
27+
## BaseGridBlueprint
28+
29+
The BaseGridBlueprint class represents a base blueprint. It provides methods for initializing, setting the dimensions and size of the grid, and accessing and modifying the grid's cells and layers. The coordinates of the cells, by default, extend from the bottom left corner of the grid. The grid is divided into quadrants, which are used to facilitate the processing of the grid. The grid is also represented as a graph, which is used to facilitate pathfinding.
30+
31+
### Properties
32+
- cell_size: Returns the size of a cell.
33+
- grid_dimensions: Returns the dimensions of the grid.
34+
- col_count: Returns the number of columns in the grid.
35+
- grid_width: Returns the width of the grid.
36+
- row_count: Returns the number of rows in the grid.
37+
- grid_height: Returns the height of the grid.
38+
- rank: Returns the rank(rows) of the grid.
39+
- file: Returns the file(columns) of the grid.
40+
- cell_list: Returns the list of cells.
41+
- array: Returns the array of cells.
42+
- dictGrid: Returns the dictionary of cells.
43+
- dictTerrain: Returns the dictionary of terrain information.
44+
- cell_coordinates: Returns the coordinates of the cells.
45+
- quadrants: Returns the quadrants of the grid.
46+
- graph: Returns the graph of the grid.
47+
48+
## TerrainGridBlueprint
49+
50+
The TerrainGridBlueprint class represents a terrain grid blueprint. It inherits from the BaseGridBlueprint class and adds methods for initializing the terrain layer of the blueprint and adjusting the passability of cells based on terrain.
51+
52+
### Properties
53+
Inherits all properties from the BaseGridBlueprint class.
54+
55+
# Extras
56+
57+
The grid_blueprint makes use of the following modules and files:
58+
59+
## grid_processing
60+
61+
The grid_processing module is used by grid_blueprint to facilitate the processing of grids. It provides functions for generating many of the characteristics of the blueprint object.
62+
63+
### Functions
64+
65+
- generate_row_strings: Generates a list of row strings. (i.e. ['a', 'b', 'c', ... , 'z', 'aa', 'ab', ... , 'az', 'ba', 'bb', ...])
66+
- generate_column_strings: Generates a list of column strings. Column strings are padded to 5 characters. (i.e. ['00001', '00002', '00003', ... , '00009', '00010', '00011', ... , '00099', '00100', '00101', ...])
67+
- generate_cell_strings: Generates a list of cells. (i.e. ['a00001', 'a00002', 'a00003', ... , 'a00009', 'a00010', 'a00011', ... , 'a00099', 'a00100', 'a00101', ...])
68+
- get_cell_coordinates: Returns the coordinates of a cell.
69+
- get_grid_dict: Returns a dictionary of cells.
70+
- generate_quadrant_coordinates: Calculates the coordinates of the quadrants for the grid.
71+
- get_quadrant_indices: Assigns quadrant indices.
72+
- generate_adjacency: Generates the adjacency data for the grid.
73+
- get_graph: Returns the graph of the grid.
74+
- process_grid: Performs all grid processing functions and returns a dictionary containing the processed grid data.
75+
76+
## terrain_processing
77+
78+
The terrain_processing module is used by grid_blueprint to facilitate the processing of terrain data. It provides functions for generating the terrain layer of the blueprint object.
79+
80+
### Functions
81+
82+
- load_terrain: Loads terrain data from a file.
83+
- diamond_square: Generates a height map using the diamond-square algorithm.
84+
- perlin_noise: Generates a height map using the perlin noise algorithm.
85+
- generate_terrain_dict: Generates a dictionary of terrain data.
86+
87+
## terrains.json
88+
89+
The terrains.json file contains the terrain data used by the terrain_processing module. It is a dictionary of terrain types. The data is structured as follows:
90+
91+
```
92+
{
93+
"terrain_type": {
94+
"raw_max" : 0.0,
95+
"int": 0,
96+
"color": "COLOR_IDENTIFIER",
97+
"cost_in": 0,
98+
"cost_out": 0,
99+
"char": ""
100+
}
101+
}
102+
```
103+
104+
You can add or remove terrain types from this file to change the terrain types available to the terrain_processing module. Colors can be specified using a color identifier (i.e. "GRASS_GREEN") or a RGBA tuple (i.e (255, 255, 255, 255)).

src/grid/blueprint/grid_processing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def get_grid_dict(cell_strings: List[str], row_strings: List[str], col_strings:
175175
} for i, cell in enumerate(cell_strings)
176176
}
177177

178-
def get_quadrant_coordinates(row_count: int, col_count: int) -> List[List[Tuple[int, int]]]:
178+
def generate_quadrant_coordinates(row_count: int, col_count: int) -> List[List[Tuple[int, int]]]:
179179
"""
180180
Get the coordinates of each quadrant in a grid.
181181
@@ -242,7 +242,7 @@ def get_quadrant_indices(quadrant_coords: List[List[Tuple[int,int]]], grid_dict:
242242
grid_dict[cell]['quadrant_index'] = i
243243
return grid_dict
244244

245-
def get_adjacency(grid_dict: Dict[str, any], row_count: int, col_count: int) -> Dict[str, Any]:
245+
def generate_adjacency(grid_dict: Dict[str, any], row_count: int, col_count: int) -> Dict[str, Any]:
246246
"""
247247
Assign adjacent cells to each cell in a grid.
248248

src/grid/blueprint/terrain_processing.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
'GRASS_GREEN': (84, 139, 84, 255),
1212
'PLAIN_GREEN': (90, 154, 90, 255),
1313
'FOOTHILL_GREEN': (82, 144, 78, 255),
14-
'SEASHELL_WHITE': (255, 245, 238, 255),
15-
'SANDY_GREY': (169, 169, 169, 255),
14+
'BEACH_GREEN': (99, 170, 112, 255),
15+
'SEASHELL_WHITE': (249, 235, 231, 255),
16+
'SANDSTONE_GREY': (169, 169, 169, 255),
17+
'SANDY_GREY': (188, 182, 134),
1618
'MOUND_GREY': (105, 105, 105, 255),
1719
'BASE_GREY': (112, 128, 136, 255),
1820
'SIDE_GREY': (79, 83, 72, 255),

src/grid/blueprint/terrains.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"default": {
33
"MOUNTAIN_PEAK": {
4-
"raw_max": 0.12,
4+
"raw_max": 0.1,
55
"int": 0,
66
"color": "SNOW_WHITE",
77
"cost_in": Infinity,
@@ -17,39 +17,39 @@
1717
"char": "|"
1818
},
1919
"MOUNTAIN_SIDE": {
20-
"raw_max": 0.18,
20+
"raw_max": 0.2,
2121
"int": 1,
2222
"color": "SIDE_GREY",
2323
"cost_in": Infinity,
2424
"cost_out": 5,
2525
"char": "/"
2626
},
2727
"MOUNTAIN_BASE": {
28-
"raw_max": 0.23,
28+
"raw_max": 0.25,
2929
"int": 2,
3030
"color": "BASE_GREY",
3131
"cost_in": Infinity,
3232
"cost_out": 0,
3333
"char": "-"
3434
},
3535
"MOUND": {
36-
"raw_max": 0.28,
36+
"raw_max": 0.3,
3737
"int": 3,
3838
"color": "MOUND_GREY",
3939
"cost_in": 2,
4040
"cost_out": 0,
4141
"char": "_"
4242
},
4343
"FOOTHILL": {
44-
"raw_max": 0.43,
44+
"raw_max": 0.45,
4545
"int": 3,
4646
"color": "FOOTHILL_GREEN",
4747
"cost_in": 1,
4848
"cost_out": 0,
4949
"char": " "
5050
},
5151
"GRASS0": {
52-
"raw_max": 0.448,
52+
"raw_max": 0.475,
5353
"int": 4,
5454
"color": "GRASS_GREEN",
5555
"cost_in": 1,
@@ -64,18 +64,18 @@
6464
"cost_out": 1,
6565
"char": " "
6666
},
67-
"GRASS2": {
67+
"BEACH_GRASS": {
6868
"raw_max": 0.488,
6969
"int": 4,
70-
"color": "GRASS_GREEN",
70+
"color": "BEACH_GREEN",
7171
"cost_in": 1,
7272
"cost_out": 0,
7373
"char": " "
7474
},
75-
"GRASS3": {
75+
"SANDSTONE": {
7676
"raw_max": 0.495,
7777
"int": 4,
78-
"color": "PLAIN_GREEN",
78+
"color": "SANDSTONE_GREY",
7979
"cost_in": 0,
8080
"cost_out": 1,
8181
"char": " "
@@ -89,7 +89,7 @@
8989
"char": "."
9090
},
9191
"SEASHELL": {
92-
"raw_max": 0.519,
92+
"raw_max": 0.518,
9393
"int": 6,
9494
"color": "SEASHELL_WHITE",
9595
"cost_in": 1.5,

0 commit comments

Comments
 (0)