-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask6.jl
72 lines (59 loc) · 1.62 KB
/
Task6.jl
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
function mark_perimetr!(r::Robot)
num_steps = fill(0, 3)
for (i, side) in enumerate((Sud, West, Sud))
num_steps[i] = moves!(r, side)
end
side = find_border!(r, Ost, Nord)
mark_perimetr(r, side)
moves!(r, Sud)
moves!(r, West)
for (i, side) in enumerate((Nord, Ost, Nord))
moves!(r, side, num_steps[i])
end
end
function find_border!(r::Robot, direction_to_border::HorizonSide, direction_of_movement::HorizonSide)
while !isborder(r, direction_to_border)
if !isborder(r, direction_of_movement)
move!(r, direction_of_movement)
else
move!(r, direction_to_border)
direction_of_movement = inverse(direction_of_movement)
end
end
return direction_of_movement
end
function mark_perimetr(r::Robot, side::HorizonSide)
move!(r, inverse(side))
if side == Sud
for (i, now_side) in enumerate((Sud, Ost, Nord, West))
move!(r, now_side)
putmarkers!(r, Int(now_side))
putmarker!(r)
end
else
for (i, now_side) in enumerate((Nord, Ost, Sud, West))
move!(r, now_side)
putmarkers!(r, Int(now_side))
end
end
end
function putmarkers!(r::Robot, side::Int)
while isborder(r, HorizonSide(mod(side + 1, 4)))
putmarker!(r)
move!(r, HorizonSide(side))
end
end
function moves!(r::Robot, side::HorizonSide)
counter = 0
while !isborder(r, side)
move!(r, side)
counter += 1
end
return counter
end
function moves!(r::Robot, side::HorizonSide, num_steps::Int)
for i = 1:num_steps
move!(r, side)
end
end
inverse(side::HorizonSide) = HorizonSide(mod(Int(side) + 2, 4))