|
1 |
| -import PyAPI.structures as THUAI6 |
2 |
| -from PyAPI.Interface import ILogic, IStudentAPI, ITrickerAPI, IGameTimer, IAI |
| 1 | +import PyAPI.structures as THUAI7 |
| 2 | +from PyAPI.Interface import ILogic, IShipAPI, ITeamAPI, IGameTimer, IAI |
3 | 3 | from math import pi
|
4 | 4 | from concurrent.futures import ThreadPoolExecutor, Future
|
5 | 5 | from typing import List, cast, Tuple, Union
|
| 6 | + |
| 7 | + |
| 8 | +class ShipAPI(IShipAPI, IGameTimer): |
| 9 | + def __init__(self, logic: ILogic) -> None: |
| 10 | + self.__logic = logic |
| 11 | + self.__pool = ThreadPoolExecutor(20) |
| 12 | + |
| 13 | + def Move(self, timeInMilliseconds: int, angle: float) -> Future[bool]: |
| 14 | + return self.__pool.submit(self.__logic.move, timeInMilliseconds, angle) |
| 15 | + |
| 16 | + def MoveRight(self, timeInMilliseconds: int) -> Future[bool]: |
| 17 | + return self.Move(timeInMilliseconds, pi * 0.5) |
| 18 | + |
| 19 | + def MoveLeft(self, timeInMilliseconds: int) -> Future[bool]: |
| 20 | + return self.Move(timeInMilliseconds, pi * 1.5) |
| 21 | + |
| 22 | + def MoveUp(self, timeInMilliseconds: int) -> Future[bool]: |
| 23 | + return self.Move(timeInMilliseconds, pi) |
| 24 | + |
| 25 | + def MoveDown(self, timeInMilliseconds: int) -> Future[bool]: |
| 26 | + return self.Move(timeInMilliseconds, 0) |
| 27 | + |
| 28 | + def Attack(self, angle: float) -> Future[bool]: |
| 29 | + return self.__pool.submit(self.__logic.Attack, angle) |
| 30 | + |
| 31 | + def Recover(self) -> Future[bool]: |
| 32 | + return self.__pool.submit(self.__logic.Recover) |
| 33 | + |
| 34 | + def Produce(self) -> Future[bool]: |
| 35 | + return self.__pool.submit(self.__logic.Produce) |
| 36 | + |
| 37 | + def Rebuild(self, constructionType: THUAI7.ConstructionType) -> Future[bool]: |
| 38 | + return self.__pool.submit(self.__logic.Rebuild, constructionType) |
| 39 | + |
| 40 | + def Construct(self, constructionType: THUAI7.ConstructionType) -> Future[bool]: |
| 41 | + return self.__pool.submit(self.__logic.Construct, constructionType) |
| 42 | + |
| 43 | + def GetFrameCount(self) -> int: |
| 44 | + return self.__logic.GetFrameCount() |
| 45 | + |
| 46 | + def Wait(self) -> bool: |
| 47 | + if self.__logic.GetCounter() == -1: |
| 48 | + return False |
| 49 | + else: |
| 50 | + return self.__logic.WaitThread() |
| 51 | + |
| 52 | + def EndAllAction(self) -> Future[bool]: |
| 53 | + return self.__pool.submit(self.__logic.EndAllAction) |
| 54 | + |
| 55 | + def SendMessage(self, toID: int, message: Union[str, bytes]) -> Future[bool]: |
| 56 | + return self.__pool.submit(self.__logic.SendMessage, toID, message) |
| 57 | + |
| 58 | + def HaveMessage(self) -> bool: |
| 59 | + return self.__logic.HaveMessage() |
| 60 | + |
| 61 | + def GetMessage(self) -> Tuple[int, Union[str, bytes]]: |
| 62 | + return self.__logic.GetMessage() |
| 63 | + |
| 64 | + def GetShips(self) -> List[THUAI7.Ship]: |
| 65 | + return self.__logic.GetShips() |
| 66 | + |
| 67 | + def GetEnemyShips(self) -> List[THUAI7.Ship]: |
| 68 | + return self.__logic.GetEnemyShips() |
| 69 | + |
| 70 | + def GetBullets(self) -> List[THUAI7.Bullet]: |
| 71 | + return self.__logic.GetBullets() |
| 72 | + |
| 73 | + def GetFullMap(self) -> List[List[THUAI7.PlaceType]]: |
| 74 | + return self.__logic.GetFullMap() |
| 75 | + |
| 76 | + def GetPlaceType(self, cellX: int, cellY: int) -> THUAI7.PlaceType: |
| 77 | + return self.__logic.GetPlaceType(cellX, cellY) |
| 78 | + |
| 79 | + def GetConstructionHp(self, cellX: int, cellY: int) -> int: |
| 80 | + return self.__logic.GetConstructionHp(cellX, cellY) |
| 81 | + |
| 82 | + def GetWormHp(self, cellX: int, cellY: int) -> int: |
| 83 | + return self.__logic.GetWormHp(cellX, cellY) |
| 84 | + |
| 85 | + def GetResouceState(self, cellX: int, cellY: int) -> int: |
| 86 | + return self.__logic.GetResouceState(cellX, cellY) |
| 87 | + |
| 88 | + def GetHomeHp(self) -> int: |
| 89 | + return self.__logic.GetHomeHp() |
| 90 | + |
| 91 | + def GetGameInfo(self) -> THUAI7.GameInfo: |
| 92 | + return self.__logic.GetGameInfo() |
| 93 | + |
| 94 | + def GetPlayerGUIDs(self) -> List[int]: |
| 95 | + return self.__logic.GetPlayerGUIDs() |
| 96 | + |
| 97 | + def GetSelfInfo(self) -> THUAI7.Ship: |
| 98 | + return cast(THUAI7.Ships, self.__logic.GetSelfInfo()) |
| 99 | + |
| 100 | + def GetMoney(self) -> int: |
| 101 | + return self.__logic.GetMoney() |
| 102 | + |
| 103 | + def GetScore(self) -> int: |
| 104 | + return self.__logic.GetScore() |
| 105 | + |
| 106 | + def HaveView(self, gridX: int, gridY: int) -> bool: |
| 107 | + return self.__logic.HaveView(gridX, gridY, self.GetSelfInfo().x, |
| 108 | + self.GetSelfInfo().y, self.GetSelfInfo().viewRange) |
| 109 | + |
| 110 | + def Print(self, cont: str) -> None: |
| 111 | + pass |
| 112 | + |
| 113 | + def PrintShip(self) -> None: |
| 114 | + pass |
| 115 | + |
| 116 | + def PrintSelfInfo(self) -> None: |
| 117 | + pass |
| 118 | + |
| 119 | + def StartTimer(self) -> None: |
| 120 | + pass |
| 121 | + |
| 122 | + def EndTimer(self) -> None: |
| 123 | + pass |
| 124 | + |
| 125 | + def Play(self, ai: IAI) -> None: |
| 126 | + ai.ShipPlay(self) |
| 127 | + |
| 128 | + |
| 129 | +class TeamAPI(ITeamAPI, IGameTimer): |
| 130 | + def __init__(self, logic: ILogic) -> None: |
| 131 | + self.__logic = logic |
| 132 | + self.__pool = ThreadPoolExecutor(20) |
| 133 | + |
| 134 | + def StartTimer(self) -> None: |
| 135 | + pass |
| 136 | + |
| 137 | + def EndTimer(self) -> None: |
| 138 | + pass |
| 139 | + |
| 140 | + def Play(self, ai: IAI) -> None: |
| 141 | + ai.TeamPlay(self) |
| 142 | + |
| 143 | + def SendMessage(self, toID: int, message: Union[str, bytes]) -> Future[bool]: |
| 144 | + return self.__pool.submit(self.__logic.SendMessage, toID, message) |
| 145 | + |
| 146 | + def HaveMessage(self) -> bool: |
| 147 | + return self.__logic.HaveMessage() |
| 148 | + |
| 149 | + def GetMessage(self) -> Tuple[int, Union[str, bytes]]: |
| 150 | + return self.__logic.GetMessage() |
| 151 | + |
| 152 | + def GetFrameCount(self) -> int: |
| 153 | + return self.__logic.GetFrameCount() |
| 154 | + |
| 155 | + def Wait(self) -> bool: |
| 156 | + if self.__logic.GetCounter() == -1: |
| 157 | + return False |
| 158 | + else: |
| 159 | + return self.__logic.WaitThread() |
| 160 | + |
| 161 | + def EndAllAction(self) -> Future[bool]: |
| 162 | + return self.__pool.submit(self.__logic.EndAllAction) |
| 163 | + |
| 164 | + def GetBullets(self) -> List[THUAI7.Bullet]: |
| 165 | + return self.__logic.GetBullets() |
| 166 | + |
| 167 | + def GetShips(self) -> List[THUAI7.Ship]: |
| 168 | + return self.__logic.GetShips() |
| 169 | + |
| 170 | + def GetEnemyShips(self) -> List[THUAI7.Ship]: |
| 171 | + return self.__logic.GetEnemyShips() |
| 172 | + |
| 173 | + def GetFullMap(self) -> List[List[THUAI7.PlaceType]]: |
| 174 | + return self.__logic.GetFullMap() |
| 175 | + |
| 176 | + def GetPlaceType(self, cellX: int, cellY: int) -> THUAI7.PlaceType: |
| 177 | + return self.__logic.GetPlaceType(cellX, cellY) |
| 178 | + |
| 179 | + def GetConstructionHp(self, cellX: int, cellY: int) -> int: |
| 180 | + return self.__logic.GetConstructionHp(cellX, cellY) |
| 181 | + |
| 182 | + def GetWormHp(self, cellX: int, cellY: int) -> int: |
| 183 | + return self.__logic.GetWormHp(cellX, cellY) |
| 184 | + |
| 185 | + def GetResouceState(self, cellX: int, cellY: int) -> int: |
| 186 | + return self.__logic.GetResouceState(cellX, cellY) |
| 187 | + |
| 188 | + def GetHomeHp(self) -> int: |
| 189 | + return self.__logic.GetHomeHp() |
| 190 | + |
| 191 | + def GetGameInfo(self) -> THUAI7.GameInfo: |
| 192 | + return self.__logic.GetGameInfo() |
| 193 | + |
| 194 | + def GetPlayerGUIDs(self) -> List[int]: |
| 195 | + return self.__logic.GetPlayerGUIDs() |
| 196 | + |
| 197 | + def GetSelfInfo(self) -> THUAI7.Home: |
| 198 | + return cast(THUAI7.Home, self.__logic.GetSelfInfo()) |
| 199 | + |
| 200 | + def GetScore(self) -> int: |
| 201 | + return self.__logic.GetScore() |
| 202 | + |
| 203 | + def GetMoney(self) -> int: |
| 204 | + return self.__logic.GetMoney() |
| 205 | + |
| 206 | + def InstallModule(self, ID: int, type: THUAI7.ModuleType) -> Future[bool]: |
| 207 | + return self.__pool.submit(self.__logic.InstallModule, ID, type) |
| 208 | + |
| 209 | + def Recycle(self, ID: int) -> Future[bool]: |
| 210 | + return self.__pool.submit(self.__logic.Recycle, ID) |
| 211 | + |
| 212 | + def BuildShip(self, shipType: THUAI7.ShipType, cellX: int, cellY: int) -> Future[bool]: |
| 213 | + return self.__pool.submit(self.__logic.BuildShip, shipType, cellX, cellY) |
| 214 | + |
| 215 | + def Print(self, string: str) -> None: |
| 216 | + pass |
| 217 | + |
| 218 | + def PrintTeam(self) -> None: |
| 219 | + pass |
| 220 | + |
| 221 | + def PrintSelfInfo(self) -> None: |
| 222 | + pass |
0 commit comments