from typing import List, Tuple, Optional, Union

from game_objects import *
from traffic_light import *
from utils import *


class Layout:
    @staticmethod
    def load_intersection_layout(game):
        light_dict = {}

        def add_light(index, crossing, position, clearing_time=4.0, sync = True):
            light_dict[index] = TrafficLight(index, crossing, clearing_time, "red", position, game, sync = sync)

        # add_light(1, [30, 31, 35], (530, 520), 4)
        add_light(2, [25, 30, 31, 35], (500, 620), 4)
        add_light(3, [21, 22, 23, 24], (500, 720), 4)
        add_light(4, [21, 22, 23, 24], (500, 935), 4)
        add_light(5, [25, 30, 31, 35], (500, 505), 4)
        add_light(6, [24, 34 , 29], (785, 1095), 4)
        add_light(7, [24, 29, 34], (925, 1095), 4)
        # add_light(8, [25, 26, 27], (1040, 1095), 4)
        add_light(9, [25, 26, 27], (1085, 1095), 4)
        add_light(10, [24, 29,  34], (660, 1095), 4)
        # add_light(11, [22, 23, 27, 33], (1225, 925), 10)
        add_light(12, [22, 23, 26, 27, 33], (1242, 820), 3)
        add_light(13, [29, 30, 31, 32], (1242, 723), 4)
        add_light(14, [29, 30, 31, 32], (1242, 505), 4)
        add_light(15, [22, 26, 23, 27, 33], (1242, 925), 10)
        add_light(16, [21, 25, 32], (1085, 358), 4)
        add_light(17, [21, 25, 32], (970, 358), 4)
        add_light(18, [33, 34, 35], (819, 358), 4)
        add_light(19, [33, 34, 35], (660, 358), 4)
        # add_light(20, [21, 25, 32], (1081, 365), 4)
        add_light(21, [3, 4, 16, 17, 25, 29, 30, 31, 32, 33, 34], (440, 755), 4)
        add_light(22, [3, 4, 12, 15, 25, 26, 27, 33, 34], (440, 808), 4)
        add_light(23, [3, 4, 12, 15, 25, 26, 27, 33, 34], (440, 860), 4)
        add_light(24, [3, 4, 6, 7, 10, 28, 34], (440, 913), 4)
        add_light(25, [2, 5, 9, 16, 17,  21, 22, 23, 29, 30, 31, 32, 33, 34, 35], (959, 1230), 4)
        add_light(26, [9, 12, 15, 22, 23, 33], (1011, 1230), 4)
        add_light(27, [9,  12, 15, 22, 23, 33], (1064, 1230), 4)
        add_light(28, [24, 34], (1125,  1224), 4)  # bus line
        add_light(29, [6, 7, 10, 13, 14, 21, 25, 33, 34], (1300, 705), 4)
        add_light(30, [2, 5,  13, 14, 21, 25, 33, 34, 35], (1300, 653), 4)
        add_light(31, [2, 5, 13, 14, 21, 25, 33, 34, 35], (1300, 600), 4)
        add_light(32, [13, 14, 16, 17, 21, 25], (1300, 548), 4)
        add_light(33, [12, 15, 18, 19, 21, 22, 23, 25, 26, 27, 29, 30, 31], (791, 275 ), 4)
        add_light(34, [6, 7, 10, 18, 19, 21, 22, 23, 24, 28, 29, 25, 30, 31], (750, 275), 4)
        add_light(35, [2, 5, 18, 19,  25, 30, 31], (694, 275), 4)
        add_light(36, [39], (2396, 966), 4)  # bridge
        add_light(37, [38], (2650, 1179), 11, sync = False)
        add_light(38, [37], (2650, 251), 11, sync = False)
        add_light(39, [36, 40, 41, 42], (2290, 775), 10)
        add_light(40, [39], (2768, 590), 10)
        add_light(41, [39], (2768, 1077), 10)
        add_light(42, [39], (2768, 344), 10)

        return light_dict


    @staticmethod
    def loads_roads(game):
        VC  = Sensor.SensorType.VEHICLES_COMING
        VW  = Sensor.SensorType.VEHICLES_WAITING
        VB  = Sensor.SensorType.BLOCKING
        BUS = Sensor.SensorType.PUBLIC_TRANSPORT

        roads = dict()
        road_conns = dict()


        def add_road(
                index: int,
                start: Tuple[int, int],
                end: Tuple[int, int],
                light_id: Optional[int],
                connection_ids: List[int],
                sensors: Union[
                    List[Tuple[Box, Sensor.SensorType]],            # Area + Type
                    List[Tuple[Box, Sensor.SensorType, List[int]]]  # Area + Type + Target Light
                ]
        ):
            light = game.state[light_id] if light_id is not None else None

            roads[index] = Road(index, game, start, end, [], light)
            road_conns[index] = connection_ids

            for sensor_data in sensors:
                roads[index].add_sensor(*sensor_data)


        add_road(1, (2883, 465), (2883, 1007), None, [], [])
        add_road(2, (4023, 646), (3478, 646), None, [55], [])
        add_road(3, (3685, 490), (3685, 1040), None, [], [])
        add_road(4, (3744, 490), (3744, 1040), None, [], [])
        add_road(5, (3018, 1209), (3448, 1209), None, [], [])
        add_road(6, (3018, 1260), (3448, 1260), None, [], [])
        add_road(7, (3367, 1571), (3367, 1010), None, [], [])
        add_road(8, (79, 906), (690, 906), 24, [35, 36], [
            (Box((100, 895), (130, 925)), VC),
            (Box((375, 895), (405 , 925)), VW)
        ])
        add_road(9, (79, 856), (1005, 856), 23, [40], [
            (Box((100, 840), (130, 870)), VC),
            (Box((375, 840), (405, 870)), VW)
        ])
        add_road(10, (79, 800), (1005, 800), 22, [41], [
            (Box((100, 788), (130, 818)), VC),
            (Box((375, 788), (405, 818)), VW)
        ])
        add_road(11, (1056, 1487), (1056, 906), 27, [52], [
            (Box((1043, 1260), (1073, 1290)), VW),
            (Box((1043, 1451), (1073, 1481)), VC)
        ])
        add_road(12, (1005, 1487), (1005, 856), 26, [53], [
            (Box((991, 1260), (1021, 1290)), VW),
            (Box((991, 1451), (1021, 1481)), VC)
        ])
        add_road(13, (950, 1485), (950, 540), 25, [54], [
            (Box((940, 1260), (970, 1290)), VW),
            (Box((936, 1451), (966, 1481)), VC)
        ])
        add_road(14, (1110, 1487), (1110, 1200), 28, [79], [
            (Box((1095, 1250), (1125, 1280)), VC),
            (Box((1095, 1421), (1125, 1451)), BUS),
            (Box((1095, 1421), (1125, 1451)), VW),
        ])  # bus line
        add_road(15, (688, 100), (688, 540), 35, [43, 50], [
            (Box((670, 130), (700, 160)), VC),
            (Box((670, 220), (700, 250)), VW)
        ])
        add_road(16, (740, 100), (740, 856), 34, [44, 46], [
            (Box((726, 130), (756, 160)), VC),
            (Box((726, 220), (756, 250)), VW)
        ])
        add_road(17, (792, 100), (792, 856), 33, [48, 47], [
            (Box((778, 130), (808, 160)), VC),
            (Box((778, 220), (808, 250)), VW)
        ])
        add_road(18, (2826, 1062), (1552, 1062), 41, [], [
            (Box((2806, 1050), (2836, 1080)), VW)
        ])
        add_road(19, (2826, 1115), (1552, 1115), 41, [], [
            (Box((2806, 1100), (2836, 1130)), VW)
        ])
        add_road(20, (2826, 380), (1552, 380), 42, [], [
            (Box((2806, 365), (2836, 395)), VW)
        ])
        add_road(21, (2826, 328), (1552, 328), 42, [], [
            (Box((2806, 316), (2836, 346)), VW)
        ])
        add_road(22, (1268, 435), (1268, 720), 14, [77], [
            (Box((1255, 450), (1285, 480)), VW)
        ])
        add_road(23, (1211, 435), (1211, 720), 14, [86], [
            (Box((1200, 450), (1230, 480)), VW)
        ])
        add_road(24, (1150, 328), (950, 328), 16, [102], [
            (Box((1110, 316), (1140, 346)), VW)
        ])
        add_road(25, (1150, 380), (950, 380), 16, [103], [
            (Box((1110, 368), (1140, 398)), VW)
        ])
        add_road(26, (478, 461), (478, 620), 5, [96], [
            (Box((460, 464), (490, 494)), VW)
        ])
        add_road(27, (531, 461), (531,  620), 5, [97], [
            (Box((517, 464), (547, 494)), VW)
        ])
        add_road(28, (590, 1062), (840, 1062), 10, [89], [
            (Box((595, 1050), (625, 1080)), VW)
        ])
        add_road(29, (590, 1115), (840, 1115), 10, [90], [
            (Box((595, 1100), (625, 1130)), VW)
        ])
        add_road(30, (79, 749), (648, 749), 21, [31], [
            (Box((100, 735), (130, 765)), VC),
            (Box((375, 735), (405, 765)), VW)
        ])
        add_road(31, (648, 749), (1002, 749), None, [32, 34], [])
        add_road(32, (1002, 749), (1056, 749), None, [33], [])
        add_road(33, (1056, 749), (1056, 100), None, [], [])
        add_road(34, (1002, 749), (1002, 100), None, [], [])
        add_road(35, (690, 906), (690, 1342), None, [], [])
        add_road(36, (690, 906), (740, 906), None, [37], [])
        add_road(37, (740, 906), (740, 1342), None, [], [])
        add_road(38, (2670, 1366), (2670, 107), 37, [], [
            (Box((2650, 1200), (2680, 1230)), VW, [39])
        ])
        add_road(39, (2550, 107), (2550, 1366), 38, [], [
            (Box((2540, 215), (2570, 245)), VW, [39])
        ])
        add_road(40, (1005, 856), (1090, 906), None, [42], [])
        add_road(41, (1005, 800), (1055, 856), None, [81], [])
        add_road(42, (1090, 906), (2070, 906), None, [83], [
            (Box((1400, 894), (1430, 924)), VB, [22, 23, 26, 27, 33]),
        ])
        add_road(43, (688, 540), (79, 540), None, [], [])
        add_road(44, (740, 856), (690, 856), None, [45], [])
        add_road(45, (690, 856), (690, 1342), None, [], [])
        add_road(46, (740, 856), (740, 1342), None, [], [])
        add_road(47, (792, 856), (1090, 856), None, [], [])
        add_road(48, (792, 853), (792, 906), None, [49], [])
        add_road(49, (792, 906), (1090, 906), None, [42], [])
        add_road(50, (688, 540), (688, 591), None, [51], [])
        add_road(51, (688, 591), (79, 591), None, [], [])
        add_road(52, (1056, 906), (1090, 906), None, [42], [])
        add_road(53, (1005, 856), (1055, 856), None, [81], [])
        # add_road(54, (688, 906), (79000, 591), None, [], [])
        add_road(54, (950, 540), (688, 540), None, [43], [])
        # roundabout
        add_road(55, (3478, 646), (3364, 554), None, [56], [])
        add_road(56, (3364, 554), (3115, 554), None, [57], [])
        add_road(57, (3115, 554), (3022, 648), None, [58, 65], [])
        add_road(58, (3022, 648), (3022, 906), None, [59], [])
        add_road(59, (3022, 906), (3115, 1010), None, [60, 63], [])
        add_road(60, (3115, 1010), (3367, 1010), None, [61], [])
        add_road(61, (3367, 1010), (3478, 906), None, [62, 64], [])
        add_road(62, (3478, 906), (3478, 646), None, [55], [])
        add_road(63, (3115, 1010), (3115, 1570), None, [], [])
        add_road(64, (3478, 906), (4018, 906), None, [], [])
        # purple road
        add_road(65, (3022, 648), (2060, 648), 40, [66, 67, 73], [
            (Box((2816, 633), (2846, 663)), VW)
        ])
        add_road(66, (2060, 648), (2060, 588), None, [68, 71], [])
        add_road(67, (2060, 648), (2060, 700), None, [75], [])
        add_road(68, (2060, 588), (2060, 537), None, [69], [])
        add_road(69, (2060, 537), (1056, 537), 32, [70], [
            (Box((1345, 526), (1375,  556)), VC),
            (Box((1970, 526), (2000, 556)), VW)
        ])
        add_road(70, (1056, 537), (1056, 70), None, [], [])
        add_road(71, (2060, 588), (720, 588), 31, [72], [
            (Box((1345, 578), (1375, 608)), VC),
            (Box((1970, 578), (2000, 608)), VW)
        ])
        add_road(72, (720, 588), (688, 540), None, [43], [])
        add_road(73, (2060, 648), (720, 648), 30, [74], [
            (Box((1345, 630), (1375, 660)), VC),
            (Box((1970, 630), (2000, 660)), VW)
        ])
        add_road(74, (720, 648), (688, 591), 29, [51], [
            (Box((1345, 680), (1375, 710)), VC),
            (Box((1970, 680), (2000, 710)), VW)
        ])
        add_road(75, (2060, 700), (690, 700), None, [76], [])
        add_road(76, (690, 700), (690, 906), None, [35], [])
        add_road(77, (1268, 720), (1268, 985), 12, [], [
            (Box((1255, 755), (1285, 785)), VW)
        ])
        add_road(79, (1110, 1200), (740, 1200), None, [80], [])
        add_road(80, (740, 1200), (740, 1345), None, [], [])
        add_road(81, (1055, 856), (2040, 856), None, [82], [
            (Box((1400, 840), (1430, 870)), VB, [22, 23, 26, 27,33]),
        ])
        add_road(82, (2040, 856), (2070, 906), None, [83], [])
        add_road(83, (2070, 906), (3022, 906), 36, [59], [
            (Box((2340, 894), (2370, 924)), VW)
        ])
        add_road(84, (1268, 985), (1268, 840), 15, [85], [
            (Box((1255, 950), (1285, 980)), VW)
        ])
        add_road(85, (1268, 840), (1268, 461), 13, [], [
            (Box((1255, 750), (1285, 780)), VW)
        ])
        add_road(86, (1211, 720), (1211, 985), 12, [], [
            (Box((1200, 755), (1230, 785)), VW)
        ])
        add_road(87, (1211, 985), (1211, 800), 15, [88], [
            (Box((1200, 950), (1230, 980)), VW)
        ])
        add_road(88, (1211, 800), (1211, 461), 13, [], [
            (Box((1200, 750), (1230, 780)), VW)
        ])
        add_road(89, (840, 1062), (1135, 1062), 7, [], [
            (Box((870, 1050), (900, 1080)), VW)
        ])
        add_road(90, (840, 1115), (1134, 1115), 7, [], [
            (Box((870, 1100), (900, 1130)), VW)
        ])
        add_road(91, (1140, 1062), (1000, 1062), 9, [94], [
            (Box((1110, 1050), (1140, 1080)), VW)
        ])
        add_road(92, (1140, 1115), (1000, 1115), 9, [95], [
            (Box((1110, 1100), (1140, 1130)), VW)
        ])
        add_road(94, (1000, 1062), (610, 1062), 6, [], [
            (Box((810, 1050), (840, 1080)), VW)
        ])
        add_road(95, (1000, 1115), (610, 1115), 6, [], [
            (Box((810, 1100), (840, 1130)), VW)
        ])
        add_road(96, (478, 620), (478, 985), 3, [], [
            (Box((460, 660), (490, 690)), VW)
        ])
        add_road(97, (531, 620), (531, 985), 3, [], [
            (Box((517, 660), (547, 690)), VW)
        ])
        add_road(98, (478, 985), (478, 700), 4, [100], [
            (Box((460, 950), (490, 980)), VW)
        ])
        add_road(99, (531, 985), (531, 700), 4, [101], [
            (Box((517, 950), (547, 980)), VW)
        ])
        add_road(100, (478, 700), (478, 461), 2, [], [
            (Box((460, 645), (490, 675)), VW)
        ])
        add_road(101, (531, 700), (531, 461), 2, [], [
            (Box((517, 645), (547, 675)), VW)
        ])
        add_road(102, (950, 328), (610, 328), 18, [], [
            (Box((850, 316), (880, 346)), VW)
        ])
        add_road(103, (950, 380), (610, 380), 18, [], [
            (Box((850, 368), (880, 398)), VW)
        ])
        add_road(104, (595, 328), (820, 328), 19, [106], [
            (Box((600, 316), (630, 346)), VW)
        ])
        add_road(105, (595, 380), (820, 380), 19, [107], [
            (Box((600, 368), (630, 398)), VW)
        ])
        add_road(106, (820, 328), (1134, 328), 17, [], [
            (Box((910, 316), (940, 346)), VW)
        ])
        add_road(107, (820, 380), (1134, 380), 17, [], [
            (Box((910, 368), (940, 398)), VW)
        ])


        for i, connections_for_road in road_conns.items():
            roads[i].connections = [roads[j] for j in connections_for_road]

        return roads


    @staticmethod
    def load_spawnpoints(game):
        spawnpoints = [
            ('bike', 1),
            ('car', 2),
            ('bike', 3),
            ('man', 4),
            ('bike', 5),
            ('man', 6),
            ('car', 7),
            ('car', 8),
            ('car', 9),
            ('car', 10),
            ('car', 11),
            ('car', 12),
            ('car', 13),
            ('bus', 14),  # bus
            ('car', 15),
            ('car', 16),
            ('car', 17),
            ('bike', 18),
            ('man', 19),
            ('bike', 20),
            ('man', 21),
            ('man', 22),
            ('bike', 23),
            ('man', 24),
            ('bike', 25),
            ('man', 26),
            ('bike', 27),
            ('bike', 28),
            ('man', 29),
            ('car', 30),
            ('boat', 38),
            ('boat', 39),
            ('man', 84),
            ('bike', 87),
            ('bike', 91) ,
            ('man', 92),
            ('bike', 98),
            ('man', 99),
            ('man', 104),
            ('bike', 105),
        ]

        result = []
        for type, road_idx in spawnpoints:
            if type in ['man', 'bike']:
                speed    = 15
                cooldown = 40
            elif type in ['car', 'boat']:
                speed    = 65
                cooldown = 40
            elif type in ['bus']:
                speed    = 40
                cooldown = 400
            else:
                raise NotImplementedError()

            result.append(SpawnPoint(game, type, game.roads[road_idx], speed = speed, cooldown = cooldown))

        return result
