Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Commented codes in agents.ipynb #805

Merged
merged 2 commits into from Mar 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 15 additions & 15 deletions agents.ipynb
Expand Up @@ -4,6 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"# AGENT #\n",
"\n",
"An agent, as defined in 2.1 is anything that can perceive its <b>environment</b> through sensors, and act upon that environment through actuators based on its <b>agent program</b>. This can be a dog, robot, or even you. As long as you can perceive the environment and act on it, you are an agent. This notebook will explain how to implement a simple agent, create an environment, and create a program that helps the agent act on the environment based on its percepts.\n",
Expand All @@ -17,6 +18,7 @@
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true,
"scrolled": true
},
"outputs": [],
Expand Down Expand Up @@ -80,7 +82,9 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"class Food(Thing):\n",
Expand Down Expand Up @@ -151,7 +155,9 @@
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"class BlindDog(Agent):\n",
Expand All @@ -163,14 +169,12 @@
" def eat(self, thing):\n",
" '''returns True upon success or False otherwise'''\n",
" if isinstance(thing, Food):\n",
" #print(\"Dog: Ate food at {}.\".format(self.location))\n",
" return True\n",
" return False\n",
" \n",
" def drink(self, thing):\n",
" ''' returns True upon success or False otherwise'''\n",
" if isinstance(thing, Water):\n",
" #print(\"Dog: Drank water at {}.\".format(self.location))\n",
" return True\n",
" return False\n",
" \n",
Expand Down Expand Up @@ -456,7 +460,9 @@
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from random import choice\n",
Expand Down Expand Up @@ -487,14 +493,12 @@
" def eat(self, thing):\n",
" '''returns True upon success or False otherwise'''\n",
" if isinstance(thing, Food):\n",
" #print(\"Dog: Ate food at {}.\".format(self.location))\n",
" return True\n",
" return False\n",
" \n",
" def drink(self, thing):\n",
" ''' returns True upon success or False otherwise'''\n",
" if isinstance(thing, Water):\n",
" #print(\"Dog: Drank water at {}.\".format(self.location))\n",
" return True\n",
" return False\n",
" \n",
Expand Down Expand Up @@ -546,11 +550,9 @@
" if action == 'turnright':\n",
" print('{} decided to {} at location: {}'.format(str(agent)[1:-1], action, agent.location))\n",
" agent.turn(Direction.R)\n",
" #print('now facing {}'.format(agent.direction.direction))\n",
" elif action == 'turnleft':\n",
" print('{} decided to {} at location: {}'.format(str(agent)[1:-1], action, agent.location))\n",
" agent.turn(Direction.L)\n",
" #print('now facing {}'.format(agent.direction.direction))\n",
" elif action == 'moveforward':\n",
" loc = copy.deepcopy(agent.location) # find out the target location\n",
" if agent.direction.direction == Direction.R:\n",
Expand All @@ -561,7 +563,6 @@
" loc[1] += 1\n",
" elif agent.direction.direction == Direction.U:\n",
" loc[1] -= 1\n",
" #print('{} at {} facing {}'.format(agent, loc, agent.direction.direction))\n",
" if self.is_inbounds(loc):# move only if the target is a valid location\n",
" print('{} decided to move {}wards at location: {}'.format(str(agent)[1:-1], agent.direction.direction, agent.location))\n",
" agent.moveforward()\n",
Expand Down Expand Up @@ -664,11 +665,9 @@
" if action == 'turnright':\n",
" print('{} decided to {} at location: {}'.format(str(agent)[1:-1], action, agent.location))\n",
" agent.turn(Direction.R)\n",
" #print('now facing {}'.format(agent.direction.direction))\n",
" elif action == 'turnleft':\n",
" print('{} decided to {} at location: {}'.format(str(agent)[1:-1], action, agent.location))\n",
" agent.turn(Direction.L)\n",
" #print('now facing {}'.format(agent.direction.direction))\n",
" elif action == 'moveforward':\n",
" loc = copy.deepcopy(agent.location) # find out the target location\n",
" if agent.direction.direction == Direction.R:\n",
Expand All @@ -679,7 +678,6 @@
" loc[1] += 1\n",
" elif agent.direction.direction == Direction.U:\n",
" loc[1] -= 1\n",
" #print('{} at {} facing {}'.format(agent, loc, agent.direction.direction))\n",
" if self.is_inbounds(loc):# move only if the target is a valid location\n",
" print('{} decided to move {}wards at location: {}'.format(str(agent)[1:-1], agent.direction.direction, agent.location))\n",
" agent.moveforward()\n",
Expand Down Expand Up @@ -1157,7 +1155,9 @@
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from ipythonblocks import BlockGrid\n",
Expand Down Expand Up @@ -1252,7 +1252,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.4rc1"
"version": "3.6.4"
}
},
"nbformat": 4,
Expand Down