-
Notifications
You must be signed in to change notification settings - Fork 0
/
zBlob.rb
74 lines (56 loc) · 1.05 KB
/
zBlob.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
$:.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 false if ant.moved?
dirs = [ :N, :E, :S, :W ].sort_by! { rand }
tmp = []
dirs.each do |dir|
n = ant.square.neighbor( dir )
if n.passable? false
tmp << dir
end
end
tmp.each do |dir|
n = ant.square.neighbor( dir )
unless n.passable?
ant2 = n.ant
if ant2 and
ant2.mine? and
not ant2.moved? and
not list.include? ant2
move_away list + [ ant2 ]
end
end
if n.passable?
ant.move dir
return true
end
end
ant.stay
return false
end
$ai.run do |ai|
strategy.turn ai
ai.my_ants.each do |ant|
next if ant.moved?
enemy = ant.closest_enemy
unless enemy.nil?
ant.set_order enemy.square, :ATTACK
next
end
end
# 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