-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmycmd.py
97 lines (85 loc) · 3.86 KB
/
mycmd.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
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
97
#!/usr/bin/env python
"""
Start module for aisandbox CTF challenge
"""
__version__ = "0.0.1"
__author__ = "@pejot"
from api import commander
from strategies.flanking_strategy import FLANKING_STRATEGY
from commander_utils.initializer import Initializer
from commander_utils.coordinates_calculator import CoordinatesCalculator
from actions.action import Action
from decision_rules.flanking_decision_rules import FlankingDecisionRules
from api import orders
class MyCommander(commander.Commander):
"""
The commander implemented for aisbx Flanking Challenge
"""
def initialize(self):
# initialize vars
self.current_actions = []
self.current_events = []
# initialize helpers
self. coordinates_calculator = CoordinatesCalculator()
# make it verbose
self.verbose = True
# for now just flanking startegy and nothing else - no cfg file
self.strategy = FLANKING_STRATEGY
self.operational_unit = Initializer.init_operation_units(
self.strategy, self.game.team.members)
self.initial_tick = True
def tick(self):
if self.initial_tick:
self.initial_tick = False
self.__grant_initial_orders()
return
reports = self.__collect_reports()
if len(reports) > 0:
self.current_events += reports
new_actions = FlankingDecisionRules.conclude(
self.current_actions, self.current_events)
if len(new_actions) > 0:
self.__grant_orders(new_actions)
else:
return
def shutdown(self):
pass
def __collect_reports(self):
reports = []
for unit in self.operational_unit:
report = unit.get_report(self.game)
for single_report in report:
reports.append({unit: single_report})
return reports
def __grant_orders(self, actions):
for action in actions:
key = action.keys()[0]
if action[key].action_type == Action.ActionType.ATTACK_BASE:
self.current_actions.append(action)
flanked_point = self.level.botSpawnAreas[
self.game.enemyTeam.name]
attacked_point = (flanked_point[0] + flanked_point[1]) / 2
self.issue(
orders.Attack, key, attacked_point, description='Attacking base')
def __grant_initial_orders(self):
# TODO
# it's too looong and contains code dupllications, fix me!
for i in range(len(self.strategy)):
# fillup_actions_array
self.current_actions.append(
{self.operational_unit[i]: self.strategy[i]["initial_action"]})
reference_point = self.level.botSpawnAreas[self.game.team.name]
# take the center own base
reference_point = (reference_point[0] + reference_point[1]) / 2
flanked_point = self.level.botSpawnAreas[self.game.enemyTeam.name]
# take the center of flanked base
flanked_point = (flanked_point[0] + flanked_point[1]) / 2
firing_distance = self.level.firingDistance
action_type = self.strategy[i]["initial_action"].action_type
if action_type == Action.ActionType.PREPARE_FLANKING_LEFT or action_type == Action.ActionType.PREPARE_FLANKING_RIGHT:
self.issue(orders.Move, self.operational_unit[i], self.coordinates_calculator.get_flanking_coordinates(
reference_point, flanked_point, firing_distance, self.strategy[i]["initial_action"]), description='Preparing flanking')
def issue(self, OrderClass, bot, *args, **dct):
""" Override issue method. Created to address orders to both, single bot and group. """
for alive in bot.alives:
super(MyCommander, self).issue(OrderClass, alive, *args, **dct)