Харут обнови решението на 20.10.2022 19:09 (преди около 2 години)
+def calculate_final_vector(start_point: tuple, tiles: list, /):
+ # validations
+ if not isinstance(start_point, tuple):
+ raise Exception(f"Give start point as tuple instead of {start_point}")
+ if len(start_point) != 2:
+ raise Exception(f"Give exactly 2 coordinates instead of {len(start_point)} for the start point")
+ if not isinstance(tiles, list):
+ raise Exception(f"Please give a list for the hex codes instead of {type(tiles).__name__}")
+
+ # unpack coordinates
+ x, y = start_point
+
+ # dict for readability
+ hex_code_dict = {
+ 'C0FFC0': 'Light Green',
+ 'FFFFC0': 'Light Yellow',
+ 'FFC0C0': 'Light Red',
+ 'C0C0FF': 'Light Blue',
+ '00C000': 'Dark Green',
+ 'C0C000': 'Dark Yellow',
+ 'C00000': 'Dark Red',
+ '0000C0': 'Dark Blue',
+ 'FFFFFF': 'White',
+ '000000': 'Black'
+ }
+
+ # main loop
+ for tile in tiles:
+ if not isinstance(tile, str):
+ raise Exception(f"Please give hex_code as string: '{tile}' instead of: {tile}")
+
+ # asure case sensitivity
+ tile = tile.upper()
+
+ if tile not in hex_code_dict.keys():
+ raise Exception(f"Please give valid hex code for colour")
+ match hex_code_dict[tile]:
+ case 'Light Green':
+ x -= 1
+ case 'Light Yellow':
+ y -= 1
+ case 'Light Red':
+ x += 1
+ case 'Light Blue':
+ x += 1
+ case 'Dark Green':
+ x += 1
+ case 'Dark Yellow':
+ y += 1
+ case 'Dark Red':
+ x -= 1
+ case 'Dark Blue':
+ x -= 1
+ case 'White':
+ continue
+ case 'Black':
+ break
+
+ return x, y