From 74093de1d3ad094d52deb52f87e9e3678efa2d7a Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Sat, 16 May 2020 10:44:01 +0200 Subject: [PATCH] Added weighted choice function --- src/AI/Affinities.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/AI/Affinities.py b/src/AI/Affinities.py index d2e1ac6..b35d505 100644 --- a/src/AI/Affinities.py +++ b/src/AI/Affinities.py @@ -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) +