|
17 | 17 | "cell_type": "code",
|
18 | 18 | "execution_count": 1,
|
19 | 19 | "metadata": {
|
20 |
| - "collapsed": false, |
21 | 20 | "scrolled": true
|
22 | 21 | },
|
23 | 22 | "outputs": [],
|
|
44 | 43 | {
|
45 | 44 | "cell_type": "code",
|
46 | 45 | "execution_count": 2,
|
47 |
| - "metadata": { |
48 |
| - "collapsed": false |
49 |
| - }, |
| 46 | + "metadata": {}, |
50 | 47 | "outputs": [
|
51 | 48 | {
|
52 | 49 | "name": "stdout",
|
|
83 | 80 | {
|
84 | 81 | "cell_type": "code",
|
85 | 82 | "execution_count": 3,
|
86 |
| - "metadata": { |
87 |
| - "collapsed": false |
88 |
| - }, |
| 83 | + "metadata": {}, |
89 | 84 | "outputs": [],
|
90 | 85 | "source": [
|
91 | 86 | "class Food(Thing):\n",
|
|
156 | 151 | {
|
157 | 152 | "cell_type": "code",
|
158 | 153 | "execution_count": 4,
|
159 |
| - "metadata": { |
160 |
| - "collapsed": false |
161 |
| - }, |
| 154 | + "metadata": {}, |
162 | 155 | "outputs": [],
|
163 | 156 | "source": [
|
164 | 157 | "class BlindDog(Agent):\n",
|
|
195 | 188 | "cell_type": "markdown",
|
196 | 189 | "metadata": {},
|
197 | 190 | "source": [
|
198 |
| - "Lets now run our simulation by creating a park with some food, water, and our dog." |
| 191 | + "Let's now run our simulation by creating a park with some food, water, and our dog." |
199 | 192 | ]
|
200 | 193 | },
|
201 | 194 | {
|
202 | 195 | "cell_type": "code",
|
203 | 196 | "execution_count": 5,
|
204 |
| - "metadata": { |
205 |
| - "collapsed": false |
206 |
| - }, |
| 197 | + "metadata": {}, |
207 | 198 | "outputs": [
|
208 | 199 | {
|
209 | 200 | "name": "stdout",
|
|
235 | 226 | "source": [
|
236 | 227 | "Notice that the dog moved from location 1 to 4, over 4 steps, and ate food at location 5 in the 5th step.\n",
|
237 | 228 | "\n",
|
238 |
| - "Lets continue this simulation for 5 more steps." |
| 229 | + "Let's continue this simulation for 5 more steps." |
239 | 230 | ]
|
240 | 231 | },
|
241 | 232 | {
|
242 | 233 | "cell_type": "code",
|
243 | 234 | "execution_count": 6,
|
244 |
| - "metadata": { |
245 |
| - "collapsed": false |
246 |
| - }, |
| 235 | + "metadata": {}, |
247 | 236 | "outputs": [
|
248 | 237 | {
|
249 | 238 | "name": "stdout",
|
|
263 | 252 | "cell_type": "markdown",
|
264 | 253 | "metadata": {},
|
265 | 254 | "source": [
|
266 |
| - "Perfect! Note how the simulation stopped after the dog drank the water - exhausting all the food and water ends our simulation, as we had defined before. Lets add some more water and see if our dog can reach it." |
| 255 | + "Perfect! Note how the simulation stopped after the dog drank the water - exhausting all the food and water ends our simulation, as we had defined before. Let's add some more water and see if our dog can reach it." |
267 | 256 | ]
|
268 | 257 | },
|
269 | 258 | {
|
270 | 259 | "cell_type": "code",
|
271 | 260 | "execution_count": 7,
|
272 |
| - "metadata": { |
273 |
| - "collapsed": false |
274 |
| - }, |
| 261 | + "metadata": {}, |
275 | 262 | "outputs": [
|
276 | 263 | {
|
277 | 264 | "name": "stdout",
|
|
298 | 285 | "cell_type": "markdown",
|
299 | 286 | "metadata": {},
|
300 | 287 | "source": [
|
301 |
| - "This is how to implement an agent, its program, and environment. However, this was a very simple case. Lets try a 2-Dimentional environment now with multiple agents.\n", |
| 288 | + "This is how to implement an agent, its program, and environment. However, this was a very simple case. Let's try a 2-Dimentional environment now with multiple agents.\n", |
302 | 289 | "\n",
|
303 | 290 | "\n",
|
304 | 291 | "# 2D Environment #\n",
|
|
349 | 336 | " return dead_agents or no_edibles\n",
|
350 | 337 | "\n",
|
351 | 338 | "class BlindDog(Agent):\n",
|
352 |
| - " location = [0,1]# change location to a 2d value\n", |
353 |
| - " direction = Direction(\"down\")# variable to store the direction our dog is facing\n", |
| 339 | + " location = [0,1] # change location to a 2d value\n", |
| 340 | + " direction = Direction(\"down\") # variable to store the direction our dog is facing\n", |
354 | 341 | " \n",
|
355 | 342 | " def movedown(self):\n",
|
356 | 343 | " self.location[1] += 1\n",
|
|
381 | 368 | "cell_type": "markdown",
|
382 | 369 | "metadata": {},
|
383 | 370 | "source": [
|
384 |
| - "Now lets test this new park with our same dog, food and water" |
| 371 | + "Now let's test this new park with our same dog, food and water" |
385 | 372 | ]
|
386 | 373 | },
|
387 | 374 | {
|
388 | 375 | "cell_type": "code",
|
389 | 376 | "execution_count": 9,
|
390 |
| - "metadata": { |
391 |
| - "collapsed": false |
392 |
| - }, |
| 377 | + "metadata": {}, |
393 | 378 | "outputs": [
|
394 | 379 | {
|
395 | 380 | "name": "stdout",
|
|
436 | 421 | "\n",
|
437 | 422 | "# PROGRAM - EnergeticBlindDog #\n",
|
438 | 423 | "\n",
|
439 |
| - "Lets make our dog turn or move forwards at random - except when he's at the edge of our park - in which case we make him change his direction explicitly by turning to avoid trying to leave the park. Our dog is blind, however, so he wouldn't know which way to turn - he'd just have to try arbitrarily.\n", |
| 424 | + "Let's make our dog turn or move forwards at random - except when he's at the edge of our park - in which case we make him change his direction explicitly by turning to avoid trying to leave the park. Our dog is blind, however, so he wouldn't know which way to turn - he'd just have to try arbitrarily.\n", |
440 | 425 | "\n",
|
441 | 426 | "<table>\n",
|
442 | 427 | " <tr>\n",
|
|
471 | 456 | {
|
472 | 457 | "cell_type": "code",
|
473 | 458 | "execution_count": 10,
|
474 |
| - "metadata": { |
475 |
| - "collapsed": false |
476 |
| - }, |
| 459 | + "metadata": {}, |
477 | 460 | "outputs": [],
|
478 | 461 | "source": [
|
479 | 462 | "from random import choice\n",
|
480 | 463 | "\n",
|
481 |
| - "turn = False# global variable to remember to turn if our dog hits the boundary\n", |
| 464 | + "turn = False # global variable to remember to turn if our dog hits the boundary\n", |
482 | 465 | "class EnergeticBlindDog(Agent):\n",
|
483 | 466 | " location = [0,1]\n",
|
484 | 467 | " direction = Direction(\"down\")\n",
|
|
611 | 594 | {
|
612 | 595 | "cell_type": "code",
|
613 | 596 | "execution_count": 12,
|
614 |
| - "metadata": { |
615 |
| - "collapsed": false |
616 |
| - }, |
| 597 | + "metadata": {}, |
617 | 598 | "outputs": [
|
618 | 599 | {
|
619 | 600 | "name": "stdout",
|
|
653 | 634 | "park.add_thing(water, [2,1])\n",
|
654 | 635 | "morewater = Water()\n",
|
655 | 636 | "park.add_thing(morewater, [0,2])\n",
|
656 |
| - "print('dog started at [0,0], facing down. Lets see if he found any food or water!')\n", |
| 637 | + "print(\"dog started at [0,0], facing down. Let's see if he found any food or water!\")\n", |
657 | 638 | "park.run(20)"
|
658 | 639 | ]
|
659 | 640 | },
|
660 | 641 | {
|
661 | 642 | "cell_type": "markdown",
|
662 | 643 | "metadata": {},
|
663 | 644 | "source": [
|
664 |
| - "This is good, but it still lacks graphics. What if we wanted to visualize our park as it changed? To do that, all we have to do is make our park a subclass of <b>GraphicEnvironment</b> instead of <b>XYEnvironment</b>. Lets see how this looks." |
| 645 | + "This is good, but it still lacks graphics. What if we wanted to visualize our park as it changed? To do that, all we have to do is make our park a subclass of <b>GraphicEnvironment</b> instead of <b>XYEnvironment</b>. Let's see how this looks." |
665 | 646 | ]
|
666 | 647 | },
|
667 | 648 | {
|
|
739 | 720 | "cell_type": "code",
|
740 | 721 | "execution_count": 19,
|
741 | 722 | "metadata": {
|
742 |
| - "collapsed": false, |
743 | 723 | "scrolled": true
|
744 | 724 | },
|
745 | 725 | "outputs": [
|
|
1155 | 1135 | "morefood = Food()\n",
|
1156 | 1136 | "park.add_thing(morewater, [2,4])\n",
|
1157 | 1137 | "park.add_thing(morefood, [4,3])\n",
|
1158 |
| - "print('dog started at [0,0], facing down. Lets see if he found any food or water!')\n", |
| 1138 | + "print(\"dog started at [0,0], facing down. Let's see if he found any food or water!\")\n", |
1159 | 1139 | "park.run(20)"
|
1160 | 1140 | ]
|
1161 | 1141 | },
|
|
1177 | 1157 | {
|
1178 | 1158 | "cell_type": "code",
|
1179 | 1159 | "execution_count": 4,
|
1180 |
| - "metadata": { |
1181 |
| - "collapsed": false |
1182 |
| - }, |
| 1160 | + "metadata": {}, |
1183 | 1161 | "outputs": [],
|
1184 | 1162 | "source": [
|
1185 | 1163 | "from ipythonblocks import BlockGrid\n",
|
|
1221 | 1199 | {
|
1222 | 1200 | "cell_type": "code",
|
1223 | 1201 | "execution_count": 5,
|
1224 |
| - "metadata": { |
1225 |
| - "collapsed": false |
1226 |
| - }, |
| 1202 | + "metadata": {}, |
1227 | 1203 | "outputs": [
|
1228 | 1204 | {
|
1229 | 1205 | "data": {
|
|
1276 | 1252 | "name": "python",
|
1277 | 1253 | "nbconvert_exporter": "python",
|
1278 | 1254 | "pygments_lexer": "ipython3",
|
1279 |
| - "version": "3.4.3" |
| 1255 | + "version": "3.5.4rc1" |
1280 | 1256 | }
|
1281 | 1257 | },
|
1282 | 1258 | "nbformat": 4,
|
1283 |
| - "nbformat_minor": 0 |
| 1259 | + "nbformat_minor": 1 |
1284 | 1260 | }
|
0 commit comments