Skip to content

Commit 7a1c6f3

Browse files
authored
Merge pull request #216 from dysonreturns/observer-fixes
Returns ObserverAI to working order
2 parents 06096ca + 2ca0d04 commit 7a1c6f3

File tree

4 files changed

+7
-28
lines changed

4 files changed

+7
-28
lines changed

examples/watch_replay.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ async def on_step(self, iteration: int):
4040
assert (
4141
replay_path.is_file()
4242
), "Run worker_rush.py in the same folder first to generate a replay. Then run watch_replay.py again."
43-
run_replay(my_observer_ai, replay_path=replay_path)
43+
run_replay(my_observer_ai, replay_path=str(replay_path))

sc2/bot_ai_internal.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,10 @@ def _prepare_start(
476476
self.realtime: bool = realtime
477477
self.base_build: int = base_build
478478

479-
self.race: Race = Race(self.game_info.player_races[self.player_id])
480-
481-
if len(self.game_info.player_races) == 2:
479+
# Get the player's race. As observer, get Race.NoRace=0
480+
self.race: Race = Race(self.game_info.player_races.get(self.player_id, 0))
481+
# Get the enemy's race only if we are not observer (replay) and the game has 2 players
482+
if self.player_id > 0 and len(self.game_info.player_races) == 2:
482483
self.enemy_race: Race = Race(self.game_info.player_races[3 - self.player_id])
483484

484485
self._distances_override_functions(self.distance_calculation_method)

sc2/game_info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import numpy as np
1111

1212
from sc2.pixel_map import PixelMap
13-
from sc2.player import Player, Race
13+
from sc2.player import Player
1414
from sc2.position import Point2, Rect, Size
1515

1616

@@ -237,7 +237,7 @@ def __init__(self, proto) -> None:
237237
self.map_ramps: list[Ramp] = None # Filled later by BotAI._prepare_first_step
238238
# pyre-ignore[8]
239239
self.vision_blockers: frozenset[Point2] = None # Filled later by BotAI._prepare_first_step
240-
self.player_races: dict[int, Race] = {
240+
self.player_races: dict[int, int] = {
241241
p.player_id: p.race_actual or p.race_requested for p in self._proto.player_info
242242
}
243243
self.start_locations: list[Point2] = [

sc2/observer_ai.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,14 @@
66

77
from __future__ import annotations
88

9-
from typing import TYPE_CHECKING
10-
119
from sc2.bot_ai_internal import BotAIInternal
1210
from sc2.data import Alert, Result
13-
from sc2.game_data import GameData
1411
from sc2.ids.ability_id import AbilityId
1512
from sc2.ids.upgrade_id import UpgradeId
1613
from sc2.position import Point2
1714
from sc2.unit import Unit
1815
from sc2.units import Units
1916

20-
if TYPE_CHECKING:
21-
from sc2.client import Client
22-
from sc2.game_info import GameInfo
23-
2417

2518
class ObserverAI(BotAIInternal):
2619
"""Base class for bots."""
@@ -36,21 +29,6 @@ def time_formatted(self) -> str:
3629
t = self.time
3730
return f"{int(t // 60):02}:{int(t % 60):02}"
3831

39-
@property
40-
def game_info(self) -> GameInfo:
41-
"""See game_info.py"""
42-
return self._game_info
43-
44-
@property
45-
def game_data(self) -> GameData:
46-
"""See game_data.py"""
47-
return self._game_data
48-
49-
@property
50-
def client(self) -> Client:
51-
"""See client.py"""
52-
return self._client
53-
5432
def alert(self, alert_code: Alert) -> bool:
5533
"""
5634
Check if alert is triggered in the current step.

0 commit comments

Comments
 (0)