This repository has been archived by the owner on Jan 7, 2018. It is now read-only.
forked from Russian-AI-Cup-2016/python3-cgdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRunner.py
52 lines (38 loc) · 1.75 KB
/
Runner.py
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
import sys
from MyStrategy import MyStrategy
from RemoteProcessClient import RemoteProcessClient
from model.Move import Move
class Runner:
def __init__(self):
if sys.argv.__len__() == 4:
self.remote_process_client = RemoteProcessClient(sys.argv[1], int(sys.argv[2]))
self.token = sys.argv[3]
else:
self.remote_process_client = RemoteProcessClient("127.0.0.1", 31001)
self.token = "0000000000000000"
def run(self):
try:
self.remote_process_client.write_token_message(self.token)
self.remote_process_client.write_protocol_version_message()
team_size = self.remote_process_client.read_team_size_message()
game = self.remote_process_client.read_game_context_message()
strategies = []
for _ in range(team_size):
strategies.append(MyStrategy())
while True:
player_context = self.remote_process_client.read_player_context_message()
if player_context is None:
break
player_wizards = player_context.wizards
if player_wizards is None or player_wizards.__len__() != team_size:
break
moves = []
for wizard_index in range(team_size):
player_wizard = player_wizards[wizard_index]
move = Move()
moves.append(move)
strategies[wizard_index].move(player_wizard, player_context.world, game, move)
self.remote_process_client.write_moves_message(moves)
finally:
self.remote_process_client.close()
Runner().run()