-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo.rb
82 lines (73 loc) · 1.92 KB
/
demo.rb
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
78
79
80
81
82
# -*- coding: utf-8 -*-
# demo.rb
require "./CHaserConnect.rb"
target = CHaserConnect.new("demo", 2009, 'localhost')
values = Array.new(10)
mode = 1
loop do
values = target.getReady
if values[0] == 0
break
end
if values[2] == 1 || values[4] == 1 || values[6] == 1 || values[8] == 1
mode = 90
end
if values[2] == 3 || values[4] == 3 || values[6] == 3 || values[8] == 3
old_mode = mode
mode = 20
end
if mode == 1
if values[2] != 2 # 下が壁でないなら
values = target.walkUp # 下に進む
else # 下が壁なら
values = target.walkLeft # 右に進む
mode = 2
end
elsif mode == 2
if values[4] != 2 # 右が壁でないなら
values = target.walkLeft # 右に進む
else # 右が壁なら
values = target.walkDown # 上に進む
mode = 3
end
elsif mode == 3
if values[8] != 2 # 上が壁でないなら
values = target.walkDown # 上に進む
else # 上が壁なら
values = target.walkRight # 左に進む
mode = 4
end
elsif mode == 4
if values[6] != 2 # 左が壁でないなら
values = target.walkRight # 左に進む
else # 左が壁なら
values = target.walkDown # 下に進む
mode = 1
end
elsif mode == 20
if values[2] == 3
values = target.walkUp
elsif values[4] == 3
values = target.walkLeft
elsif values[6] == 3
values = target.walkRight
else
values = target.walkDown
mode = old_mode
end
elsif mode == 90
if values[2] == 1
values = target.putUp
elsif values[4] == 1
values = target.putLeft
elsif values[6] == 1
values = target.putRight
else
values = target.putDown
end
end
if values[0] == 0
break
end
end
target.close