From 80e36e4aa58dc9f67a1fa23353a045ffb5ab8bb3 Mon Sep 17 00:00:00 2001 From: Pilot Date: Tue, 15 Sep 2020 14:39:17 -0400 Subject: [PATCH] Silly responses for failed attempts - This is over engineered, I was just trying out an idea - MessageTable implements a Random Distribution System - Changed the alignment of the output messages to lineup. --- .gitignore | 1 + witty_retort.py | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 .gitignore create mode 100644 witty_retort.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c18dd8d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__/ diff --git a/witty_retort.py b/witty_retort.py new file mode 100644 index 0000000..b1c7645 --- /dev/null +++ b/witty_retort.py @@ -0,0 +1,41 @@ +import random +import functools + +class MessageTable: + contents = [] + + def add_entry(self, string, probability): + entry = { + "remark": string, + "probability": probability, + "table": self + } + + self.contents.append(entry) + + def get_message(self): + probability_sum = functools.reduce( + lambda total, entry: + entry["probability"] + total, + self.contents, 0 + ); + + hit_value = random.randrange(probability_sum) + running_value = 0 + for i in self.contents: + running_value += i["probability"] + if hit_value < running_value: + return i + + + + + +remarks = MessageTable() +remarks.add_entry("Not quite", 30) +remarks.add_entry("Keep trying", 20) +remarks.add_entry("Intresting strategy", 15) +remarks.add_entry("Close", 10) +remarks.add_entry("Don't give up", 10) +remarks.add_entry("I though you had it", 10) +remarks.add_entry("You can do it!", 5)