forked from PyLadiesCZ/roboprojekt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validator.py
77 lines (66 loc) · 2.33 KB
/
validator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
This file is called by Pytest test_backend.py
It checks that the maps have correct structure
Don't call it separately
"""
from backend import get_board, get_data
def get_order_squares(text):
order_squares = {
'ground':"A_ground",
'hole':"B_hole",
'starting_square':"B_starting_square",
'repair':"B_repair",
'belt':"B_belt",
'gear':"B_gear",
'flag':"C_flag",
'pusher':"D_pusher",
'laser':"D_laser",
'wall':"D_wall"}
return order_squares[text]
def check_squares(map_name):
data = get_data("maps/" + map_name + ".json")
board = get_board(data)
"""
Change the list of types squares to the letters.
A, B and C type can be only once in type list.
"""
for coordinate, type in board.items():
square_type_letter = []
square_type_and_direction = []
for i in type:
square_type_letter.append(get_order_squares(i.type))
"""
Squares with the same type and direction mustn't be in list of types
"""
if (i.type, i.direction) in square_type_and_direction:
return coordinate, i.type # (8, 9), 'wall'
else:
square_type_and_direction.append((i.type, i.direction))
a = 0
b = 0
c = 0
for letter in square_type_letter:
if letter[0] == 'A':
a += 1
if letter[0] == 'B':
b += 1
if letter[0] == 'C':
c += 1
if a > 1 or b > 1 or c > 1:
return coordinate, a, b, c # ((1, 9), 1, 2, 0)
"""
Squares types must be in the correct order.
["A","B","D"] is correct ["D", "A"] is not
A < B < C < D
"""
letters_count = len(square_type_letter)
for i in range(letters_count-1):
if square_type_letter[i][0] > square_type_letter[i+1][0]:
return coordinate, square_type_letter[i] # ((7, 9), 'D')
"""
"Flag" mustn't be over the "Hole" or "Starting square"
"""
for i in range(len(square_type_letter)-1):
if square_type_letter[i] == "B_hole" and square_type_letter[i+1] == "C_flag" or square_type_letter[i] == "B_starting_square" and square_type_letter[i+1] == "C_flag":
return coordinate, square_type_letter[i]
return True