Skip to content

Commit 09c252c

Browse files
authored
Update Model.py
1 parent b255f15 commit 09c252c

1 file changed

Lines changed: 41 additions & 20 deletions

File tree

Model.py

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ class AbilityName(Enum):
1414
GUARDIAN_ATTACK = "GUARDIAN_ATTACK"
1515
GUARDIAN_DODGE = "GUARDIAN_DODGE"
1616
GUARDIAN_FORTIFY = "GUARDIAN_FORTIFY"
17+
SHADOW_ATTACK = "SHADOW_ATTACK"
18+
SHADOW_DODGE = "SHADOW_DODGE"
19+
SHADOW_SLASH = "SHADOW_SLASH"
1720

1821

1922
class Direction(Enum):
@@ -28,6 +31,7 @@ class HeroName(Enum):
2831
BLASTER = "BLASTER"
2932
HEALER = "HEALER"
3033
GUARDIAN = "GUARDIAN"
34+
SHADOW = "SHADOW"
3135

3236

3337
class AbilityType(Enum):
@@ -43,7 +47,7 @@ class Phase(Enum):
4347

4448

4549
class AbilityConstants:
46-
def __init__(self, name, type, range, ap_cost, cooldown, area_of_effect, power, is_lobbing):
50+
def __init__(self, name, type, range, ap_cost, cooldown, area_of_effect, power, is_lobbing, is_piercing):
4751
self.name = name
4852
self.type = type
4953
self.range = range
@@ -52,19 +56,23 @@ def __init__(self, name, type, range, ap_cost, cooldown, area_of_effect, power,
5256
self.power = power
5357
self.area_of_effect = area_of_effect
5458
self.is_lobbing = is_lobbing
59+
self.is_piercing = is_piercing
5560

5661

5762
class GameConstants:
58-
def __init__(self, max_ap, preprocess_timeout, first_move_timeout, normal_timeout,
59-
max_turns, kill_score, objective_zone_score, max_score):
63+
def __init__(self, max_ap, preprocess_timeout, first_move_timeout, normal_timeout, max_turns,
64+
kill_score, objective_zone_score, max_score, total_move_phases, max_score_diff, init_overtime):
6065
self.max_ap = max_ap
6166
self.preprocess_timeout = preprocess_timeout
6267
self.first_move_timeout = first_move_timeout
68+
self.total_move_phases = total_move_phases
6369
self.normal_timeout = normal_timeout
6470
self.max_turns = max_turns
6571
self.kill_score = kill_score
6672
self.objective_zone_score = objective_zone_score
6773
self.max_score = max_score
74+
self.init_overtime = init_overtime
75+
self.max_score_diff = max_score_diff
6876
if World.DEBUGGING_MODE:
6977
import datetime
7078
World.LOG_FILE_POINTER = open('client' + '-' +
@@ -86,12 +94,13 @@ def _update_constants(self, ability_constants):
8694
self.power = ability_constants.power
8795
self.area_of_effect = ability_constants.area_of_effect
8896
self.is_lobbing = ability_constants.is_lobbing
97+
self.is_piercing = ability_constants.is_piercing
8998

9099
def is_ready(self):
91100
return self.rem_cooldown <= 0
92101

93102
def __str__(self):
94-
return 'name:' + self.name + '\trem_cooldown:' + str(self.rem_cooldown)
103+
return 'name:' + self.name.value + '\trem_cooldown:' + str(self.rem_cooldown)
95104

96105

97106
class HeroConstants:
@@ -161,7 +170,7 @@ def __hash__(self):
161170
return self.id
162171

163172
def __str__(self):
164-
return 'id:' + str(self.id) + ' name:' + self.name
173+
return 'id:' + str(self.id) + ' name:' + self.name.value
165174

166175

167176
class Cell:
@@ -245,6 +254,8 @@ def __init__(self, world=None, queue=None):
245254
self.my_score = 0
246255
self.ap = 0
247256
self.opp_score = 0
257+
self.max_overtime = 0
258+
self.remaining_overtime = 0
248259
self.current_phase = Phase.PICK
249260
self.current_turn = 0
250261
self.move_phase_num = -1
@@ -258,11 +269,14 @@ def __init__(self, world=None, queue=None):
258269
self.kill_score = game_constants.kill_score
259270
self.objective_zone_score = game_constants.objective_zone_score
260271
self.max_score = game_constants.max_score
272+
self.total_move_phases = game_constants.total_move_phases
273+
self.init_overtime = game_constants.init_overtime
261274
self.hero_constants = world.hero_constants
262275
self.ability_constants = world.ability_constants
263276
self.map = world.map
264277
self.queue = world.queue
265278
self.heroes = world.heroes
279+
self.max_score_diff = world.max_score_diff
266280
else:
267281
self.queue = queue
268282

@@ -321,6 +335,8 @@ def _handle_turn_message(self, msg):
321335
msg = msg['args'][0]
322336
self.my_score = msg["myScore"]
323337
self.opp_score = msg["oppScore"]
338+
self.max_overtime = msg["maxOvertime"]
339+
self.remaining_overtime = msg["remainingOvertime"]
324340
self.current_phase = Phase[msg["currentPhase"]]
325341
self.ap = msg["AP"]
326342
self.current_turn = msg["currentTurn"]
@@ -408,7 +424,7 @@ def _ability_constants_init(self, ability_list):
408424
for dic in ability_list:
409425
ability_constant = AbilityConstants(AbilityName[dic["name"]], AbilityType[dic["type"]], dic["range"],
410426
dic["APCost"], dic["cooldown"], dic["areaOfEffect"], dic["power"],
411-
dic["isLobbing"])
427+
dic["isLobbing"], dic["isPiercing"])
412428
abilities.append(ability_constant)
413429
self.ability_constants = abilities
414430

@@ -466,12 +482,17 @@ def _game_constant_init(self, game_constants_msg):
466482
max_turns=game_constants_msg["maxTurns"],
467483
kill_score=game_constants_msg["killScore"],
468484
objective_zone_score=game_constants_msg["objectiveZoneScore"],
469-
max_score=game_constants_msg["maxScore"])
485+
max_score=game_constants_msg["maxScore"],
486+
total_move_phases=game_constants_msg["totalMovePhases"],
487+
max_score_diff=game_constants_msg["maxScoreDiff"],
488+
init_overtime=game_constants_msg["initOvertime"])
470489
self.max_ap = self.game_constants.max_ap
471490
self.max_turns = self.game_constants.max_turns
472491
self.kill_score = self.game_constants.kill_score
473492
self.objective_zone_score = self.game_constants.objective_zone_score
474493
self.max_score = self.game_constants.max_score
494+
self.max_score_diff = self.game_constants.max_score_diff
495+
self.init_overtime = self.game_constants.init_overtime
475496

