добавил debug_functions.py, пока только добавление ивентов и то не полностью
This commit is contained in:
@@ -0,0 +1,39 @@
|
|||||||
|
def add_new_event():
|
||||||
|
name = input("Введите название ивента\n")
|
||||||
|
description = input("Введите описание ивента\n")
|
||||||
|
try:
|
||||||
|
well = bool(input("Этот ивент хороший?\n"))
|
||||||
|
except Exception as e:
|
||||||
|
return e
|
||||||
|
variants = input("Введите варианты развития ивентов, разделённые */!/*\n").split("*/!/*")
|
||||||
|
consequence = input("Введите функции которые выполнятся при варианте ивента, "
|
||||||
|
"разделённые */!/*\n").split("*/!/*")
|
||||||
|
probability_consequence = [int(i) for i in input("Введите вероятности вариантов ивентов,"
|
||||||
|
" разделённые */!/*\n").split("*/!/*")]
|
||||||
|
if len(variants) == len(consequence) == len(probability_consequence):
|
||||||
|
response = {
|
||||||
|
"name": name,
|
||||||
|
"description": description,
|
||||||
|
"variants": variants,
|
||||||
|
"consequence": consequence,
|
||||||
|
"probability_consequence": probability_consequence,
|
||||||
|
"probability": 0,
|
||||||
|
"well": well
|
||||||
|
}
|
||||||
|
return response
|
||||||
|
else:
|
||||||
|
return "Длины variants, consequence и probability_consequence не равны"
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
while True:
|
||||||
|
answer = input("Что сегодня сделаем?\n")
|
||||||
|
if answer == "добавить эвент":
|
||||||
|
print(add_new_event())
|
||||||
|
else:
|
||||||
|
print("Ничего не понятно")
|
||||||
|
quit(0)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
@@ -7,7 +7,8 @@ import configparser
|
|||||||
def get_random_event():
|
def get_random_event():
|
||||||
db = UseDB("events")
|
db = UseDB("events")
|
||||||
response = db.find_document({})
|
response = db.find_document({})
|
||||||
random_event = random.choices([i["_id"] for i in response], weights=[i["probability"] for i in response])
|
random_event = random.choices([i["_id"] for i in response],
|
||||||
|
weights=[i["probability"] for i in response])
|
||||||
return db.find_document({"_id": random_event[0]})[0]
|
return db.find_document({"_id": random_event[0]})[0]
|
||||||
|
|
||||||
|
|
||||||
@@ -21,21 +22,20 @@ def recalculation_events(well):
|
|||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read("conf/config.ini")
|
config.read("conf/config.ini")
|
||||||
difficulty = config['Settings']['difficulty']
|
difficulty = config['Settings']['difficulty']
|
||||||
|
db = UseDB("events")
|
||||||
|
not_well_events = db.find_document({"well": False})
|
||||||
|
well_events = db.find_document({"well": True})
|
||||||
if well:
|
if well:
|
||||||
db = UseDB("events")
|
|
||||||
not_well_events = db.find_document({"well": False})
|
|
||||||
for i in not_well_events:
|
for i in not_well_events:
|
||||||
db.update_document({"_id": i["_id"]}, {"probability": i["probability"] + difficulties[difficulty][0]})
|
db.update_document({"_id": i["_id"]},
|
||||||
well_events = db.find_document({"well": True})
|
{"probability": i["probability"] + difficulties[difficulty][0]})
|
||||||
ratio = len(not_well_events) * difficulties[difficulty][0] / len(well_events)
|
ratio = len(not_well_events) * difficulties[difficulty][0] / len(well_events)
|
||||||
for i in well_events:
|
for i in well_events:
|
||||||
db.update_document({"_id": i["_id"]}, {"probability": i["probability"] - ratio})
|
db.update_document({"_id": i["_id"]}, {"probability": i["probability"] - ratio})
|
||||||
else:
|
else:
|
||||||
db = UseDB("events")
|
|
||||||
well_events = db.find_document({"well": True})
|
|
||||||
for i in well_events:
|
for i in well_events:
|
||||||
db.update_document({"_id": i["_id"]}, {"probability": i["probability"] + difficulties[difficulty][1]})
|
db.update_document({"_id": i["_id"]},
|
||||||
not_well_events = db.find_document({"well": False})
|
{"probability": i["probability"] + difficulties[difficulty][1]})
|
||||||
ratio = len(well_events) * difficulties[difficulty][1] / len(not_well_events)
|
ratio = len(well_events) * difficulties[difficulty][1] / len(not_well_events)
|
||||||
for i in not_well_events:
|
for i in not_well_events:
|
||||||
db.update_document({"_id": i["_id"]}, {"probability": i["probability"] - ratio})
|
db.update_document({"_id": i["_id"]}, {"probability": i["probability"] - ratio})
|
||||||
|
|||||||
Reference in New Issue
Block a user