Skip to content
This repository was archived by the owner on Aug 18, 2021. It is now read-only.

Commit 5ad67e5

Browse files
committed
Revert "dont use tuple for indexing, addresses #32"
This reverts commit 4e14f39.
1 parent 4e14f39 commit 5ad67e5

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

reinforce-gridworld/reinforce-gridworld.ipynb

+5-8
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@
147147
" E = self.grid_size + VISIBLE_RADIUS - 1\n",
148148
" gps = [(E, E), (S, E), (E, S), (S, S)]\n",
149149
" gp = gps[random.randint(0, len(gps)-1)]\n",
150-
" gy, gx = gp\n",
151-
" self.grid[gy, gx] = GOAL_VALUE\n",
150+
" self.grid[gp] = GOAL_VALUE\n",
152151
" \n",
153152
" def visible(self, pos):\n",
154153
" y, x = pos\n",
@@ -238,8 +237,7 @@
238237
" def record_step(self):\n",
239238
" \"\"\"Add the current state to history for display later\"\"\"\n",
240239
" grid = np.array(self.grid.grid)\n",
241-
" y, x = self.agent.pos\n",
242-
" grid[y, x] = self.agent.health * 0.5 # Agent marker faded by health\n",
240+
" grid[self.agent.pos] = self.agent.health * 0.5 # Agent marker faded by health\n",
243241
" visible = np.array(self.grid.visible(self.agent.pos))\n",
244242
" self.history.append((grid, visible, self.agent.health))\n",
245243
" \n",
@@ -258,9 +256,8 @@
258256
" self.agent.act(action)\n",
259257
" \n",
260258
" # Get reward from where agent landed, add to agent health\n",
261-
" y, x = self.agent.pos\n",
262-
" value = self.grid.grid[y, x]\n",
263-
" self.grid.grid[y, x] = 0\n",
259+
" value = self.grid.grid[self.agent.pos]\n",
260+
" self.grid.grid[self.agent.pos] = 0\n",
264261
" self.agent.health += value\n",
265262
" \n",
266263
" # Check if agent won (reached the goal) or lost (health reached 0)\n",
@@ -710,7 +707,7 @@
710707
"metadata": {
711708
"collapsed": false
712709
},
713-
"outputs": [],
710+
"outputs": [ ],
714711
"source": [
715712
"hidden_size = 50\n",
716713
"learning_rate = 1e-4\n",

0 commit comments

Comments
 (0)