Skip to content

Commit

Permalink
fix: New seed handling since gym v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
strakam committed Oct 12, 2024
1 parent 5ea1e09 commit 1e79af3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions generals/core/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def grid(self, grid: str | np.ndarray):
first_general = np.argwhere(np.isin(grid, ["A"]))
second_general = np.argwhere(np.isin(grid, ["B"]))
if len(first_general) != 1 or len(second_general) != 1:
raise ValueError("Exactly one 'A' and one 'B' should be present in the grid.")
raise ValueError(
"Exactly one 'A' and one 'B' should be present in the grid."
)

self._grid = grid

Expand Down Expand Up @@ -111,7 +113,10 @@ def grid_from_generator(
if general_positions is None:
general_positions = self.general_positions
if seed is None:
seed = self.seed
if self.seed is None:
seed = np.random.randint(0, 2**20)
else:
seed = self.seed

# Probabilities of each cell type
p_neutral = 1 - mountain_density - city_density
Expand All @@ -120,7 +125,7 @@ def grid_from_generator(
# Place cells on the map
rng = np.random.default_rng(seed)
map = rng.choice(
[PASSABLE, MOUNTAIN, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[PASSABLE, MOUNTAIN, "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
size=grid_dims,
p=probs,
)
Expand All @@ -142,6 +147,7 @@ def grid_from_generator(
try:
return Grid(map_string)
except ValueError:
seed += 1 # Increase seed to generate a different map
return self.grid_from_generator(
grid_dims=grid_dims,
mountain_density=mountain_density,
Expand Down

0 comments on commit 1e79af3

Please sign in to comment.