Question: Using AgentPy Provide the code proposed for modeling an agent in a room. Consider the following rules: Environment: A room is a rectangle, arranged in

Using AgentPy Provide the code proposed for modeling an agent in a room. Consider the following rules:
Environment:
A room is a rectangle, arranged in cells, with m
rows and
n columns.
A cell can contain a reward
(
negative value
)
or a penalty
(
positive value
)
.
As the robot passes over the cell, it collects and removes the item it contains.
Agent:
A robot can obtain the information of each cell in the room using a coordinate system
(
row
,
column
)
.
The robot takes
1
unit of time to travel from one cell to any neighboring cell
(
up
,
down, right or left
)
.
The robot spends
1
unit of energy to travel from one cell to any neighboring cell.
The robot's energy is modified according to the values
given in each cell.
The robot stops if there are no more cells with rewards or if its energy runs out.
Actions
Design the robot's behavior according to the following rules, considering the updated information:
The robot moves randomly in the room.
The robot selects the cell with the highest reward and traces a route to collect it
.
The robot searches for the nearest cell with a reward and traces a route to collect it
Add some graphs to visualize The answer
.
Parameters in
.
json:
{
"
money
"
:
1
,
"position":
[
0
,
4
]
,
"step
_
cost
"
:
1
,
"state":
[
[
5
,
0
,
0
,
3
,
0
,
2
,
0
,
0
,
1
]
]
}
ParameterViewer:
import json, numpy as np
from matplotlib import pyplot as plt
import seaborn as sns
# Reading information from files
f = open('params3.json')
parameters = json.load(f)
state, money, step_cost, position =[parameters[key] for key in ['state', 'money', 'step_cost', 'position']]
h, w = np.array(state).shape
plt.rcParams['figure.figsize']=[w//2, h//2]
print('money: {}'.format(money))
print('step cost: {}'.format(step_cost))
print('position: {}'.format(position))
ax = sns.heatmap(state, linewidth=0.5, linecolor='black', annot=True, cmap='RdBu', cbar=False, vmin=-7, vmax=7)
plt.xticks([])
plt.yticks([])
plt.show()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!