forked from Russian-AI-Cup-2014/ruby-cgdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunner.rb
More file actions
50 lines (40 loc) · 1.37 KB
/
Copy pathrunner.rb
File metadata and controls
50 lines (40 loc) · 1.37 KB
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
require './my_strategy'
require './remote_process_client'
class Runner
def initialize
if ARGV.length == 3
@remote_process_client = RemoteProcessClient::new(ARGV[0], ARGV[1].to_i)
@token = ARGV[2]
else
@remote_process_client = RemoteProcessClient::new('127.0.0.1', 31001)
@token = '0000000000000000'
end
end
def run
begin
@remote_process_client.write_token_message(@token)
team_size = @remote_process_client.read_team_size_message
@remote_process_client.write_protocol_version_message
game = @remote_process_client.read_game_context_message
strategies = []
team_size.times do |_|
strategies.push(MyStrategy::new)
end
while (player_context = @remote_process_client.read_player_context_message) != nil
player_hockeyists = player_context.hockeyists
break if player_hockeyists == nil || player_hockeyists.length != team_size
moves = []
team_size.times do |hockeyist_index|
player_hockeyist = player_hockeyists[hockeyist_index]
move = Move::new
moves.push(move)
strategies[player_hockeyist.teammate_index].move(player_hockeyist, player_context.world, game, move)
end
@remote_process_client.write_moves_message(moves)
end
ensure
@remote_process_client.close
end
end
end
Runner.new.run