9f5e7ae057026bada366f1900dbfa49e3c315c01
<mask token>


class Layout:
    <mask token>
    <mask token>
    <mask token>

<mask token>


class Layout:

    @staticmethod
    def load_intersection_layout(game):
        light_dict = {}

        def add_light(index, crossing, position, clearing_time=4.0, sync=True):
            light_dict[index] = TrafficLight(index, crossing, clearing_time,
                'red', position, game, sync=sync)
        add_light(2, [25, 30, 31, 35], (500, 620), 4)
        add_light(3, [21, 22, 23, 24], (500, 720), 4)
        add_light(4, [21, 22, 23, 24], (500, 935), 4)
        add_light(5, [25, 30, 31, 35], (500, 505), 4)
        add_light(6, [24, 34, 29], (785, 1095), 4)
        add_light(7, [24, 29, 34], (925, 1095), 4)
        add_light(9, [25, 26, 27], (1085, 1095), 4)
        add_light(10, [24, 29, 34], (660, 1095), 4)
        add_light(12, [22, 23, 26, 27, 33], (1242, 820), 3)
        add_light(13, [29, 30, 31, 32], (1242, 723), 4)
        add_light(14, [29, 30, 31, 32], (1242, 505), 4)
        add_light(15, [22, 26, 23, 27, 33], (1242, 925), 10)
        add_light(16, [21, 25, 32], (1085, 358), 4)
        add_light(17, [21, 25, 32], (970, 358), 4)
        add_light(18, [33, 34, 35], (819, 358), 4)
        add_light(19, [33, 34, 35], (660, 358), 4)
        add_light(21, [3, 4, 16, 17, 25, 29, 30, 31, 32, 33, 34], (440, 755), 4
            )
        add_light(22, [3, 4, 12, 15, 25, 26, 27, 33, 34], (440, 808), 4)
        add_light(23, [3, 4, 12, 15, 25, 26, 27, 33, 34], (440, 860), 4)
        add_light(24, [3, 4, 6, 7, 10, 28, 34], (440, 913), 4)
        add_light(25, [2, 5, 9, 16, 17, 21, 22, 23, 29, 30, 31, 32, 33, 34,
            35], (959, 1230), 4)
        add_light(26, [9, 12, 15, 22, 23, 33], (1011, 1230), 4)
        add_light(27, [9, 12, 15, 22, 23, 33], (1064, 1230), 4)
        add_light(28, [24, 34], (1125, 1224), 4)
        add_light(29, [6, 7, 10, 13, 14, 21, 25, 33, 34], (1300, 705), 4)
        add_light(30, [2, 5, 13, 14, 21, 25, 33, 34, 35], (1300, 653), 4)
        add_light(31, [2, 5, 13, 14, 21, 25, 33, 34, 35], (1300, 600), 4)
        add_light(32, [13, 14, 16, 17, 21, 25], (1300, 548), 4)
        add_light(33, [12, 15, 18, 19, 21, 22, 23, 25, 26, 27, 29, 30, 31],
            (791, 275), 4)
        add_light(34, [6, 7, 10, 18, 19, 21, 22, 23, 24, 28, 29, 25, 30, 31
            ], (750, 275), 4)
        add_light(35, [2, 5, 18, 19, 25, 30, 31], (694, 275), 4)
        add_light(36, [39], (2396, 966), 4)
        add_light(37, [38], (2650, 1179), 11, sync=False)
        add_light(38, [37], (2650, 251), 11, sync=False)
        add_light(39, [36, 40, 41, 42], (2290, 775), 10)
        add_light(40, [39], (2768, 590), 10)
        add_light(41, [39], (2768, 1077), 10)
        add_light(42, [39], (2768, 344), 10)
        return light_dict
    <mask token>
    <mask token>

