Added weighted choice function
This commit is contained in:
parent
b61ffc008b
commit
74093de1d3
@ -1,3 +1,8 @@
|
|||||||
|
import random
|
||||||
|
|
||||||
|
from src.entities.Enums import Classifiers
|
||||||
|
|
||||||
|
|
||||||
class Affinities:
|
class Affinities:
|
||||||
def __init__(self, food, water, rest):
|
def __init__(self, food, water, rest):
|
||||||
"""
|
"""
|
||||||
@ -9,3 +14,15 @@ class Affinities:
|
|||||||
self.food = food
|
self.food = food
|
||||||
self.water = water
|
self.water = water
|
||||||
self.rest = rest
|
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)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user