-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.rb
More file actions
46 lines (42 loc) · 945 Bytes
/
bot.rb
File metadata and controls
46 lines (42 loc) · 945 Bytes
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
class Bot
@letter = " "
@x = 0
@y = 0
@map = []
def initialize(letter)
@letter = letter
end
def update_map(mapa)
rows = mapa.split('\n')
map = []
rows.each_with_index do |row, index|
map[index] = row.split(",")
end
pos = mapa.index(@letter) / 2
@y = pos / rows.length
@x = pos % rows.length
end
def move
mov = Random.rand(8)
puts "mov#{mov}"
case mov
when 0
return "N"
when 1
return "E"
when 2
return "S"
when 3
return "O"
when 4
return "BN"
when 5
return "BE"
when 6
return "BS"
when 7
return "BO"
end
"P"
end
end