When Python reacts
So, the issues are:
The second to last:
agents[1][1] -= 1
should be:
agents[1][1] += 1
if random.random() < 0.6:
should be:
if random.random() < 0.5:
Perhaps even harder:
if random.random() > 0.5:
should be:
if random.random() < 0.5:
This is especially tricky as it currently makes almost no difference to the code at all – > 0.5
has almost the same
probablity as < 0.5
(remembering that random()
generates a number between zero and just less than one). But it is the kind of thing that
eventually will come back to bite us – if we change the probability value, for example. It needs spotting.
Close reading for logical issues is undoubtedly the hardest part of debugging: just looking for these issues is very hard. Over the next few debugging practices we'll look at some help for doing this.