so we're going to go back to the AL for
all bar problem we're going to ask
ourselves what does it mean to be
successful in the world of the AL for
all bar problem right what is success in
this case and can we then identify uh
individual agents that are being
successful right so the original model
illustrates how many agents make as a
bar U and whether or not the bar is
crowded but what if we want to know
which of those agents are doing better
right then we want to identify
successful agents all right um and so we
have to think a little bit about that
well what does it mean to be successful
in this context it means that I've
attended the bar when it was not full
when it was not overcrowded right um I
don't get success for not attending the
bar right that's I don't really care
about not attending I only get reward if
I attended uh when it was overcrowded at
least in this particular context is the
the way we're going to find it so when I
want to think about how to extend a
model like this in order to try and
identify this i' like to write down uh
kind of a few notes as to what I'm going
to need to do that right um and so one
of the things that I might write down is
that well you know I need to keep track
at an individual level of the turtle
success and so I'm going to add
something I call reward right which is
that you know the the basic idea behind
reward is that the agents will get
reward rewarded if they attend the bar
when it's not full right so to do that
I'm going to modify the turtle Zone part
of the code to add a reward I'm thinking
to make sure that I set that reward to
zero initially right so they have no
rewards then I'm need to make sure that
the turtles get rewarded for going to
the bar when it's not crowded um and
finally you know I want to do some sort
of visual indication so it makes a
little easier for me to identify the the
the best Turtles uh the best agents so
I'm going to change the turtle's color
based on the reward in order to do that
and so that's what we're about to do so
as I mentioned there's four things I
want to achieve in modifying this code I
want to modify the turtle own to add the
reward I want to initialize the reward I
want to make sure it gets updated
properly and then I want to color uh the
turtles the agents on the basis of that
reward right so let's go over to the
code tab um and let me blow this up a
little
bit and so here's the turtles own all
right and so we can quickly go in there
and we can add in our
reward um and as you can see this is a
fairly well documented model so we can
add in uh description so this is um keep
track of
when agents go to the bar
and it is not
crowded okay so that's the first thing
we need to do got that done we now have
that property uh we can always you know
it's always helpful to debug as you do
each little thing so we can hit setup uh
we can actually type inspect one of
turtles down
here and we can pull over and sure
enough see if it has a reward and it
does and it's zero uh but we want to
make sure of that so we can go into
the setup procedure and kind of you know
since we're just extending this model
we're not really caring too much about
understanding what every single part of
it says uh but instead we're going to go
down to wherever we see so here it is
create
Turtles right and we can just go in
there and we can say set reward to zero
so reset the O the
reward uh to the starting
condition
uh and of course you know can always go
back and check that one as well hit
inspect one of
turtles sure enough we have a reward of
zero right okay so now the third thing
we need to do is make sure that the
reward gets updated appropriately when
the turtle attends the bar and it is not
crowded so we need to look down a little
further to see when does that happen
well right here we can see that we're
deciding whether or not we should attend
right so ask the turtles if they should
attend but at that point we don't know
if the bar is crowded or not however if
you look down here you can see if the
attendance is greater than the
overcrowding threshold then I'm going to
print crowded right so there but there's
no check that says if it's not greater
right if it is if if it's at the level
where it's okay so what we can do is we
can take this if statement and we can
modify it to an if else
right and this is going to give this the
power to add a to do something if the if
the bar is not crowded right and what do
we want to do if the bar is not crowded
well all the turtles that attended the
bar have this attend Boolean set to true
and you could kind of tell that by
looking through the code you don't even
have to look in detail right so you can
see the as Turtle set prediction set
aend um as to whether or not their
prediction is less than the threshold um
so they'll only attend if it's less than
it um so we know here that we're in the
condition where the bar is not crowded
so now we have to find the set of all
turtles that have attended the bar well
that's pretty simple actually that's
just ask Turtles with attend because we
know that if they
attended then we move them into one of
the bars spaces right and we increase
the attendance and so we can ask them to
do something well what do we want them
to do we want them to set their reward
to reward + one right and so this will
allow us to um identify first of all the
cases where the bar is not crowded
because the attendance is less than or
equal to the threshold and find all the
turtles who actually attended and in
increment their reward so again as
always it's important let's double check
this and make sure we did it correctly
so we can hit setup um we can hit go and
we can now see except so we're now in a
state where the bar is not crowded and
so the reward if we did this properly
for all of these Turtles should be one
right so we can inspect one of these
turtles that is attending and we go down
sure enough reward of one because we
only went one time step right right um
and let's say you want to do it the
debug a little bit more you want to like
really make sure um that you are working
correctly you could just say print print
reward of turtles with
attend right so this is just going to
first of all find all the turtles with
aend being true and then it's going to
print the reward of and just in case if
you're worried about order of operations
you can always put brackets so this is
saying this is definitely find the
turtles with a 10 and then print their
reward and if we did this correctly
right this should print a whole string
of ones because every turtle that
attended we now know was in a case where
it was not crowded and this is the first
time step and so therefore it should all
be once sure enough if we scroll around
we see that it's all ones right so we're
pretty confident our codee's working
correctly might want to run it a while
just to make sure and we can always um
look at like a particular Turtle find
out what the reward was before and then
find out cases where they moved in right
um into the bar and then see if the
reward incremented right so that would
be further debug checks that we could do
um so that's it for this getting reward
up and running in the next uh video
we're going to talk about um colors and
visualization of those Rewards