Skip to content

Commit

Permalink
foi
Browse files Browse the repository at this point in the history
  • Loading branch information
yaansz committed Oct 15, 2021
1 parent 665a60e commit ae53bf7
Showing 1 changed file with 14 additions and 101 deletions.
115 changes: 14 additions & 101 deletions week-1/practice-week-2-1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
{
"cell_type": "code",
"execution_count": 42,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -67,7 +67,7 @@
},
{
"cell_type": "code",
"execution_count": 43,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -84,7 +84,7 @@
},
{
"cell_type": "code",
"execution_count": 44,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -120,70 +120,6 @@
" return self.direction\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Agente Inteligente"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {},
"outputs": [],
"source": [
"import random\n",
"import typing\n",
"import logging\n",
"\n",
"class SmartAgent(Agent):\n",
"\n",
" def __init__(self, location: int):\n",
" # Default init\n",
" self.performance = 0\n",
"\n",
" # IDK ABOUT THAT\n",
" self.direction = 1\n",
" \n",
" self.location = location\n",
" \n",
" \n",
" def act(self, env):\n",
" if env.floor_is_clean() is True:\n",
" logging.debug(\"Parado na casa \" + str(self.location))\n",
" return AGENT_STATE[\"NoOp\"]\n",
" \n",
" elif env.rooms[self.location] == FLOOR_STATE[\"dirty\"]:\n",
" env.rooms[self.location] = FLOOR_STATE[\"clean\"]\n",
" return AGENT_STATE[\"clean\"]\n",
" \n",
" elif self.location == 0:\n",
" self.direction = AGENT_STATE[\"right\"]\n",
" elif self.location == len(env.rooms) - 1:\n",
" self.direction = AGENT_STATE[\"left\"]\n",
" else:\n",
" right = 0\n",
" left = 0\n",
" # Encontrar a sujeira mais próxima\n",
" for i in range(self.location - 1, -1, -1):\n",
" left += 1\n",
"\n",
" if env.rooms[i] == FLOOR_STATE[\"dirty\"]:\n",
" break\n",
" for i in range(self.location + 1, len(env.rooms)):\n",
" right += 1\n",
" if env.rooms[i] == FLOOR_STATE[\"dirty\"]:\n",
" break\n",
"\n",
" self.direction = 1 if right < left else -1\n",
"\n",
" logging.debug(\"Movendo de \" + str(self.location) + \" para \" + str(self.location + self.direction))\n",
" self.location += self.direction\n",
" \n",
" return self.direction\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -194,7 +130,7 @@
},
{
"cell_type": "code",
"execution_count": 46,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -236,10 +172,6 @@
" if choice == AGENT_STATE[\"clean\"]:\n",
" self.agent.performance += 1\n",
" \n",
" elif choice is AGENT_STATE[\"right\"] or choice is AGENT_STATE[\"left\"]:\n",
" self.agent.performance -= 1\n",
" # Raise an exception ????????\n",
" \n",
" return\n",
"\n",
"\n",
Expand All @@ -263,7 +195,7 @@
},
{
"cell_type": "code",
"execution_count": 47,
"execution_count": 5,
"metadata": {
"scrolled": false
},
Expand All @@ -273,25 +205,15 @@
"output_type": "stream",
"text": [
"\u001b[32mDumb Agent: \u001b[0m\n",
"\u001b[32mPassos: 1000, Pontuação: -122, Sala: [0, 0], Inicial: 0\u001b[0m\n",
"\u001b[32mPassos: 1000, Pontuação: -116, Sala: [0, 0], Inicial: 1\u001b[0m\n",
"\u001b[32mPassos: 1000, Pontuação: -156, Sala: [0, 1], Inicial: 0\u001b[0m\n",
"\u001b[32mPassos: 1000, Pontuação: -164, Sala: [0, 1], Inicial: 1\u001b[0m\n",
"\u001b[32mPassos: 1000, Pontuação: -170, Sala: [1, 0], Inicial: 0\u001b[0m\n",
"\u001b[32mPassos: 1000, Pontuação: -168, Sala: [1, 0], Inicial: 1\u001b[0m\n",
"\u001b[32mPassos: 1000, Pontuação: -164, Sala: [1, 1], Inicial: 0\u001b[0m\n",
"\u001b[32mPassos: 1000, Pontuação: -142, Sala: [1, 1], Inicial: 1\u001b[0m\n",
"\u001b[32mMédia da pontuação: -150.25\u001b[0m\n",
"\u001b[32mSmart Agent: \u001b[0m\n",
"\u001b[32mPassos: 1000, Pontuação: 233, Sala: [0, 0], Inicial: 0\u001b[0m\n",
"\u001b[32mPassos: 1000, Pontuação: 230, Sala: [0, 0], Inicial: 1\u001b[0m\n",
"\u001b[32mPassos: 1000, Pontuação: 239, Sala: [0, 1], Inicial: 0\u001b[0m\n",
"\u001b[32mPassos: 1000, Pontuação: 213, Sala: [0, 1], Inicial: 1\u001b[0m\n",
"\u001b[32mPassos: 1000, Pontuação: 226, Sala: [1, 0], Inicial: 0\u001b[0m\n",
"\u001b[32mPassos: 1000, Pontuação: 231, Sala: [1, 0], Inicial: 1\u001b[0m\n",
"\u001b[32mPassos: 1000, Pontuação: 214, Sala: [1, 1], Inicial: 0\u001b[0m\n",
"\u001b[32mPassos: 1000, Pontuação: 210, Sala: [1, 1], Inicial: 1\u001b[0m\n",
"\u001b[32mMédia da pontuação: 224.5\u001b[0m\n"
"\u001b[32mPassos: 1000, Pontuação: 419, Sala: [0, 0], Inicial: 0\u001b[0m\n",
"\u001b[32mPassos: 1000, Pontuação: 417, Sala: [0, 0], Inicial: 1\u001b[0m\n",
"\u001b[32mPassos: 1000, Pontuação: 420, Sala: [0, 1], Inicial: 0\u001b[0m\n",
"\u001b[32mPassos: 1000, Pontuação: 448, Sala: [0, 1], Inicial: 1\u001b[0m\n",
"\u001b[32mPassos: 1000, Pontuação: 444, Sala: [1, 0], Inicial: 0\u001b[0m\n",
"\u001b[32mPassos: 1000, Pontuação: 417, Sala: [1, 0], Inicial: 1\u001b[0m\n",
"\u001b[32mPassos: 1000, Pontuação: 420, Sala: [1, 1], Inicial: 0\u001b[0m\n",
"\u001b[32mPassos: 1000, Pontuação: 424, Sala: [1, 1], Inicial: 1\u001b[0m\n",
"\u001b[32mMédia da pontuação: 426.125\u001b[0m\n"
]
}
],
Expand Down Expand Up @@ -326,15 +248,6 @@
" performancesDumb.append(evaluate(env_config, DumbAgent(agent_position), 50, 1000))\n",
" logging.info(f\"Passos: 1000, Pontuação: {performancesDumb[-1]}, Sala: {env_config}, Inicial: {agent_position}\")\n",
" logging.info(\"Média da pontuação: \" + str(sum(performancesDumb) / len(performancesDumb) ))\n",
"\n",
"\n",
" logging.info(\"Smart Agent: \")\n",
" for env_config in env_possible:\n",
" for agent_position in agent_possible:\n",
" performancesSmart.append(evaluate(env_config, SmartAgent(agent_position), 50, 1000))\n",
" logging.info(f\"Passos: 1000, Pontuação: {performancesSmart[-1]}, Sala: {env_config}, Inicial: {agent_position}\")\n",
" logging.info(\"Média da pontuação: \" + str(sum(performancesSmart) / len(performancesSmart) ))\n",
"\n",
"main()"
]
},
Expand Down

0 comments on commit ae53bf7

Please sign in to comment.