-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask5.jl
51 lines (43 loc) · 1.17 KB
/
Task5.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
""""
--function solve(r::Robot)
Красит углы в поле с перегородками
"""
function solve(r::Robot)
mvs = []
go_to_corner(r, mvs) # Занять угол
mark_corners!(r) # Покрасить углы
return_back!(r, mvs) # Вернуться в начальное положение
end
function moveIfPossible(r::Robot, mvs::AbstractArray, side::HorizonSide)
if !isborder(r, side)
move!(r, side)
push!(mvs, side)
end
end
function go_to_corner(r::Robot, mvs::AbstractArray)
while isborder(r, Nord) == false || isborder(r, Ost) == false
moveIfPossible!(r, mvs, Nord)
moveIfPossible!(r, mvs, Ost)
end
# Робот достиг правого верхнего угла
end
function moves!(r::Robot, side::HorizonSide)
while !isborder(r, side)
move!(r, side)
end
end
function mark_corners(r::Robot)
for side in (Sud, West, Nord, Ost)
moves!(r, side)
putmarker!(r)
end
end
function inverse(side::HorizonSide)
return HorizonSide(mod(Int(side) + 2, 4))
end
function return_back(r::Robot, mvs::AbstractArray)
while length(mvs) > 0
last_move = mvs.pop()
move!(r, inverse(last_move))
end
end