Reset dots to initial positions, and reset RNG seed.
(self)
| 231 | return self.obs, reward, done, intercept |
| 232 | |
| 233 | def reset(self): |
| 234 | """ |
| 235 | Reset dots to initial positions, and reset RNG seed. |
| 236 | """ |
| 237 | |
| 238 | self.ts = 0 # reset timesteps |
| 239 | |
| 240 | # Reset RNG |
| 241 | random.seed(self.seed) |
| 242 | |
| 243 | # provide default observation |
| 244 | self.obs = np.zeros((self.h, self.w)) |
| 245 | |
| 246 | # Set boundaries (so we don't spawn points on the edge. |
| 247 | # Not that there's a real problem with it, but it's boring. |
| 248 | bh1, bh2 = self.h // 5, 4 * self.h // 5 |
| 249 | bw1, bw2 = self.w // 5, 4 * self.w // 5 |
| 250 | |
| 251 | # Start dots in the middle. |
| 252 | # midr = self.h//2 <= we randomize this now. |
| 253 | # midc = self.w//2 |
| 254 | |
| 255 | # We know that the sum from n=0 to n=N of 1 - n/N = (N + 1)/2 |
| 256 | # Thus, computing the initial grid space for a dot, given the |
| 257 | # length of its tail N would be (self.decay + 1)/2. |
| 258 | # But... we also have to cap it at 1. So, who cares? |
| 259 | |
| 260 | # Reinitalize network dot placement. |
| 261 | r, c = random.randint(bh1, bh2), random.randint(bw1, bw2) |
| 262 | self.netDot = Dot(r, c, self.decay) |
| 263 | self.obs[r, c] = 1 |
| 264 | |
| 265 | # Reinitalize target dot placement with initial movement direction. |
| 266 | self.dots = [] |
| 267 | self.dotDir = random.randint(self.minch, self.choices - 1) |
| 268 | for d in range(self.ndots): |
| 269 | r, c = random.randint(bh1, bh2), random.randint(bw1, bw2) |
| 270 | self.dots.append(Dot(r, c, self.decay)) |
| 271 | self.obs[r, c] = 1 |
| 272 | |
| 273 | # Reinitalize red herring placement. |
| 274 | self.herrings = [] |
| 275 | for h in range(self.herrs): |
| 276 | r, c = random.randint(bh1, bh2), random.randint(bw1, bw2) |
| 277 | self.herrings.append(Dot(r, c, self.decay)) |
| 278 | self.obs[r, c] = 1 |
| 279 | |
| 280 | return self.obs |
| 281 | |
| 282 | def movePoint(self, d: Dot, dotDir: int = -1): |
| 283 | """ |