<mask token>


class Layout:

    @staticmethod
    def load_intersection_layout(game):
        light_dict = {}

        def add_light(index, crossing, position, clearing_time=4.0, sync=True):
            light_dict[index] = TrafficLight(index, crossing, clearing_time,
                'red', position, game, sync=sync)
        add_light(2, [25, 30, 31, 35], (500, 620), 4)
        add_light(3, [21, 22, 23, 24], (500, 720), 4)
        add_light(4, [21, 22, 23, 24], (500, 935), 4)
        add_light(5, [25, 30, 31, 35], (500, 505), 4)
        add_light(6, [24, 34, 29], (785, 1095), 4)
        add_light(7, [24, 29, 34], (925, 1095), 4)
        add_light(9, [25, 26, 27], (1085, 1095), 4)
        add_light(10, [24, 29, 34], (660, 1095), 4)
        add_light(12, [22, 23, 26, 27, 33], (1242, 820), 3)
        add_light(13, [29, 30, 31, 32], (1242, 723), 4)
        add_light(14, [29, 30, 31, 32], (1242, 505), 4)
        add_light(15, [22, 26, 23, 27, 33], (1242, 925), 10)
        add_light(16, [21, 25, 32], (1085, 358), 4)
        add_light(17, [21, 25, 32], (970, 358), 4)
        add_light(18, [33, 34, 35], (819, 358), 4)
        add_light(19, [33, 34, 35], (660, 358), 4)
        add_light(21, [3, 4, 16, 17, 25, 29, 30, 31, 32, 33, 34], (440, 755), 4
            )
        add_light(22, [3, 4, 12, 15, 25, 26, 27, 33, 34], (440, 808), 4)
        add_light(23, [3, 4, 12, 15, 25, 26, 27, 33, 34], (440, 860), 4)
        add_light(24, [3, 4, 6, 7, 10, 28, 34], (440, 913), 4)
        add_light(25, [2, 5, 9, 16, 17, 21, 22, 23, 29, 30, 31, 32, 33, 34,
            35], (959, 1230), 4)
        add_light(26, [9, 12, 15, 22, 23, 33], (1011, 1230), 4)
        add_light(27, [9, 12, 15, 22, 23, 33], (1064, 1230), 4)
        add_light(28, [24, 34], (1125, 1224), 4)
        add_light(29, [6, 7, 10, 13, 14, 21, 25, 33, 34], (1300, 705), 4)
        add_light(30, [2, 5, 13, 14, 21, 25, 33, 34, 35], (1300, 653), 4)
        add_light(31, [2, 5, 13, 14, 21, 25, 33, 34, 35], (1300, 600), 4)
        add_light(32, [13, 14, 16, 17, 21, 25], (1300, 548), 4)
        add_light(33, [12, 15, 18, 19, 21, 22, 23, 25, 26, 27, 29, 30, 31],
            (791, 275), 4)
        add_light(34, [6, 7, 10, 18, 19, 21, 22, 23, 24, 28, 29, 25, 30, 31
            ], (750, 275), 4)
        add_light(35, [2, 5, 18, 19, 25, 30, 31], (694, 275), 4)
        add_light(36, [39], (2396, 966), 4)
        add_light(37, [38], (2650, 1179), 11, sync=False)
        add_light(38, [37], (2650, 251), 11, sync=False)
        add_light(39, [36, 40, 41, 42], (2290, 775), 10)
        add_light(40, [39], (2768, 590), 10)
        add_light(41, [39], (2768, 1077), 10)
        add_light(42, [39], (2768, 344), 10)
        return light_dict

    @staticmethod
    def loads_roads(game):
        VC = Sensor.SensorType.VEHICLES_COMING
        VW = Sensor.SensorType.VEHICLES_WAITING
        VB = Sensor.SensorType.BLOCKING
        BUS = Sensor.SensorType.PUBLIC_TRANSPORT
        roads = dict()
        road_conns = dict()

        def add_road(index: int, start: Tuple[int, int], end: Tuple[int,
            int], light_id: Optional[int], connection_ids: List[int],
            sensors: Union[List[Tuple[Box, Sensor.SensorType]], List[Tuple[
            Box, Sensor.SensorType, List[int]]]]):
            light = game.state[light_id] if light_id is not None else None
            roads[index] = Road(index, game, start, end, [], light)
            road_conns[index] = connection_ids
            for sensor_data in sensors:
                roads[index].add_sensor(*sensor_data)
        add_road(1, (2883, 465), (2883, 1007), None, [], [])
        add_road(2, (4023, 646), (3478, 646), None, [55], [])
        add_road(3, (3685, 490), (3685, 1040), None, [], [])
        add_road(4, (3744, 490), (3744, 1040), None, [], [])
        add_road(5, (3018, 1209), (3448, 1209), None, [], [])
        add_road(6, (3018, 1260), (3448, 1260), None, [], [])
        add_road(7, (3367, 1571), (3367, 1010), None, [], [])
        add_road(8, (79, 906), (690, 906), 24, [35, 36], [(Box((100, 895),
            (130, 925)), VC), (Box((375, 895), (405, 925)), VW)])
        add_road(9, (79, 856), (1005, 856), 23, [40], [(Box((100, 840), (
            130, 870)), VC), (Box((375, 840), (405, 870)), VW)])
        add_road(10, (79, 800), (1005, 800), 22, [41], [(Box((100, 788), (
            130, 818)), VC), (Box((375, 788), (405, 818)), VW)])
        add_road(11, (1056, 1487), (1056, 906), 27, [52], [(Box((1043, 1260
            ), (1073, 1290)), VW), (Box((1043, 1451), (1073, 1481)), VC)])
        add_road(12, (1005, 1487), (1005, 856), 26, [53], [(Box((991, 1260),
            (1021, 1290)), VW), (Box((991, 1451), (1021, 1481)), VC)])
        add_road(13, (950, 1485), (950, 540), 25, [54], [(Box((940, 1260),
            (970, 1290)), VW), (Box((936, 1451), (966, 1481)), VC)])
        add_road(14, (1110, 1487), (1110, 1200), 28, [79], [(Box((1095, 
            1250), (1125, 1280)), VC), (Box((1095, 1421), (1125, 1451)),
            BUS), (Box((1095, 1421), (1125, 1451)), VW)])
        add_road(15, (688, 100), (688, 540), 35, [43, 50], [(Box((670, 130),
            (700, 160)), VC), (Box((670, 220), (700, 250)), VW)])
        add_road(16, (740, 100), (740, 856), 34, [44, 46], [(Box((726, 130),
            (756, 160)), VC), (Box((726, 220), (756, 250)), VW)])
        add_road(17, (792, 100), (792, 856), 33, [48, 47], [(Box((778, 130),
            (808, 160)), VC), (Box((778, 220), (808, 250)), VW)])
        add_road(18, (2826, 1062), (1552, 1062), 41, [], [(Box((2806, 1050),
            (2836, 1080)), VW)])
        add_road(19, (2826, 1115), (1552, 1115), 41, [], [(Box((2806, 1100),
            (2836, 1130)), VW)])
        add_road(20, (2826, 380), (1552, 380), 42, [], [(Box((2806, 365), (
            2836, 395)), VW)])
        add_road(21, (2826, 328), (1552, 328), 42, [], [(Box((2806, 316), (
            2836, 346)), VW)])
        add_road(22, (1268, 435), (1268, 720), 14, [77], [(Box((1255, 450),
            (1285, 480)), VW)])
        add_road(23, (1211, 435), (1211, 720), 14, [86], [(Box((1200, 450),
            (1230, 480)), VW)])
        add_road(24, (1150, 328), (950, 328), 16, [102], [(Box((1110, 316),
            (1140, 346)), VW)])
        add_road(25, (1150, 380), (950, 380), 16, [103], [(Box((1110, 368),
            (1140, 398)), VW)])
        add_road(26, (478, 461), (478, 620), 5, [96], [(Box((460, 464), (
            490, 494)), VW)])
        add_road(27, (531, 461), (531, 620), 5, [97], [(Box((517, 464), (
            547, 494)), VW)])
        add_road(28, (590, 1062), (840, 1062), 10, [89], [(Box((595, 1050),
            (625, 1080)), VW)])
        add_road(29, (590, 1115), (840, 1115), 10, [90], [(Box((595, 1100),
            (625, 1130)), VW)])
        add_road(30, (79, 749), (648, 749), 21, [31], [(Box((100, 735), (
            130, 765)), VC), (Box((375, 735), (405, 765)), VW)])
        add_road(31, (648, 749), (1002, 749), None, [32, 34], [])
        add_road(32, (1002, 749), (1056, 749), None, [33], [])
        add_road(33, (1056, 749), (1056, 100), None, [], [])
        add_road(34, (1002, 749), (1002, 100), None, [], [])
        add_road(35, (690, 906), (690, 1342), None, [], [])
        add_road(36, (690, 906), (740, 906), None, [37], [])
        add_road(37, (740, 906), (740, 1342), None, [], [])
        add_road(38, (2670, 1366), (2670, 107), 37, [], [(Box((2650, 1200),
            (2680, 1230)), VW, [39])])
        add_road(39, (2550, 107), (2550, 1366), 38, [], [(Box((2540, 215),
            (2570, 245)), VW, [39])])
        add_road(40, (1005, 856), (1090, 906), None, [42], [])
        add_road(41, (1005, 800), (1055, 856), None, [81], [])
        add_road(42, (1090, 906), (2070, 906), None, [83], [(Box((1400, 894
            ), (1430, 924)), VB, [22, 23, 26, 27, 33])])
        add_road(43, (688, 540), (79, 540), None, [], [])
        add_road(44, (740, 856), (690, 856), None, [45], [])
        add_road(45, (690, 856), (690, 1342), None, [], [])
        add_road(46, (740, 856), (740, 1342), None, [], [])
        add_road(47, (792, 856), (1090, 856), None, [], [])
        add_road(48, (792, 853), (792, 906), None, [49], [])
        add_road(49, (792, 906), (1090, 906), None, [42], [])
        add_road(50, (688, 540), (688, 591), None, [51], [])
        add_road(51, (688, 591), (79, 591), None, [], [])
        add_road(52, (1056, 906), (1090, 906), None, [42], [])
        add_road(53, (1005, 856), (1055, 856), None, [81], [])
        add_road(54, (950, 540), (688, 540), None, [43], [])
        add_road(55, (3478, 646), (3364, 554), None, [56], [])
        add_road(56, (3364, 554), (3115, 554), None, [57], [])
        add_road(57, (3115, 554), (3022, 648), None, [58, 65], [])
        add_road(58, (3022, 648), (3022, 906), None, [59], [])
        add_road(59, (3022, 906), (3115, 1010), None, [60, 63], [])
        add_road(60, (3115, 1010), (3367, 1010), None, [61], [])
        add_road(61, (3367, 1010), (3478, 906), None, [62, 64], [])
        add_road(62, (3478, 906), (3478, 646), None, [55], [])
        add_road(63, (3115, 1010), (3115, 1570), None, [], [])
        add_road(64, (3478, 906), (4018, 906), None, [], [])
        add_road(65, (3022, 648), (2060, 648), 40, [66, 67, 73], [(Box((
            2816, 633), (2846, 663)), VW)])
        add_road(66, (2060, 648), (2060, 588), None, [68, 71], [])
        add_road(67, (2060, 648), (2060, 700), None, [75], [])
        add_road(68, (2060, 588), (2060, 537), None, [69], [])
        add_road(69, (2060, 537), (1056, 537), 32, [70], [(Box((1345, 526),
            (1375, 556)), VC), (Box((1970, 526), (2000, 556)), VW)])
        add_road(70, (1056, 537), (1056, 70), None, [], [])
        add_road(71, (2060, 588), (720, 588), 31, [72], [(Box((1345, 578),
            (1375, 608)), VC), (Box((1970, 578), (2000, 608)), VW)])
        add_road(72, (720, 588), (688, 540), None, [43], [])
        add_road(73, (2060, 648), (720, 648), 30, [74], [(Box((1345, 630),
            (1375, 660)), VC), (Box((1970, 630), (2000, 660)), VW)])
        add_road(74, (720, 648), (688, 591), 29, [51], [(Box((1345, 680), (
            1375, 710)), VC), (Box((1970, 680), (2000, 710)), VW)])
        add_road(75, (2060, 700), (690, 700), None, [76], [])
        add_road(76, (690, 700), (690, 906), None, [35], [])
        add_road(77, (1268, 720), (1268, 985), 12, [], [(Box((1255, 755), (
            1285, 785)), VW)])
        add_road(79, (1110, 1200), (740, 1200), None, [80], [])
        add_road(80, (740, 1200), (740, 1345), None, [], [])
        add_road(81, (1055, 856), (2040, 856), None, [82], [(Box((1400, 840
            ), (1430, 870)), VB, [22, 23, 26, 27, 33])])
        add_road(82, (2040, 856), (2070, 906), None, [83], [])
        add_road(83, (2070, 906), (3022, 906), 36, [59], [(Box((2340, 894),
            (2370, 924)), VW)])
        add_road(84, (1268, 985), (1268, 840), 15, [85], [(Box((1255, 950),
            (1285, 980)), VW)])
        add_road(85, (1268, 840), (1268, 461), 13, [], [(Box((1255, 750), (
            1285, 780)), VW)])
        add_road(86, (1211, 720), (1211, 985), 12, [], [(Box((1200, 755), (
            1230, 785)), VW)])
        add_road(87, (1211, 985), (1211, 800), 15, [88], [(Box((1200, 950),
            (1230, 980)), VW)])
        add_road(88, (1211, 800), (1211, 461), 13, [], [(Box((1200, 750), (
            1230, 780)), VW)])
        add_road(89, (840, 1062), (1135, 1062), 7, [], [(Box((870, 1050), (
            900, 1080)), VW)])
        add_road(90, (840, 1115), (1134, 1115), 7, [], [(Box((870, 1100), (
            900, 1130)), VW)])
        add_road(91, (1140, 1062), (1000, 1062), 9, [94], [(Box((1110, 1050
            ), (1140, 1080)), VW)])
        add_road(92, (1140, 1115), (1000, 1115), 9, [95], [(Box((1110, 1100
            ), (1140, 1130)), VW)])
        add_road(94, (1000, 1062), (610, 1062), 6, [], [(Box((810, 1050), (
            840, 1080)), VW)])
        add_road(95, (1000, 1115), (610, 1115), 6, [], [(Box((810, 1100), (
            840, 1130)), VW)])
        add_road(96, (478, 620), (478, 985), 3, [], [(Box((460, 660), (490,
            690)), VW)])
        add_road(97, (531, 620), (531, 985), 3, [], [(Box((517, 660), (547,
            690)), VW)])
        add_road(98, (478, 985), (478, 700), 4, [100], [(Box((460, 950), (
            490, 980)), VW)])
        add_road(99, (531, 985), (531, 700), 4, [101], [(Box((517, 950), (
            547, 980)), VW)])
        add_road(100, (478, 700), (478, 461), 2, [], [(Box((460, 645), (490,
            675)), VW)])
        add_road(101, (531, 700), (531, 461), 2, [], [(Box((517, 645), (547,
            675)), VW)])
        add_road(102, (950, 328), (610, 328), 18, [], [(Box((850, 316), (
            880, 346)), VW)])
        add_road(103, (950, 380), (610, 380), 18, [], [(Box((850, 368), (
            880, 398)), VW)])
        add_road(104, (595, 328), (820, 328), 19, [106], [(Box((600, 316),
            (630, 346)), VW)])
        add_road(105, (595, 380), (820, 380), 19, [107], [(Box((600, 368),
            (630, 398)), VW)])
        add_road(106, (820, 328), (1134, 328), 17, [], [(Box((910, 316), (
            940, 346)), VW)])
        add_road(107, (820, 380), (1134, 380), 17, [], [(Box((910, 368), (
            940, 398)), VW)])
        for i, connections_for_road in road_conns.items():
            roads[i].connections = [roads[j] for j in connections_for_road]
        return roads

    @staticmethod
    def load_spawnpoints(game):
        spawnpoints = [('bike', 1), ('car', 2), ('bike', 3), ('man', 4), (
            'bike', 5), ('man', 6), ('car', 7), ('car', 8), ('car', 9), (
            'car', 10), ('car', 11), ('car', 12), ('car', 13), ('bus', 14),
            ('car', 15), ('car', 16), ('car', 17), ('bike', 18), ('man', 19
            ), ('bike', 20), ('man', 21), ('man', 22), ('bike', 23), ('man',
            24), ('bike', 25), ('man', 26), ('bike', 27), ('bike', 28), (
            'man', 29), ('car', 30), ('boat', 38), ('boat', 39), ('man', 84
            ), ('bike', 87), ('bike', 91), ('man', 92), ('bike', 98), (
            'man', 99), ('man', 104), ('bike', 105)]
        result = []
        for type, road_idx in spawnpoints:
            if type in ['man', 'bike']:
                speed = 15
                cooldown = 40
            elif type in ['car', 'boat']:
                speed = 65
                cooldown = 40
            elif type in ['bus']:
                speed = 40
                cooldown = 400
            else:
                raise NotImplementedError()
            result.append(SpawnPoint(game, type, game.roads[road_idx],
                speed=speed, cooldown=cooldown))
        return result

