-
Notifications
You must be signed in to change notification settings - Fork 0
/
bwapi_ruby.rb
97 lines (82 loc) · 1.42 KB
/
bwapi_ruby.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
require 'java'
$LOAD_PATH.unshift(File.dirname(__FILE__) + '\lib')
require 'bwmirror_v2_4.jar'
module Bwapi
include_package 'bwapi'
include_package 'bwta'
# Eager load all bwapi classes so they can be included in other modules
AIModule
BaseLocation
Bullet
BulletType
BWEventListener
BWTA
Chokepoint
Client
Color
DamageType
DefaultBWListener
Error
Event
ExplosionType
Force
Game
GameType
Key
Mirror
MouseButton
Order
Player
PlayerType
Polygon
Position
Race
Region
Region
TechType
TilePosition
Unit
UnitCommand
UnitCommandType
UnitSizeType
UnitType
UpgradeType
WeaponType
def self.start_bot(klass)
mirror = Bwapi::Mirror.new
BotInitializer.new(mirror, klass)
end
class BWListener
include Bwapi::BWEventListener
def method_missing(name, *args)
# ignore for now
end
end
class BotInitializer < BWListener
attr_reader :mirror, :bot_klass
def initialize(mirror, klass)
@mirror = mirror
@bot_klass = klass
mirror.getModule.setEventListener(self)
mirror.start_game()
puts "Starting game.."
end
def on_start
puts "Game started"
game = mirror.getGame
player = game.self
puts "Initializing bot"
bot = bot_klass.new(game, player)
bot.on_start
mirror.getModule.setEventListener(bot)
puts "Bot Initialized"
end
end
class Bot < BWListener
attr_reader :game, :player
def initialize(game, player)
@game = game
@player = player
end
end
end