-
Notifications
You must be signed in to change notification settings - Fork 0
/
zBlob2.rb
65 lines (47 loc) · 983 Bytes
/
zBlob2.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
$:.unshift File.dirname($0)
require 'AI.rb'
require 'BaseStrategy'
#
# main routine
#
$logger.log = false
$logger.log_status = false
strategy = BaseStrategy.new
def move_away list
ant = list[-1]
return if ant.moved?
if ant.stuck?
$logger.info "#{ ant } stuck!"
# Signal other ants to move away
dirs = [ :N, :E, :S, :W ].sort_by! { rand }
dirs.each do |dir|
ant2 = ant.square.neighbor( dir ).ant
if ant2 and
ant2.mine? and
not ant2.moved? and
not list.include? ant2
move_away list + [ ant2 ]
end
end
end
if not ant.stuck?
sq = ant.square
[ :N, :E, :S, :W ].each do |dir|
if sq.neighbor(dir).passable?
$logger.info "Moving #{ ant} to #{ dir }"
ant.move dir
break
end
end
return
end
end
$ai.run do |ai|
strategy.turn ai
# Attempt to move off the hill if there
ai.hills.each_friend do |sq|
if sq.ant? and sq.ant.mine?
move_away [ sq.ant]
end
end
end