forked from wholesomedonut/pystermind
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.
This commit is contained in:
parent
30f54f438f
commit
80e36e4aa5
|
@ -0,0 +1 @@
|
|||
__pycache__/
|
|
@ -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)
|
Loading…
Reference in New Issue