# -*- coding: utf-8 -*- """ Created on Tue Oct 25 18:58:05 2022 @author: Roman """ import datetime as dt import random import itertools as it import math import time today = dt.datetime.now() players = [] def check_position(pos, players): for i, pl in enumerate(players): if pl.get('pos') == pos: return i return -1 def motion(pos, n): if n == 1: pos[0] -= 1 if n == 2: pos[0] += 1 if n == 3: pos[1] -= 1 if n == 4: pos[1] += 1 if pos[0] < 1: pos[0] = 1 if pos[0] > 10: pos[0] = 10 if pos[1] < 1: pos[1] = 1 if pos[1] > 10: pos[1] = 10 return pos def action(pl1, pl2, season, today): if pl1["type"] == pl2["type"]: pl1['power'] += 1 pl2['power'] += 1 else: result_power1 = (pl1['power'] + math.pi * ((today - pl1['date']).days // 365)) result_power1 = math.ceil(1.5 * result_power1) if pl1['type'] == season else math.ceil(result_power1) result_power2 = (pl2['power'] + math.pi * ((today - pl2['date']).days // 365)) result_power2 = math.ceil(1.5 * result_power2) if pl2['type'] == season else math.ceil(result_power2) if result_power1 > result_power2: pl2['type'] = pl1['type'] elif result_power1 < result_power2: pl1['type'] = pl2['type'] return [pl1, pl2] def print_players(players): print(25 * "=") for i in range(10): for j in range(10): k = check_position([i + 1, j + 1], players) char = 0 if k == -1 else players[k]["type"] + 1 print(char, end='') print() print(25 * "=") for i in range(4): for j in range(10): players.append( { "type": i, "power": random.randint(1, 100), "date": today - dt.timedelta( days=365 * random.randint(1, 50) + random.randint(0, 365) ), "pos": [0, 0] } ) for pl in players: pos = [random.randint(1, 10), random.randint(1, 10)] while check_position(pos, players) != -1: pos = [random.randint(1, 10), random.randint(1, 10)] pl['pos'] = pos k = 0 for season in it.cycle([0, 1, 2, 3]): k += 1 print_players(players) time.sleep(1) random.shuffle(players) for i, pl in enumerate(players): n = random.randint(1, 4) new_pos = pl['pos'].copy() new_pos = motion(new_pos, n) j = check_position(new_pos, players) if j != -1 and j != i: pl, players[j] = action(pl, players[j], season, today) else: pl['pos'] = new_pos if k == 100: break print_players(players) result = { 0: 0, 1: 0, 2: 0, 3: 0 } for pl in players: result[pl['type']] += 1 print(result)