добавил перезапись сложности в config.ini

добавил зависимости вероятностей от сложности
немного английской грамматики добавил
This commit is contained in:
2022-12-24 22:21:08 +07:00
parent fbb32c50d9
commit f09ad6613a
6 changed files with 35 additions and 17 deletions
+5
View File
@@ -1,5 +1,6 @@
import pygame
from modules.Board import Board
from modules.Mathematics import recalculation_events, get_random_event
class Game:
@@ -24,6 +25,10 @@ class Game:
self.running = False
if event.type == pygame.MOUSEBUTTONDOWN:
self.board.get_click(event.pos)
if event.type == pygame.MOUSEWHEEL:
event = get_random_event()
recalculation_events(event["well"])
print(event)
def render(self):
self.screen.fill((0, 0, 0))
+7 -1
View File
@@ -1,5 +1,6 @@
import pygame
import pygame_menu
import configparser
def set_difficulty(value, _):
@@ -8,10 +9,15 @@ def set_difficulty(value, _):
def start_the_game():
config = configparser.ConfigParser()
config.read('conf/config.ini')
config['Settings']['difficulty'] = difficulty
with open('conf/config.ini', 'w') as configfile:
config.write(configfile)
menu.toggle()
difficulty = ""
difficulty = "Простая"
pygame.init()
surface = pygame.display.set_mode((600, 400))
mytheme = pygame_menu.themes.THEME_DARK.copy()
+18 -10
View File
@@ -1,6 +1,7 @@
from modules.DB import UseDB
from loguru import logger
import random
import configparser
def get_random_event():
@@ -11,30 +12,37 @@ def get_random_event():
def recalculation_events(well):
difficulties = {
"Простая": [5, 5],
"Средняя": [5, 2],
"Сложная": [5, 1],
"Проигрывать весело": [10, 1]
}
config = configparser.ConfigParser()
config.read("conf/config.ini")
difficulty = config['Settings']['difficulty']
if well:
db = UseDB("events")
not_well_events = db.find_document({"well": False})
for i in not_well_events:
db.update_document({"_id": i["_id"]}, {"probability": i["probability"] + 5})
db.update_document({"_id": i["_id"]}, {"probability": i["probability"] + difficulties[difficulty][0]})
well_events = db.find_document({"well": True})
cooficent = len(not_well_events) * 5 / len(well_events)
ratio = len(not_well_events) * difficulties[difficulty][0] / len(well_events)
for i in well_events:
db.update_document({"_id": i["_id"]}, {"probability": i["probability"] - cooficent})
db.update_document({"_id": i["_id"]}, {"probability": i["probability"] - ratio})
else:
db = UseDB("events")
well_events = db.find_document({"well": True})
for i in well_events:
db.update_document({"_id": i["_id"]}, {"probability": i["probability"] + 5})
db.update_document({"_id": i["_id"]}, {"probability": i["probability"] + difficulties[difficulty][1]})
not_well_events = db.find_document({"well": False})
cooficent = len(well_events) * 5 / len(not_well_events)
ratio = len(well_events) * difficulties[difficulty][1] / len(not_well_events)
for i in not_well_events:
db.update_document({"_id": i["_id"]}, {"probability": i["probability"] - cooficent})
db.update_document({"_id": i["_id"]}, {"probability": i["probability"] - ratio})
def start_calculating():
logger.remove()
logger.add("conf/log.log", level="INFO")
logger.info("Валидация началась")
logger.debug("Валидация началась")
db = UseDB("events")
response = db.find_document({})
sum_percent_probability = sum([i["probability"] for i in response])
@@ -50,4 +58,4 @@ def start_calculating():
logger.critical(f"Ошибка в ивенте {i['name']}. Разница в длинах variants, consequence "
f"и probability_consequence")
quit(0)
logger.info("Валидация игры успешно прошла")
logger.debug("Валидация игры успешно прошла")