476497
def _get_hero(self, hero_type):
477498
for hero in self.heroes:
@@ -529,28 +550,28 @@ def get_impact_cell(self, ability=None, ability_name=None, start_cell=None, star
529550
return self.get_impact_cells(ability_constant, start_cell, target_cell)[-1]
530551

531552
def get_impact_cells(self, ability_constant, start_cell, target_cell):
532-
if ability_constant.is_lobbing:
533-
if self.manhattan_distance(target_cell, start_cell) <= ability_constant.range:
534-
return [target_cell]
535553
if start_cell.is_wall or start_cell == target_cell and not ability_constant.is_lobbing:
536554
return [start_cell]
537555
last_cell = None
538-
ray_cells = self.get_ray_cells(start_cell, target_cell)
556+
ray_cells = self.get_ray_cells(start_cell, target_cell, ability_constant.is_lobbing)
539557
impact_cells = []
540558
for cell in ray_cells:
541559
if self.manhattan_distance(cell, start_cell) > ability_constant.range:
542-
continue
560+
break
543561
last_cell = cell
544-
if self.is_affected(ability_constant, cell) or ability_constant.is_lobbing:
562+
if ability_constant.is_lobbing:
563+
continue
564+
if self.is_affected(ability_constant, cell):
545565
impact_cells.append(cell)
546-
break
566+
if not ability_constant.is_piercing:
567+
break
547568
if last_cell not in impact_cells:
548569
impact_cells.append(last_cell)
549570
return impact_cells
550571

551572
def is_affected(self, ability_constant, cell):
552-
return (self._get_opp_hero(cell) is not None and ability_constant.type == AbilityType.OFFENSIVE) or (
553-
self._get_my_hero(cell) is not None and ability_constant.type == AbilityType.DEFENSIVE)
573+
return (self._get_opp_hero(cell) is not None and not ability_constant.type == AbilityType.DEFENSIVE) or \
574+
(self._get_my_hero(cell) is not None and ability_constant.type == AbilityType.DEFENSIVE)
554575

555576
@staticmethod
556577
def manhattan_distance(start_cell=None, end_cell=None, start_cell_row=None, start_cell_column=None,
@@ -625,8 +646,8 @@ def is_between(first, second, between):
625646
if is_between(start, target, option):
626647
return option
627648

628-
def get_ray_cells(self, start_cell, end_cell):
629-
if not self.is_accessible(start_cell.row, start_cell.column):
649+
def get_ray_cells(self, start_cell, end_cell, is_lobbing=False):
650+
if not self.is_accessible(start_cell.row, start_cell.column) and not is_lobbing:
630651
return []
631652
if start_cell == end_cell:
632653
return [start_cell]
@@ -637,11 +658,11 @@ def get_ray_cells(self, start_cell, end_cell):
637658
neighbour = self._calculate_neighbour(start_cell, end_cell, current, former)
638659
if neighbour is None:
639660
break
640-
if neighbour.is_wall:
661+
if neighbour.is_wall and not is_lobbing:
641662
break
642663
if neighbour.row != current.row and neighbour.column != current.column and (
643664
self.map.get_cell(current.row, neighbour.column).is_wall
644-
or self.map.get_cell(neighbour.row, current.column).is_wall):
665+
or self.map.get_cell(neighbour.row, current.column).is_wall) and not is_lobbing:
645666
break
646667
res += [neighbour]
647668
former = current

0 commit comments

Comments
 (0)