def _choose_vacant_home_or_vacant_lot(self):
"""Choose a vacant home to move into or a vacant lot to build on.
Currently, a person scores all the vacant homes/lots in town and then selects
one of the top three. TODO: Probabilistically select from all homes/lots using the
scores to derive likelihoods of selecting each.
"""
home_and_lot_scores = self._rate_all_vacant_homes_and_vacant_lots()
if len(home_and_lot_scores) >= 3:
# Pick from top three
top_three_choices = heapq.nlargest(3, home_and_lot_scores, key=home_and_lot_scores.get)
if random.random() < 0.6:
choice = top_three_choices[0]
elif random.random() < 0.9:
choice = top_three_choices[1]
else:
choice = top_three_choices[2]
elif home_and_lot_scores:
choice = list(home_and_lot_scores)[0]
else:
choice = None
return choice
评论列表
文章目录