Added weighted choice function

This commit is contained in:
Marcin Kostrzewski 2020-05-16 10:44:01 +02:00
parent b61ffc008b
commit 74093de1d3

View File

@ -1,3 +1,8 @@
import random
from src.entities.Enums import Classifiers
class Affinities:
def __init__(self, food, water, rest):
"""
@ -9,3 +14,15 @@ class Affinities:
self.food = food
self.water = water
self.rest = rest
def getWeigths(self):
return [self.food, self.water, self.rest]
def pickWeightedAffinity(affinities: Affinities):
population = [Classifiers.FOOD, Classifiers.WATER, Classifiers.REST]
weights = affinities.getWeigths()
return random.choices(population, weights)