-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo2.rb
115 lines (101 loc) · 1.76 KB
/
demo2.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# -*- coding: utf-8 -*-
# demo2.rb
require "./CHaserConnect.rb"
target = CHaserConnect.new("デモ2", 2010, 'localhost')
values = Array.new(10)
mode = 1
mode_old = 1
# mode
# 1 walkUp
# 2 walkDown
# 3 walkRight
# 4 walkLeft
# 5 putUp
# 6 putDown
# 7 putRight
# 8 putLeft
# 9 lookUp
# 10 lookDown
# 11 lookRight
# 12 lookLeft
# 13 searchUp
# 14 searchDown
# 15 searchRight
# 16 searchLeft
loop do
values = target.getReady
if values[0] == 0
break
end
if mode_old == 1
if values[2] != 2
mode = 1
else
mode = 4
end
end
if mode_old == 4 || mode == 4
if values[4] != 2
mode = 4
else
mode = 2
end
end
if mode_old == 2 || mode == 2
if values[8] != 2
mode = 2
else
mode = 3
end
end
if mode_old == 3 || mode == 3
if values[6] != 2
mode = 3
else
mode = 1
end
end
if values[2] == 3 || values[4] == 3 || values[6] == 3 || values[8] == 3
if values[2] == 3
mode = 1
elsif values[4] == 3
mode = 4
elsif values[6] == 3
mode = 3
else
mode = 2
end
end
if values[2] == 1 || values[4] == 1 || values[6] == 1 || values[8] == 1
if values[2] == 1
mode = 5
elsif values[4] == 1
mode = 8
elsif values[6] == 1
mode = 7
else
mode = 6
end
end
if mode == 1
values = target.walkUp
elsif mode == 2
values = target.walkDown
elsif mode == 3
values = target.walkRight
elsif mode == 4
values = target.walkLeft
elsif mode == 5
values = target.putUp
elsif mode == 6
values = target.putDown
elsif mode == 7
values = target.putRight
elsif mode == 8
values = target.putLeft
end
if values[0] == 0
break
end
mode_old = mode
end