62 lines
2.5 KiB
Python
62 lines
2.5 KiB
Python
from modules.DB import UseDB
|
|
from loguru import logger
|
|
import configparser
|
|
import requests
|
|
|
|
|
|
def get_random_event():
|
|
response = requests.get("http://194.61.1.147:52540/get_random_event")
|
|
return response.json()
|
|
|
|
|
|
def recalculation_events(well):
|
|
config = configparser.ConfigParser()
|
|
config.read("conf/config.ini")
|
|
requests.get("http://194.61.1.147:52540/recalculation_events",
|
|
params={
|
|
"well": well,
|
|
"difficulty": config['Settings']['difficulty']
|
|
})
|
|
|
|
|
|
def start_calculating():
|
|
logger.debug("Валидация началась")
|
|
db = UseDB("events")
|
|
response = db.find_document({})
|
|
sum_percent_probability = sum([i["probability"] for i in response])
|
|
sum_percent_probability_in_events = sum([sum(i["probability_consequence"]) for i in response])
|
|
if sum_percent_probability != 100:
|
|
logger.critical("Сумма вероятностей всех ивентов не равна 100, это плохо, не надо так")
|
|
quit(0)
|
|
if sum_percent_probability_in_events != len(response) * 100:
|
|
logger.critical("Проблема в каком-то ивенте, сумма вероятностей не правильная")
|
|
quit(0)
|
|
for i in response:
|
|
if not (len(i["variants"]) == len(i["consequence"]) == len(i["probability_consequence"])):
|
|
logger.critical(f"Ошибка в ивенте {i['name']}. Разница в длинах variants, consequence "
|
|
f"и probability_consequence")
|
|
quit(0)
|
|
logger.debug("Валидация игры успешно прошла")
|
|
|
|
|
|
def field_generation():
|
|
difficulties = {
|
|
"Простая": [40, 30, 15, 10, 5],
|
|
"Средняя": [30, 30, 25, 10, 5],
|
|
"Сложная": [30, 40, 15, 10, 5],
|
|
"Проигрывать весело": [5, 50, 20, 10, 15]
|
|
}
|
|
config = configparser.ConfigParser()
|
|
config.read("conf/config.ini")
|
|
difficulty = config['Settings']['difficulty']
|
|
import random
|
|
board = []
|
|
for _ in range(8):
|
|
line = []
|
|
for _ in range(13):
|
|
# 0 - ничего, 1 - мина, любое другое число - указывает на количество получаемых мух
|
|
variant = random.choices(['0', '1', '2', '5', '10'], weights=difficulties[difficulty])
|
|
line.append(int(variant[0]))
|
|
board.append(line)
|
|
return board
|