Skip to content

Commit 98b6bbd

Browse files
authored
Merge pull request #85 from kywch/rip-vecns
Remove the vec-noise dependency, which crashes pip install
2 parents 4bb1549 + 6392f9e commit 98b6bbd

File tree

5 files changed

+85
-7
lines changed

5 files changed

+85
-7
lines changed

nmmo/core/game_api.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# pylint: disable=no-member,bare-except
22
from abc import ABC, abstractmethod
3-
from typing import Dict, List
3+
from typing import Dict
4+
from collections import deque
45
import dill
56
import numpy as np
67

@@ -24,7 +25,7 @@ def __init__(self, env, sampling_weight=None):
2425
self._agent_stats = {}
2526
self._winners = None
2627
self._game_done = False
27-
self.history: List[Dict] = []
28+
self.history: deque[Dict] = deque(maxlen=100)
2829
assert self.is_compatible(), "Game is not compatible with the config"
2930

3031
@abstractmethod

nmmo/core/terrain.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
import logging
33

44
import numpy as np
5-
import vec_noise
65
from imageio.v2 import imread, imsave
76
from scipy import stats
87

9-
from nmmo.lib import material, seeding, utils
8+
from nmmo.lib import material, seeding, utils, vec_noise
109

1110

1211
def sharp(noise):

nmmo/lib/vec_noise.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import numpy as np
2+
3+
# The noise2() was ported from https://github.com/zbenjamin/vec_noise
4+
5+
# https://github.com/zbenjamin/vec_noise/blob/master/_noise.h#L13
6+
GRAD3 = np.array([
7+
[1,1,0], [-1,1,0], [1,-1,0], [-1,-1,0],
8+
[1,0,1], [-1,0,1], [1,0,-1], [-1,0,-1],
9+
[0,1,1], [0,-1,1], [0,1,-1], [0,-1,-1],
10+
[1,0,-1], [-1,0,-1], [0,-1,1], [0,1,1]
11+
])
12+
13+
# https://github.com/zbenjamin/vec_noise/blob/master/_noise.h#L31
14+
PERM = np.array([
15+
151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140,
16+
36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, 190, 6, 148, 247, 120,
17+
234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33,
18+
88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71,
19+
134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133,
20+
230, 220, 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, 65, 25, 63, 161,
21+
1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, 200, 196, 135, 130,
22+
116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226, 250,
23+
124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, 206, 59, 227,
24+
47, 16, 58, 17, 182, 189, 28, 42, 223, 183, 170, 213, 119, 248, 152, 2, 44,
25+
154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9, 129, 22, 39, 253, 19, 98,
26+
108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228, 251, 34,
27+
242, 193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249, 14,
28+
239, 107, 49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204, 176, 115, 121,
29+
50, 45, 127, 4, 150, 254, 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243,
30+
141, 128, 195, 78, 66, 215, 61, 156, 180
31+
], dtype=np.int32)
32+
PERM = np.concatenate((PERM, PERM))
33+
34+
# 2D simplex skew factors
35+
F2 = 0.5 * (np.sqrt(3.0) - 1.0)
36+
G2 = (3.0 - np.sqrt(3.0)) / 6.0
37+
38+
# https://github.com/zbenjamin/vec_noise/blob/master/_simplex.c#L46
39+
def snoise2(x, y):
40+
"""Generate 2D simplex noise for given coordinates."""
41+
s = (x + y) * F2
42+
i = np.floor(x + s).astype(int)
43+
j = np.floor(y + s).astype(int)
44+
t = (i + j) * G2
45+
46+
x0 = x - (i - t)
47+
y0 = y - (j - t)
48+
49+
# Determine which simplex we're in
50+
i1 = (x0 > y0).astype(int)
51+
j1 = 1 - i1
52+
53+
x1 = x0 - i1 + G2
54+
y1 = y0 - j1 + G2
55+
x2 = x0 - 1 + 2 * G2
56+
y2 = y0 - 1 + 2 * G2
57+
58+
# Hash coordinates of the three simplex corners
59+
ii = i & 255
60+
jj = j & 255
61+
gi0 = PERM[ii + PERM[jj]] % 12
62+
gi1 = PERM[ii + i1 + PERM[jj + j1]] % 12
63+
gi2 = PERM[ii + 1 + PERM[jj + 1]] % 12
64+
65+
# Calculate contribution from three corners
66+
t0 = 0.5 - x0**2 - y0**2
67+
t1 = 0.5 - x1**2 - y1**2
68+
t2 = 0.5 - x2**2 - y2**2
69+
70+
mask0 = (t0 >= 0).astype(float)
71+
mask1 = (t1 >= 0).astype(float)
72+
mask2 = (t2 >= 0).astype(float)
73+
74+
n0 = mask0 * t0**4 * (GRAD3[gi0, 0] * x0 + GRAD3[gi0, 1] * y0)
75+
n1 = mask1 * t1**4 * (GRAD3[gi1, 0] * x1 + GRAD3[gi1, 1] * y1)
76+
n2 = mask2 * t2**4 * (GRAD3[gi2, 0] * x2 + GRAD3[gi2, 1] * y2)
77+
78+
# Sum up and scale the result
79+
return 70 * (n0 + n1 + n2)

nmmo/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '2.1.1'
1+
__version__ = '2.1.2'

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
'scipy==1.10.0',
3939
'pytest==7.3.0',
4040
'pytest-benchmark==3.4.1',
41-
'vec-noise==1.1.4',
4241
'imageio>=2.27',
4342
'ordered-set==4.1.0',
4443
'pettingzoo==1.24.1',
@@ -52,7 +51,7 @@
5251
ext_modules = cythonize(["nmmo/lib/cython_helper.pyx"]),
5352
include_dirs=[np.get_include()],
5453
extras_require=extra,
55-
python_requires=">=3.7",
54+
python_requires=">=3.7,<3.11",
5655
license="MIT",
5756
author="Joseph Suarez",
5857
author_email="[email protected]",

0 commit comments

Comments
 (0)