-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyBot.rb
executable file
·41 lines (34 loc) · 1.16 KB
/
MyBot.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
#!/usr/bin/env ruby
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'lib')
require 'ai'
ai=AI.new
ai.log_turn_times = ARGV.include?("--log_turn_times")
ai.setup do |ai|
@food_attract_radius = ai.viewradius.ceil.to_i
$stderr.puts "Food rd: #{@food_attract_radius}"
@enemy_distance = ai.attackradius.ceil.to_i
$stderr.puts "Enemy rd: #{@enemy_distance}"
end
ai.run do |ai|
@agressive = ai.my_ants.size > ai.enemy_ants.size * 2
ai.grid.each do |square|
square.apply_height(4,3) if square.ant? && square.ant.mine?
if square.ant? && square.ant.enemy?
if @agressive
square.apply_height(-(@enemy_distance+1), @enemy_distance)
else
square.apply_height(@enemy_distance+1, @enemy_distance)
end
end
square.apply_height(-(@food_attract_radius+1),@food_attract_radius) if square.food?
end
ai.my_ants.each_with_index do |ant, index|
$stderr.puts "Processing ant: #{index}"
# Don't double-move an ant
next if ant.moved?
# Use flow to check which direction to go
possible_directions = ant.square.flow_directions
direction = possible_directions.first
ant.order(direction) if direction
end
end