from typing import List, Tuple, Optional, Union
from game_objects import *
from traffic_light import *
from utils import *


class Layout:

    @staticmethod
    def load_intersection_layout(game):
        light_dict = {}

        def add_light(index, crossing, position, clearing_time=4.0, sync=True):
            light_dict[index] = TrafficLight(index, crossing, clearing_time,
                'red', position, game, sync=sync)
        add_light(2, [25, 30, 31, 35], (500, 620), 4)
        add_light(3, [21, 22, 23, 24], (500, 720), 4)
        add_light(4, [21, 22, 23, 24], (500, 935), 4)
        add_light(5, [25, 30, 31, 35], (500, 505), 4)
        add_light(6, [24, 34, 29], (785, 1095), 4)
        add_light(7, [24, 29, 34], (925, 1095), 4)
        add_light(9, [25, 26, 27], (1085, 1095), 4)
        add_light(10, [24, 29, 34], (660, 1095), 4)
        add_light(12, [22, 23, 26, 27, 33], (1242, 820), 3)
        add_light(13, [29, 30, 31, 32], (1242, 723), 4)
        add_light(14, [29, 30, 31, 32], (1242, 505), 4)
        add_light(15, [22, 26, 23, 27, 33], (1242, 925), 10)
        add_light(16, [21, 25, 32], (1085, 358), 4)
        add_light(17, [21, 25, 32], (970, 358), 4)
        add_light(18, [33, 34, 35], (819, 358), 4)
        add_light(19, [33, 34, 35], (660, 358), 4)
        add_light(21, [3, 4, 16, 17, 25, 29, 30, 31, 32, 33, 34], (440, 755), 4
            )
        add_light(22, [3, 4, 12, 15, 25, 26, 27, 33, 34], (440, 808), 4)
        add_light(23, [3, 4, 12, 15, 25, 26, 27, 33, 34], (440, 860), 4)
        add_light(24, [3, 4, 6, 7, 10, 28, 34], (440, 913), 4)
        add_light(25, [2, 5, 9, 16, 17, 21, 22, 23, 29, 30, 31, 32, 33, 34,
            35], (959, 1230), 4)
        add_light(26, [9, 12, 15, 22, 23, 33], (1011, 1230), 4)
        add_light(27, [9, 12, 15, 22, 23, 33], (1064, 1230), 4)
        add_light(28, [24, 34], (1125, 1224), 4)
        add_light(29, [6, 7, 10, 13, 14, 21, 25, 33, 34], (1300, 705), 4)
        add_light(30, [2, 5, 13, 14, 21, 25, 33, 34, 35], (1300, 653), 4)
        add_light(31, [2, 5, 13, 14, 21, 25, 33, 34, 35], (1300, 600), 4)
        add_light(32, [13, 14, 16, 17, 21, 25], (1300, 548), 4)
        add_light(33, [12, 15, 18, 19, 21, 22, 23, 25, 26, 27, 29, 30, 31],
            (791, 275), 4)
        add_light(34, [6, 7, 10, 18, 19, 21, 22, 23, 24, 28, 29, 25, 30, 31
            ], (750, 275), 4)
        add_light(35, [2, 5, 18, 19, 25, 30, 31], (694, 275), 4)
        add_light(36, [39], (2396, 966), 4)
        add_light(37, [38], (2650, 1179), 11, sync=False)
        add_light(38, [37], (2650, 251), 11, sync=False)
        add_light(39, [36, 40, 41, 42], (2290, 775), 10)
        add_light(40, [39], (2768, 590), 10)
        add_light(41, [39], (2768, 1077), 10)
        add_light(42, [39], (2768, 344), 10)
        return light_dict

    @staticmethod
    def loads_roads(game):
        VC = Sensor.SensorType.VEHICLES_COMING
        VW = Sensor.SensorType.VEHICLES_WAITING
        VB = Sensor.SensorType.BLOCKING
        BUS = Sensor.SensorType.PUBLIC_TRANSPORT
        roads = dict()
        road_conns = dict()

        def add_road(index: int, start: Tuple[int, int], end: Tuple[int,
            int], light_id: Optional[int], connection_ids: List[int],
            sensors: Union[List[Tuple[Box, Sensor.SensorType]], List[Tuple[
            Box, Sensor.SensorType, List[int]]]]):
            light = game.state[light_id] if light_id is not None else None
            roads[index] = Road(index, game, start, end, [], light)
            road_conns[index] = connection_ids
            for sensor_data in sensors:
                roads[index].add_sensor(*sensor_data)
        add_road(1, (2883, 465), (2883, 1007), None, [], [])
        add_road(2, (4023, 646), (3478, 646), None, [55], [])
        add_road(3, (3685, 490), (3685, 1040), None, [], [])
        add_road(4, (3744, 490), (3744, 1040), None, [], [])
        add_road(5, (3018, 1209), (3448, 1209), None, [], [])
        add_road(6, (3018, 1260), (3448, 1260), None, [], [])
        add_road(7, (3367, 1571), (3367, 1010), None, [], [])
        add_road(8, (79, 906), (690, 906), 24, [35, 36], [(Box((100, 895),
            (130, 925)), VC), (Box((375, 895), (405, 925)), VW)])
        add_road(9, (79, 856), (1005, 856), 23, [40], [(Box((100, 840), (
            130, 870)), VC), (Box((375, 840), (405, 870)), VW)])
        add_road(10, (79, 800), (1005, 800), 22, [41], [(Box((100, 788), (
            130, 818)), VC), (Box((375, 788), (405, 818)), VW)])
        add_road(11, (1056, 1487), (1056, 906), 27, [52], [(Box((1043, 1260
            ), (1073, 1290)), VW), (Box((1043, 1451), (1073, 1481)), VC)])
        add_road(12, (1005, 1487), (1005, 856), 26, [53], [(Box((991, 1260),
            (1021, 1290)), VW), (Box((991, 1451), (1021, 1481)), VC)])
        add_road(13, (950, 1485), (950, 540), 25, [54], [(Box((940, 1260),
            (970, 1290)), VW), (Box((936, 1451), (966, 1481)), VC)])
        add_road(14, (1110, 1487), (1110, 1200), 28, [79], [(Box((1095, 
            1250), (1125, 1280)), VC), (Box((1095, 1421), (1125, 1451)),
            BUS), (Box((1095, 1421), (1125, 1451)), VW)])
        add_road(15, (688, 100), (688, 540), 35, [43, 50], [(Box((670, 130),
            (700, 160)), VC), (Box((670, 220), (700, 250)), VW)])
        add_road(16, (740, 100), (740, 856), 34, [44, 46], [(Box((726, 130),
            (756, 160)), VC), (Box((726, 220), (756, 250)), VW)])
        add_road(17, (792, 100), (792, 856), 33, [48, 47], [(Box((778, 130),
            (808, 160)), VC), (Box((778, 220), (808, 250)), VW)])
        add_road(18, (2826, 1062), (1552, 1062), 41, [], [(Box((2806, 1050),
            (2836, 1080)), VW)])
        add_road(19, (2826, 1115), (1552, 1115), 41, [], [(Box((2806, 1100),
            (2836, 1130)), VW)])
        add_road(20, (2826, 380), (1552, 380), 42, [], [(Box((2806, 365), (
            2836, 395)), VW)])
        add_road(21, (2826, 328), (1552, 328), 42, [], [(Box((2806, 316), (
            2836, 346)), VW)])
        add_road(22, (1268, 435), (1268, 720), 14, [77], [(Box((1255, 450),
            (1285, 480)), VW)])
        add_road(23, (1211, 435), (1211, 720), 14, [86], [(Box((1200, 450),
            (1230, 480)), VW)])
        add_road(24, (1150, 328), (950, 328), 16, [102], [(Box((1110, 316),
            (1140, 346)), VW)])
        add_road(25, (1150, 380), (950, 380), 16, [103], [(Box((1110, 368),
            (1140, 398)), VW)])
        add_road(26, (478, 461), (478, 620), 5, [96], [(Box((460, 464), (
            490, 494)), VW)])
        add_road(27, (531, 461), (531, 620), 5, [97], [(Box((517, 464), (
            547, 494)), VW)])
        add_road(28, (590, 1062), (840, 1062), 10, [89], [(Box((595, 1050),
            (625, 1080)), VW)])
        add_road(29, (590, 1115), (840, 1115), 10, [90], [(Box((595, 1100),
            (625, 1130)), VW)])
        add_road(30, (79, 749), (648, 749), 21, [31], [(Box((100, 735), (
            130, 765)), VC), (Box((375, 735), (405, 765)), VW)])
        add_road(31, (648, 749), (1002, 749), None, [32, 34], [])
        add_road(32, (1002, 749), (1056, 749), None, [33], [])
        add_road(33, (1056, 749), (1056, 100), None, [], [])
        add_road(34, (1002, 749), (1002, 100), None, [], [])
        add_road(35, (690, 906), (690, 1342), None, [], [])
        add_road(36, (690, 906), (740, 906), None, [37], [])
        add_road(37, (740, 906), (740, 1342), None, [], [])
        add_road(38, (2670, 1366), (2670, 107), 37, [], [(Box((2650, 1200),
            (2680, 1230)), VW, [39])])
        add_road(39, (2550, 107), (2550, 1366), 38, [], [(Box((2540, 215),
            (2570, 245)), VW, [39])])
        add_road(40, (1005, 856), (1090, 906), None, [42], [])
        add_road(41, (1005, 800), (1055, 856), None, [81], [])
        add_road(42, (1090, 906), (2070, 906), None, [83], [(Box((1400, 894
            ), (1430, 924)), VB, [22, 23, 26, 27, 33])])
        add_road(43, (688, 540), (79, 540), None, [], [])
        add_road(44, (740, 856), (690, 856), None, [45], [])
        add_road(45, (690, 856), (690, 1342), None, [], [])
        add_road(46, (740, 856), (740, 1342), None, [], [])
        add_road(47, (792, 856), (1090, 856), None, [], [])
        add_road(48, (792, 853), (792, 906), None, [49], [])
        add_road(49, (792, 906), (1090, 906), None, [42], [])
        add_road(50, (688, 540), (688, 591), None, [51], [])
        add_road(51, (688, 591), (79, 591), None, [], [])
        add_road(52, (1056, 906), (1090, 906), None, [42], [])
        add_road(53, (1005, 856), (1055, 856), None, [81], [])
        add_road(54, (950, 540), (688, 540), None, [43], [])
        add_road(55, (3478, 646), (3364, 554), None, [56], [])
        add_road(56, (3364, 554), (3115, 554), None, [57], [])
        add_road(57, (3115, 554), (3022, 648), None, [58, 65], [])
        add_road(58, (3022, 648), (3022, 906), None, [59], [])
        add_road(59, (3022, 906), (3115, 1010), None, [60, 63], [])
        add_road(60, (3115, 1010), (3367, 1010), None, [61], [])
        add_road(61, (3367, 1010), (3478, 906), None, [62, 64], [])
        add_road(62, (3478, 906), (3478, 646), None, [55], [])
        add_road(63, (3115, 1010), (3115, 1570), None, [], [])
        add_road(64, (3478, 906), (4018, 906), None, [], [])
        add_road(65, (3022, 648), (2060, 648), 40, [66, 67, 73], [(Box((
            2816, 633), (2846, 663)), VW)])
        add_road(66, (2060, 648), (2060, 588), None, [68, 71], [])
        add_road(67, (2060, 648), (2060, 700), None, [75], [])
        add_road(68, (2060, 588), (2060, 537), None, [69], [])
        add_road(69, (2060, 537), (1056, 537), 32, [70], [(Box((1345, 526),
            (1375, 556)), VC), (Box((1970, 526), (2000, 556)), VW)])
        add_road(70, (1056, 537), (1056, 70), None, [], [])
        add_road(71, (2060, 588), (720, 588), 31, [72], [(Box((1345, 578),
            (1375, 608)), VC), (Box((1970, 578), (2000, 608)), VW)])
        add_road(72, (720, 588), (688, 540), None, [43], [])
        add_road(73, (2060, 648), (720, 648), 30, [74], [(Box((1345, 630),
            (1375, 660)), VC), (Box((1970, 630), (2000, 660)), VW)])
        add_road(74, (720, 648), (688, 591), 29, [51], [(Box((1345, 680), (
            1375, 710)), VC), (Box((1970, 680), (2000, 710)), VW)])
        add_road(75, (2060, 700), (690, 700), None, [76], [])
        add_road(76, (690, 700), (690, 906), None, [35], [])
        add_road(77, (1268, 720), (1268, 985), 12, [], [(Box((1255, 755), (
            1285, 785)), VW)])
        add_road(79, (1110, 1200), (740, 1200), None, [80], [])
        add_road(80, (740, 1200), (740, 1345), None, [], [])
        add_road(81, (1055, 856), (2040, 856), None, [82], [(Box((1400, 840
            ), (1430, 870)), VB, [22, 23, 26, 27, 33])])
        add_road(82, (2040, 856), (2070, 906), None, [83], [])
        add_road(83, (2070, 906), (3022, 906), 36, [59], [(Box((2340, 894),
            (2370, 924)), VW)])
        add_road(84, (1268, 985), (1268, 840), 15, [85], [(Box((1255, 950),
            (1285, 980)), VW)])
        add_road(85, (1268, 840), (1268, 461), 13, [], [(Box((1255, 750), (
            1285, 780)), VW)])
        add_road(86, (1211, 720), (1211, 985), 12, [], [(Box((1200, 755), (
            1230, 785)), VW)])
        add_road(87, (1211, 985), (1211, 800), 15, [88], [(Box((1200, 950),
            (1230, 980)), VW)])
        add_road(88, (1211, 800), (1211, 461), 13, [], [(Box((1200, 750), (
            1230, 780)), VW)])
        add_road(89, (840, 1062), (1135, 1062), 7, [], [(Box((870, 1050), (
            900, 1080)), VW)])
        add_road(90, (840, 1115), (1134, 1115), 7, [], [(Box((870, 1100), (
            900, 1130)), VW)])
        add_road(91, (1140, 1062), (1000, 1062), 9, [94], [(Box((1110, 1050
            ), (1140, 1080)), VW)])
        add_road(92, (1140, 1115), (1000, 1115), 9, [95], [(Box((1110, 1100
            ), (1140, 1130)), VW)])
        add_road(94, (1000, 1062), (610, 1062), 6, [], [(Box((810, 1050), (
            840, 1080)), VW)])
        add_road(95, (1000, 1115), (610, 1115), 6, [], [(Box((810, 1100), (
            840, 1130)), VW)])
        add_road(96, (478, 620), (478, 985), 3, [], [(Box((460, 660), (490,
            690)), VW)])
        add_road(97, (531, 620), (531, 985), 3, [], [(Box((517, 660), (547,
            690)), VW)])
        add_road(98, (478, 985), (478, 700), 4, [100], [(Box((460, 950), (
            490, 980)), VW)])
        add_road(99, (531, 985), (531, 700), 4, [101], [(Box((517, 950), (
            547, 980)), VW)])
        add_road(100, (478, 700), (478, 461), 2, [], [(Box((460, 645), (490,
            675)), VW)])
        add_road(101, (531, 700), (531, 461), 2, [], [(Box((517, 645), (547,
            675)), VW)])
        add_road(102, (950, 328), (610, 328), 18, [], [(Box((850, 316), (
            880, 346)), VW)])
        add_road(103, (950, 380), (610, 380), 18, [], [(Box((850, 368), (
            880, 398)), VW)])
        add_road(104, (595, 328), (820, 328), 19, [106], [(Box((600, 316),
            (630, 346)), VW)])
        add_road(105, (595, 380), (820, 380), 19, [107], [(Box((600, 368),
            (630, 398)), VW)])
        add_road(106, (820, 328), (1134, 328), 17, [], [(Box((910, 316), (
            940, 346)), VW)])
        add_road(107, (820, 380), (1134, 380), 17, [], [(Box((910, 368), (
            940, 398)), VW)])
        for i, connections_for_road in road_conns.items():
            roads[i].connections = [roads[j] for j in connections_for_road]
        return roads

    @staticmethod
    def load_spawnpoints(game):
        spawnpoints = [('bike', 1), ('car', 2), ('bike', 3), ('man', 4), (
            'bike', 5), ('man', 6), ('car', 7), ('car', 8), ('car', 9), (
            'car', 10), ('car', 11), ('car', 12), ('car', 13), ('bus', 14),
            ('car', 15), ('car', 16), ('car', 17), ('bike', 18), ('man', 19
            ), ('bike', 20), ('man', 21), ('man', 22), ('bike', 23), ('man',
            24), ('bike', 25), ('man', 26), ('bike', 27), ('bike', 28), (
            'man', 29), ('car', 30), ('boat', 38), ('boat', 39), ('man', 84
            ), ('bike', 87), ('bike', 91), ('man', 92), ('bike', 98), (
            'man', 99), ('man', 104), ('bike', 105)]
        result = []
        for type, road_idx in spawnpoints:
            if type in ['man', 'bike']:
                speed = 15
                cooldown = 40
            elif type in ['car', 'boat']:
                speed = 65
                cooldown = 40
            elif type in ['bus']:
                speed = 40
                cooldown = 400
            else:
                raise NotImplementedError()
            result.append(SpawnPoint(game, type, game.roads[road_idx],
                speed=speed, cooldown=cooldown))
        return result

from typing import List, Tuple, Optional, Union

from game_objects import *
from traffic_light import *
from utils import *


class Layout:
    @staticmethod
    def load_intersection_layout(game):
        light_dict = {}

        def add_light(index, crossing, position, clearing_time=4.0, sync = True):
            light_dict[index] = TrafficLight(index, crossing, clearing_time, "red", position, game, sync = sync)

        # add_light(1, [30, 31, 35], (530, 520), 4)
        add_light(2, [25, 30, 31, 35], (500, 620), 4)
        add_light(3, [21, 22, 23, 24], (500, 720), 4)
        add_light(4, [21, 22, 23, 24], (500, 935), 4)
        add_light(5, [25, 30, 31, 35], (500, 505), 4)
        add_light(6, [24, 34 , 29], (785, 1095), 4)
        add_light(7, [24, 29, 34], (925, 1095), 4)
        # add_light(8, [25, 26, 27], (1040, 1095), 4)
        add_light(9, [25, 26, 27], (1085, 1095), 4)
        add_light(10, [24, 29,  34], (660, 1095), 4)
        # add_light(11, [22, 23, 27, 33], (1225, 925), 10)
        add_light(12, [22, 23, 26, 27, 33], (1242, 820), 3)
        add_light(13, [29, 30, 31, 32], (1242, 723), 4)
        add_light(14, [29, 30, 31, 32], (1242, 505), 4)
        add_light(15, [22, 26, 23, 27, 33], (1242, 925), 10)
        add_light(16, [21, 25, 32], (1085, 358), 4)
        add_light(17, [21, 25, 32], (970, 358), 4)
        add_light(18, [33, 34, 35], (819, 358), 4)
        add_light(19, [33, 34, 35], (660, 358), 4)
        # add_light(20, [21, 25, 32], (1081, 365), 4)
        add_light(21, [3, 4, 16, 17, 25, 29, 30, 31, 32, 33, 34], (440, 755), 4)
        add_light(22, [3, 4, 12, 15, 25, 26, 27, 33, 34], (440, 808), 4)
        add_light(23, [3, 4, 12, 15, 25, 26, 27, 33, 34], (440, 860), 4)
        add_light(24, [3, 4, 6, 7, 10, 28, 34], (440, 913), 4)
        add_light(25, [2, 5, 9, 16, 17,  21, 22, 23, 29, 30, 31, 32, 33, 34, 35], (959, 1230), 4)
        add_light(26, [9, 12, 15, 22, 23, 33], (1011, 1230), 4)
        add_light(27, [9,  12, 15, 22, 23, 33], (1064, 1230), 4)
        add_light(28, [24, 34], (1125,  1224), 4)  # bus line
        add_light(29, [6, 7, 10, 13, 14, 21, 25, 33, 34], (1300, 705), 4)
        add_light(30, [2, 5,  13, 14, 21, 25, 33, 34, 35], (1300, 653), 4)
        add_light(31, [2, 5, 13, 14, 21, 25, 33, 34, 35], (1300, 600), 4)
        add_light(32, [13, 14, 16, 17, 21, 25], (1300, 548), 4)
        add_light(33, [12, 15, 18, 19, 21, 22, 23, 25, 26, 27, 29, 30, 31], (791, 275 ), 4)
        add_light(34, [6, 7, 10, 18, 19, 21, 22, 23, 24, 28, 29, 25, 30, 31], (750, 275), 4)
        add_light(35, [2, 5, 18, 19,  25, 30, 31], (694, 275), 4)
        add_light(36, [39], (2396, 966), 4)  # bridge
        add_light(37, [38], (2650, 1179), 11, sync = False)
        add_light(38, [37], (2650, 251), 11, sync = False)
        add_light(39, [36, 40, 41, 42], (2290, 775), 10)
        add_light(40, [39], (2768, 590), 10)
        add_light(41, [39], (2768, 1077), 10)
        add_light(42, [39], (2768, 344), 10)

        return light_dict


    @staticmethod
    def loads_roads(game):
        VC  = Sensor.SensorType.VEHICLES_COMING
        VW  = Sensor.SensorType.VEHICLES_WAITING
        VB  = Sensor.SensorType.BLOCKING
        BUS = Sensor.SensorType.PUBLIC_TRANSPORT

        roads = dict()
        road_conns = dict()


        def add_road(
                index: int,
                start: Tuple[int, int],
                end: Tuple[int, int],
                light_id: Optional[int],
                connection_ids: List[int],
                sensors: Union[
                    List[Tuple[Box, Sensor.SensorType]],            # Area + Type
                    List[Tuple[Box, Sensor.SensorType, List[int]]]  # Area + Type + Target Light
                ]
        ):
            light = game.state[light_id] if light_id is not None else None

            roads[index] = Road(index, game, start, end, [], light)
            road_conns[index] = connection_ids

            for sensor_data in sensors:
                roads[index].add_sensor(*sensor_data)


        add_road(1, (2883, 465), (2883, 1007), None, [], [])
        add_road(2, (4023, 646), (3478, 646), None, [55], [])
        add_road(3, (3685, 490), (3685, 1040), None, [], [])
        add_road(4, (3744, 490), (3744, 1040), None, [], [])
        add_road(5, (3018, 1209), (3448, 1209), None, [], [])
        add_road(6, (3018, 1260), (3448, 1260), None, [], [])
        add_road(7, (3367, 1571), (3367, 1010), None, [], [])
        add_road(8, (79, 906), (690, 906), 24, [35, 36], [
            (Box((100, 895), (130, 925)), VC),
            (Box((375, 895), (405 , 925)), VW)
        ])
        add_road(9, (79, 856), (1005, 856), 23, [40], [
            (Box((100, 840), (130, 870)), VC),
            (Box((375, 840), (405, 870)), VW)
        ])
        add_road(10, (79, 800), (1005, 800), 22, [41], [
            (Box((100, 788), (130, 818)), VC),
            (Box((375, 788), (405, 818)), VW)
        ])
        add_road(11, (1056, 1487), (1056, 906), 27, [52], [
            (Box((1043, 1260), (1073, 1290)), VW),
            (Box((1043, 1451), (1073, 1481)), VC)
        ])
        add_road(12, (1005, 1487), (1005, 856), 26, [53], [
            (Box((991, 1260), (1021, 1290)), VW),
            (Box((991, 1451), (1021, 1481)), VC)
        ])
        add_road(13, (950, 1485), (950, 540), 25, [54], [
            (Box((940, 1260), (970, 1290)), VW),
            (Box((936, 1451), (966, 1481)), VC)
        ])
        add_road(14, (1110, 1487), (1110, 1200), 28, [79], [
            (Box((1095, 1250), (1125, 1280)), VC),
            (Box((1095, 1421), (1125, 1451)), BUS),
            (Box((1095, 1421), (1125, 1451)), VW),
        ])  # bus line
        add_road(15, (688, 100), (688, 540), 35, [43, 50], [
            (Box((670, 130), (700, 160)), VC),
            (Box((670, 220), (700, 250)), VW)
        ])
        add_road(16, (740, 100), (740, 856), 34, [44, 46], [
            (Box((726, 130), (756, 160)), VC),
            (Box((726, 220), (756, 250)), VW)
        ])
        add_road(17, (792, 100), (792, 856), 33, [48, 47], [
            (Box((778, 130), (808, 160)), VC),
            (Box((778, 220), (808, 250)), VW)
        ])
        add_road(18, (2826, 1062), (1552, 1062), 41, [], [
            (Box((2806, 1050), (2836, 1080)), VW)
        ])
        add_road(19, (2826, 1115), (1552, 1115), 41, [], [
            (Box((2806, 1100), (2836, 1130)), VW)
        ])
        add_road(20, (2826, 380), (1552, 380), 42, [], [
            (Box((2806, 365), (2836, 395)), VW)
        ])
        add_road(21, (2826, 328), (1552, 328), 42, [], [
            (Box((2806, 316), (2836, 346)), VW)
        ])
        add_road(22, (1268, 435), (1268, 720), 14, [77], [
            (Box((1255, 450), (1285, 480)), VW)
        ])
        add_road(23, (1211, 435), (1211, 720), 14, [86], [
            (Box((1200, 450), (1230, 480)), VW)
        ])
        add_road(24, (1150, 328), (950, 328), 16, [102], [
            (Box((1110, 316), (1140, 346)), VW)
        ])
        add_road(25, (1150, 380), (950, 380), 16, [103], [
            (Box((1110, 368), (1140, 398)), VW)
        ])
        add_road(26, (478, 461), (478, 620), 5, [96], [
            (Box((460, 464), (490, 494)), VW)
        ])
        add_road(27, (531, 461), (531,  620), 5, [97], [
            (Box((517, 464), (547, 494)), VW)
        ])
        add_road(28, (590, 1062), (840, 1062), 10, [89], [
            (Box((595, 1050), (625, 1080)), VW)
        ])
        add_road(29, (590, 1115), (840, 1115), 10, [90], [
            (Box((595, 1100), (625, 1130)), VW)
        ])
        add_road(30, (79, 749), (648, 749), 21, [31], [
            (Box((100, 735), (130, 765)), VC),
            (Box((375, 735), (405, 765)), VW)
        ])
        add_road(31, (648, 749), (1002, 749), None, [32, 34], [])
        add_road(32, (1002, 749), (1056, 749), None, [33], [])
        add_road(33, (1056, 749), (1056, 100), None, [], [])
        add_road(34, (1002, 749), (1002, 100), None, [], [])
        add_road(35, (690, 906), (690, 1342), None, [], [])
        add_road(36, (690, 906), (740, 906), None, [37], [])
        add_road(37, (740, 906), (740, 1342), None, [], [])
        add_road(38, (2670, 1366), (2670, 107), 37, [], [
            (Box((2650, 1200), (2680, 1230)), VW, [39])
        ])
        add_road(39, (2550, 107), (2550, 1366), 38, [], [
            (Box((2540, 215), (2570, 245)), VW, [39])
        ])
        add_road(40, (1005, 856), (1090, 906), None, [42], [])
        add_road(41, (1005, 800), (1055, 856), None, [81], [])
        add_road(42, (1090, 906), (2070, 906), None, [83], [
            (Box((1400, 894), (1430, 924)), VB, [22, 23, 26, 27, 33]),
        ])
        add_road(43, (688, 540), (79, 540), None, [], [])
        add_road(44, (740, 856), (690, 856), None, [45], [])
        add_road(45, (690, 856), (690, 1342), None, [], [])
        add_road(46, (740, 856), (740, 1342), None, [], [])
        add_road(47, (792, 856), (1090, 856), None, [], [])
        add_road(48, (792, 853), (792, 906), None, [49], [])
        add_road(49, (792, 906), (1090, 906), None, [42], [])
        add_road(50, (688, 540), (688, 591), None, [51], [])
        add_road(51, (688, 591), (79, 591), None, [], [])
        add_road(52, (1056, 906), (1090, 906), None, [42], [])
        add_road(53, (1005, 856), (1055, 856), None, [81], [])
        # add_road(54, (688, 906), (79000, 591), None, [], [])
        add_road(54, (950, 540), (688, 540), None, [43], [])
        # roundabout
        add_road(55, (3478, 646), (3364, 554), None, [56], [])
        add_road(56, (3364, 554), (3115, 554), None, [57], [])
        add_road(57, (3115, 554), (3022, 648), None, [58, 65], [])
        add_road(58, (3022, 648), (3022, 906), None, [59], [])
        add_road(59, (3022, 906), (3115, 1010), None, [60, 63], [])
        add_road(60, (3115, 1010), (3367, 1010), None, [61], [])
        add_road(61, (3367, 1010), (3478, 906), None, [62, 64], [])
        add_road(62, (3478, 906), (3478, 646), None, [55], [])
        add_road(63, (3115, 1010), (3115, 1570), None, [], [])
        add_road(64, (3478, 906), (4018, 906), None, [], [])
        # purple road
        add_road(65, (3022, 648), (2060, 648), 40, [66, 67, 73], [
            (Box((2816, 633), (2846, 663)), VW)
        ])
        add_road(66, (2060, 648), (2060, 588), None, [68, 71], [])
        add_road(67, (2060, 648), (2060, 700), None, [75], [])
        add_road(68, (2060, 588), (2060, 537), None, [69], [])
        add_road(69, (2060, 537), (1056, 537), 32, [70], [
            (Box((1345, 526), (1375,  556)), VC),
            (Box((1970, 526), (2000, 556)), VW)
        ])
        add_road(70, (1056, 537), (1056, 70), None, [], [])
        add_road(71, (2060, 588), (720, 588), 31, [72], [
            (Box((1345, 578), (1375, 608)), VC),
            (Box((1970, 578), (2000, 608)), VW)
        ])
        add_road(72, (720, 588), (688, 540), None, [43], [])
        add_road(73, (2060, 648), (720, 648), 30, [74], [
            (Box((1345, 630), (1375, 660)), VC),
            (Box((1970, 630), (2000, 660)), VW)
        ])
        add_road(74, (720, 648), (688, 591), 29, [51], [
            (Box((1345, 680), (1375, 710)), VC),
            (Box((1970, 680), (2000, 710)), VW)
        ])
        add_road(75, (2060, 700), (690, 700), None, [76], [])
        add_road(76, (690, 700), (690, 906), None, [35], [])
        add_road(77, (1268, 720), (1268, 985), 12, [], [
            (Box((1255, 755), (1285, 785)), VW)
        ])
        add_road(79, (1110, 1200), (740, 1200), None, [80], [])
        add_road(80, (740, 1200), (740, 1345), None, [], [])
        add_road(81, (1055, 856), (2040, 856), None, [82], [
            (Box((1400, 840), (1430, 870)), VB, [22, 23, 26, 27,33]),
        ])
        add_road(82, (2040, 856), (2070, 906), None, [83], [])
        add_road(83, (2070, 906), (3022, 906), 36, [59], [
            (Box((2340, 894), (2370, 924)), VW)
        ])
        add_road(84, (1268, 985), (1268, 840), 15, [85], [
            (Box((1255, 950), (1285, 980)), VW)
        ])
        add_road(85, (1268, 840), (1268, 461), 13, [], [
            (Box((1255, 750), (1285, 780)), VW)
        ])
        add_road(86, (1211, 720), (1211, 985), 12, [], [
            (Box((1200, 755), (1230, 785)), VW)
        ])
        add_road(87, (1211, 985), (1211, 800), 15, [88], [
            (Box((1200, 950), (1230, 980)), VW)
        ])
        add_road(88, (1211, 800), (1211, 461), 13, [], [
            (Box((1200, 750), (1230, 780)), VW)
        ])
        add_road(89, (840, 1062), (1135, 1062), 7, [], [
            (Box((870, 1050), (900, 1080)), VW)
        ])
        add_road(90, (840, 1115), (1134, 1115), 7, [], [
            (Box((870, 1100), (900, 1130)), VW)
        ])
        add_road(91, (1140, 1062), (1000, 1062), 9, [94], [
            (Box((1110, 1050), (1140, 1080)), VW)
        ])
        add_road(92, (1140, 1115), (1000, 1115), 9, [95], [
            (Box((1110, 1100), (1140, 1130)), VW)
        ])
        add_road(94, (1000, 1062), (610, 1062), 6, [], [
            (Box((810, 1050), (840, 1080)), VW)
        ])
        add_road(95, (1000, 1115), (610, 1115), 6, [], [
            (Box((810, 1100), (840, 1130)), VW)
        ])
        add_road(96, (478, 620), (478, 985), 3, [], [
            (Box((460, 660), (490, 690)), VW)
        ])
        add_road(97, (531, 620), (531, 985), 3, [], [
            (Box((517, 660), (547, 690)), VW)
        ])
        add_road(98, (478, 985), (478, 700), 4, [100], [
            (Box((460, 950), (490, 980)), VW)
        ])
        add_road(99, (531, 985), (531, 700), 4, [101], [
            (Box((517, 950), (547, 980)), VW)
        ])
        add_road(100, (478, 700), (478, 461), 2, [], [
            (Box((460, 645), (490, 675)), VW)
        ])
        add_road(101, (531, 700), (531, 461), 2, [], [
            (Box((517, 645), (547, 675)), VW)
        ])
        add_road(102, (950, 328), (610, 328), 18, [], [
            (Box((850, 316), (880, 346)), VW)
        ])
        add_road(103, (950, 380), (610, 380), 18, [], [
            (Box((850, 368), (880, 398)), VW)
        ])
        add_road(104, (595, 328), (820, 328), 19, [106], [
            (Box((600, 316), (630, 346)), VW)
        ])
        add_road(105, (595, 380), (820, 380), 19, [107], [
            (Box((600, 368), (630, 398)), VW)
        ])
        add_road(106, (820, 328), (1134, 328), 17, [], [
            (Box((910, 316), (940, 346)), VW)
        ])
        add_road(107, (820, 380), (1134, 380), 17, [], [
            (Box((910, 368), (940, 398)), VW)
        ])


        for i, connections_for_road in road_conns.items():
            roads[i].connections = [roads[j] for j in connections_for_road]

        return roads


    @staticmethod
    def load_spawnpoints(game):
        spawnpoints = [
            ('bike', 1),
            ('car', 2),
            ('bike', 3),
            ('man', 4),
            ('bike', 5),
            ('man', 6),
            ('car', 7),
            ('car', 8),
            ('car', 9),
            ('car', 10),
            ('car', 11),
            ('car', 12),
            ('car', 13),
            ('bus', 14),  # bus
            ('car', 15),
            ('car', 16),
            ('car', 17),
            ('bike', 18),
            ('man', 19),
            ('bike', 20),
            ('man', 21),
            ('man', 22),
            ('bike', 23),
            ('man', 24),
            ('bike', 25),
            ('man', 26),
            ('bike', 27),
            ('bike', 28),
            ('man', 29),
            ('car', 30),
            ('boat', 38),
            ('boat', 39),
            ('man', 84),
            ('bike', 87),
            ('bike', 91) ,
            ('man', 92),
            ('bike', 98),
            ('man', 99),
            ('man', 104),
            ('bike', 105),
        ]

        result = []
        for type, road_idx in spawnpoints:
            if type in ['man', 'bike']:
                speed    = 15
                cooldown = 40
            elif type in ['car', 'boat']:
                speed    = 65
                cooldown = 40
            elif type in ['bus']:
                speed    = 40
                cooldown = 400
            else:
                raise NotImplementedError()

            result.append(SpawnPoint(game, type, game.roads[road_idx], speed = speed, cooldown = cooldown))

        return result